MRMS
mrm-robot-line.h
1 #pragma once
2 #include <mrm-action.h>
3 #include <mrm-robot.h>
4 
5 // Change these values to get optimal robot's behaviour.
6 
7 // CATCH_SERVO drives jaws that catch ball.
8 #define CATCH_SERVO_L_CATCH 30
9 #define CATCH_SERVO_L_CLOSE 0 // Closed position, ball caught.
10 #define CATCH_SERVO_L_OPEN 90 // Open position, ready to catch a ball.
11 #define CATCH_SERVO_R_CATCH 60
12 #define CATCH_SERVO_R_CLOSE 90 // Closed position, ball caught.
13 #define CATCH_SERVO_R_OPEN 0 // Open position, ready to catch a ball.
14 
15 // LIFT_SERVO lifts catch the mechanism.
16 #define LIFT_SERVO_DOWN 80 // Lowest position, catching a ball.
17 #define LIFT_SERVO_UP 120 // Top (idle) position.
18 
19 #define LIDAR_COUNT 6 // 3 or 6, depending on model. If only 3 lidars built in, 6-mode cannot be used.
20 
21 #define WALL_DIFFERENCE_ALLOWED_MM 50 // If difference bigger, no wall.
22 #define MAXIMUM_WALL_MM 300 // If distance bigger than this value, do not follow wall.
23 
24 // mrm-8x8a display bitmaps.
25 enum ledSign {LED_EVACUATION_ZONE, LED_FULL_CROSSING_BOTH_MARKS, LED_FULL_CROSSING_MARK_LEFT, LED_FULL_CROSSING_MARK_RIGHT, LED_FULL_CROSSING_NO_MARK,
26  LED_HALF_CROSSING_MARK_LEFT, LED_HALF_CROSSING_MARK_RIGHT, LED_HALF_CROSSING_LEFT_NO_MARK, LED_HALF_CROSSING_RIGHT_NO_MARK,
27  LED_LINE_FULL, LED_LINE_FULL_BOTH_MARKS, LED_LINE_FULL_MARK_LEFT, LED_LINE_FULL_MARK_RIGHT, LED_LINE_INTERRUPTED, LED_CURVE_LEFT,
28  LED_CURVE_RIGHT, LED_OBSTACLE, LED_OBSTACLE_AROUND_LEFT, LED_OBSTACLE_AROUND_RIGHT, LED_PAUSE, LED_PLAY, LED_T_CROSSING_BY_L,
29  LED_T_CROSSING_BY_R, LED_WALL_AHEAD, LED_WALL_L, LED_WALL_R};
30 
31 /* All the Action-classes have to be forward declared here (before RobotLine) as RobotLine declaration uses them. The other option would be
32 not to declare them here, but in that case Action-objects in RobotLine will have to be declared as ActionBase class, forcing downcast later in code, if
33 derived functions are used.*/
36 class ActionLineFollow;
37 class ActionRCJLine;
38 
39 class ActionLoop0;
40 class ActionLoop1;
41 class ActionLoop2;
42 class ActionLoop3;
43 class ActionLoop4;
44 class ActionLoop5;
45 class ActionLoop6;
46 class ActionLoop7;
47 class ActionLoop8;
48 class ActionLoop9;
49 class ActionLoopMenu;
50 
53 class RobotLine : public Robot {
54  uint16_t BIGGEST_GAP_IN_LINE_MS = 2500;
55  // Changing this parameter will cause major behaviour change. Limit value: 127.
56  const uint8_t TOP_SPEED = 90; // 7.4 V 80 11.1 V 60
57  const uint16_t AHEAD_IN_CROSSING = 210; // 7.4V : 300
58  const uint8_t LAST_TRANSISTOR = 7; // mrm-ref-can: 8, mrm-ref-can8: 7
59 
60  // Actions' declarations
61  ActionEvacuationZone* actionEvacuationZone;
62  ActionObstacleAvoid* actionObstacleAvoid;
63  ActionLineFollow* actionLineFollow;
64  ActionRCJLine* actionRCJLine;
65  ActionBase* actionWallFollow;
66  ActionStop* actionStop;
67 
68  // Generic actions
69  ActionLoop0* actionLoop0;
70  ActionLoop1* actionLoop1;
71  ActionLoop2* actionLoop2;
72  ActionLoop3* actionLoop3;
73  ActionLoop4* actionLoop4;
74  ActionLoop5* actionLoop5;
75  ActionLoop6* actionLoop6;
76  ActionLoop7* actionLoop7;
77  ActionLoop8* actionLoop8;
78  ActionLoopMenu* actionLoopMenu;
79 
80  uint16_t barrierBrightest = 2000; // Default value, it should be calibrated.
81 
82  MotorGroupDifferential* motorGroup = NULL; // Class that conveys commands to motors.
83 
84 public:
88  RobotLine(char name[] = (char*)"RCJ Line"); // Maximum 15 characters
89 
92  void armCatch();
93 
96  void armCatchReady();
97 
98  void armClose();
99 
102  void armDrop();
103 
106  void armUp();
107 
111  bool barrier();
112 
115  void bitmapsSet();
116 
121  uint16_t brightness(uint8_t transistorNumber);
122 
127  bool button(uint8_t number);
128 
131  void curve();
132 
136  bool dark();
137 
141  void display(ledSign image);
142 
146  void display(char* text);
147 
150  void evacuationZone();
151 
155  uint16_t front();
156 
160  uint16_t frontLeft();
161 
165  uint16_t frontRight();
166 
172  void go(int16_t leftSpeed, int16_t rightSpeed);
173 
177  uint16_t leftBack();
178 
182  uint16_t leftFront();
183 
189  bool lineAny(uint8_t fistTransistor = 0, uint8_t lastTransistor = 0xFF);
190 
195  bool line(uint8_t transistorNumber);
196 
200  float lineCenter();
201 
204  void loop0();
205  void loop1();
206  void loop2();
207  void loop3();
208  void loop4();
209  void loop5();
210  void loop6();
211  void loop7();
212  void loop8();
213 
216  void loopMenu();
217 
220  void goAhead();
221 
225  float heading();
226 
231  uint8_t hue(uint8_t deviceNumber);
232 
237  void illumination(uint8_t current, uint8_t deviceNumber);
238 
241  void lineFollow();
242 
245  void loop();
246 
250  bool markers();
251 
254  void obstacleAvoid();
255 
259 
265  uint8_t patternColors(uint8_t deviceNumber);
266 
270  float pitch();
271 
274  void rcjLine();
275 
279  uint16_t rightBack();
280 
284  uint16_t rightFront();
285 
289  float roll();
290 
295  uint8_t saturation(uint8_t deviceNumber);
296 
301  void servo(uint16_t degrees = 90, uint8_t servoNumber = 0);
302 
306  void sign(uint8_t number);
307 
310  void stop();
311 
316  void surfacePrint(bool newLine = false, uint16_t delayMsAfterPrint = 0);
317 
321  void turn(int16_t byDegreesClockwise);
322 
327  uint8_t value(uint8_t deviceNumber);
328 
331  void wallFollow();
332 
336  bool wallLeft();
337 
341  bool wallRight();
342 };
343 
368 class ActionLineFollow : public ActionBase {
369  void perform(){ ((RobotLine*)_robot)->lineFollow(); }
370 public:
371  ActionLineFollow(RobotLine* robot) : ActionBase(robot, "lnf", "Line follow", 1) {}
372 };
373 
377  void perform() { ((RobotLine*)_robot)->obstacleAvoid(); }
378 public:
379  bool leftOfObstacle; // Obstacle is on the robot's left side
380 
381  ActionObstacleAvoid(RobotLine* robot) : ActionBase(robot, "obs", "Obstacle avoid", 0) {}
382 };
383 
387  void perform() { ((RobotLine*)_robot)->evacuationZone(); }
388 public:
389 
390  ActionEvacuationZone(RobotLine* robot) : ActionBase(robot, "eva", "Evacuation zone", 1) {}
391 };
392 
395 class ActionRCJLine : public ActionBase {
396  void perform() { ((RobotLine*)_robot)->rcjLine(); }
397 public:
398  ActionRCJLine(Robot* robot) : ActionBase(robot, "lin", "RCJ Line", 1) {}
399 };
400 
403 class ActionWallFollow : public ActionBase {
404  void perform() { ((RobotLine*)_robot)->wallFollow(); }
405 public:
406  ActionWallFollow(RobotLine* robot) : ActionBase(robot, "wal", "Wall follow") {}
407 };
408 
409 
410 // ****************** Generic actions
411 
412 class ActionLoop0 : public ActionBase {
413  void perform() { ((RobotLine*)_robot)->loop0(); }
414 public:
415  ActionLoop0(RobotLine* robot) : ActionBase(robot, "lo0", "Loop 0", 8) {}
416 };
417 
418 class ActionLoop1 : public ActionBase {
419  void perform() { ((RobotLine*)_robot)->loop1(); }
420 public:
421  ActionLoop1(RobotLine* robot) : ActionBase(robot, "lo1", "Loop 1", 8) {}
422 };
423 
424 class ActionLoop2 : public ActionBase {
425  void perform() { ((RobotLine*)_robot)->loop2(); }
426 public:
427  ActionLoop2(RobotLine* robot) : ActionBase(robot, "lo2", "Loop 2", 8) {}
428 };
429 
430 class ActionLoop3 : public ActionBase {
431  void perform() { ((RobotLine*)_robot)->loop3(); }
432 public:
433  ActionLoop3(RobotLine* robot) : ActionBase(robot, "lo3", "Loop 3", 8) {}
434 };
435 
436 class ActionLoop4 : public ActionBase {
437  void perform() { ((RobotLine*)_robot)->loop4(); }
438 public:
439  ActionLoop4(RobotLine* robot) : ActionBase(robot, "lo4", "Loop 4", 8) {}
440 };
441 
442 class ActionLoop5 : public ActionBase {
443  void perform() { ((RobotLine*)_robot)->loop5(); }
444 public:
445  ActionLoop5(RobotLine* robot) : ActionBase(robot, "lo5", "Loop 5", 8) {}
446 };
447 
448 class ActionLoop6 : public ActionBase {
449  void perform() { ((RobotLine*)_robot)->loop6(); }
450 public:
451  ActionLoop6(RobotLine* robot) : ActionBase(robot, "lo6", "Loop 6", 8) {}
452 };
453 
454 class ActionLoop7 : public ActionBase {
455  void perform() { ((RobotLine*)_robot)->loop7(); }
456 public:
457  ActionLoop7(RobotLine* robot) : ActionBase(robot, "lo7", "Loop 7", 8) {}
458 };
459 
460 class ActionLoop8 : public ActionBase {
461  void perform() { ((RobotLine*)_robot)->loop8(); }
462 public:
463  ActionLoop8(RobotLine* robot) : ActionBase(robot, "lo8", "Loop 8", 8) {}
464 };
465 
468 class ActionLoopMenu : public ActionBase {
469  void perform() { ((RobotLine*)_robot)->loopMenu(); }
470 public:
471  ActionLoopMenu(Robot* robot) : ActionBase(robot, "lme", "Loop (menu)", 1) {}
472 };
Definition: mrm-action.h:7
ActionBase(Robot *robot, const char shortcut[4], const char text[20], uint8_t menuLevel=1, BoardId boardsId=ID_ANY)
Definition: mrm-action.cpp:23
Definition: mrm-robot-line.h:386
Definition: mrm-robot-line.h:368
Definition: mrm-robot-line.h:412
Definition: mrm-robot-line.h:418
Definition: mrm-robot-line.h:424
Definition: mrm-robot-line.h:430
Definition: mrm-robot-line.h:436
Definition: mrm-robot-line.h:442
Definition: mrm-robot-line.h:448
Definition: mrm-robot-line.h:454
Definition: mrm-robot-line.h:460
Definition: RobotLineTest.h:16
Definition: mrm-robot-line.h:468
Definition: mrm-robot-line.h:376
Definition: mrm-robot-line.h:395
Definition: mrm-action.h:277
Definition: mrm-robot-line.h:403
Definition: mrm-board.h:403
Definition: mrm-robot.h:42
Definition: mrm-robot-line.h:53
RobotLine(char name[]=(char *)"RCJ Line")
Definition: mrm-robot-line.cpp:16
uint16_t front()
Definition: mrm-robot-line.cpp:655
uint16_t leftFront()
Definition: mrm-robot-line.cpp:723
void bitmapsSet()
Definition: mrm-robot-line.cpp:144
void curve()
Definition: mrm-robot-line.cpp:559
bool barrier()
Definition: mrm-robot-line.cpp:138
void armDrop()
Definition: mrm-robot-line.cpp:121
void surfacePrint(bool newLine=false, uint16_t delayMsAfterPrint=0)
Definition: mrm-robot-line.cpp:1063
bool markers()
Definition: mrm-robot-line.cpp:861
void armUp()
Definition: mrm-robot-line.cpp:129
void armCatchReady()
Definition: mrm-robot-line.cpp:104
void wallFollow()
Definition: mrm-robot-line.cpp:1105
uint8_t patternColors(uint8_t deviceNumber)
Definition: mrm-robot-line.cpp:984
void omniWheelsTest()
void display(ledSign image)
Definition: mrm-robot-line.cpp:610
void stop()
Definition: mrm-robot-line.cpp:1055
void rcjLine()
Definition: mrm-robot-line.cpp:997
void evacuationZone()
Definition: mrm-robot-line.cpp:624
void goAhead()
Definition: mrm-robot-line.cpp:684
void go(int16_t leftSpeed, int16_t rightSpeed)
Definition: mrm-robot-line.cpp:678
float pitch()
Definition: mrm-robot-line.cpp:991
bool dark()
Definition: mrm-robot-line.cpp:603
uint16_t brightness(uint8_t transistorNumber)
Definition: mrm-robot-line.cpp:553
void turn(int16_t byDegreesClockwise)
Definition: mrm-robot-line.cpp:1077
float heading()
Definition: mrm-robot-line.cpp:693
void illumination(uint8_t current, uint8_t deviceNumber)
Definition: mrm-robot-line.cpp:709
void lineFollow()
Definition: mrm-robot-line.cpp:753
uint16_t frontRight()
Definition: mrm-robot-line.cpp:669
bool button(uint8_t number)
Definition: mrm-robot-line.cpp:545
uint16_t rightBack()
Definition: mrm-robot-line.cpp:1012
uint8_t saturation(uint8_t deviceNumber)
Definition: mrm-robot-line.cpp:1034
void obstacleAvoid()
Definition: mrm-robot-line.cpp:906
uint16_t leftBack()
Definition: mrm-robot-line.cpp:716
uint16_t frontLeft()
Definition: mrm-robot-line.cpp:662
float lineCenter()
Definition: mrm-robot-line.cpp:747
uint8_t hue(uint8_t deviceNumber)
Definition: mrm-robot-line.cpp:701
float roll()
Definition: mrm-robot-line.cpp:1026
bool wallRight()
Definition: mrm-robot-line.cpp:1210
bool line(uint8_t transistorNumber)
Definition: mrm-robot-line.cpp:740
bool wallLeft()
Definition: mrm-robot-line.cpp:1203
bool lineAny(uint8_t fistTransistor=0, uint8_t lastTransistor=0xFF)
Definition: mrm-robot-line.cpp:732
void loopMenu()
Definition: mrm-robot-line.cpp:852
void servo(uint16_t degrees=90, uint8_t servoNumber=0)
Definition: mrm-robot-line.cpp:1042
uint16_t rightFront()
Definition: mrm-robot-line.cpp:1019
uint8_t value(uint8_t deviceNumber)
Definition: mrm-robot-line.cpp:1098
void loop()
Definition: mrm-robot-line.cpp:821
void armCatch()
Definition: mrm-robot-line.cpp:96
void sign(uint8_t number)
Definition: mrm-robot-line.cpp:1049
void loop0()
Definition: mrm-robot-line.cpp:829