0

Line Robot - starting and ending actions

How to start an action?

Robot's useful action usually includes some kind of moving around. How to start it? The easiest way is to start it always, as soon as robot is powered on. This solution is highly inadvisable. If You wonder why, wait till it hits the floor, after jumping from the desk.

Way to do it in ML-R is by using ActionBase derived classes, which were described on previous page. They offer You 3 possibilities.

Program call

First is to start it in code, like this:

actionSet(actionLineFollow);
This line is a part of rcjLine() function in mrm-robot-line.cpp and is used to initiate line-following action. Therefore, the action can be started by calling actionSet() function and including action object's name as the only parameter. First time the program flow passes through main loop, it will replace the current action, causing ActionLineFollow perform() function to start executing repeatedly, as long as ActionLineFollow stays the current action. You can check in ActionLineFollow declaration that perform() calls RobotLinee::lineFollow() function, being the one that actually contains the working code.

Menu

A menu is displayed each time robot enters idle state (ends actions), both in USB connected computer, and on a paired Bluetooth device, like a mobile phone or tablet. You can use any of these devices to issue commands in form of 3-letter shortcuts, which are again defined in action's constructor definition:

/** Start RCJ Line run.
*/
class ActionRCJLine : public ActionBase {
	void perform() { ((RobotLine*)_robot)->rcjLine(); }
public:
	ActionRCJLine(Robot* robot) : ActionBase(robot, "lin", "RCJ Line", 1) {}
};
According to this definition "lin - RCJ Line" will be displayed in the main menu (parameter "1" states that) and the action can be started by typing "lin" (depending on terminal's implementation, additional "Enter" or "Send" button may be necessary).

Button

A robot featuring ML-R 8x8 bicolor display, CAN Bus,UART, 4 switches (mrm-8x8a) has 4 user defined buttons. Even the main microcontroller, MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32) has one, although not so easily accessible. To use a button, it has to be associated with the desired action. To link it to RobotLine, use this line, like in the MRMS_ESP32.ino program:

	// Set buttons' actions.
	mrm_8x8a->actionSet(actionRCJLine, 0); // Button 0 starts RCJ Line.
This line is a part of RoboLinee's constructor. You can add Your actions after this one.

Action end

Ending an action is easy in 2 ways:

  • by setting another action, using actionSet() function or
  • by calling end() function.
After action end, the robot will enter idle state, which does nothing except first displaying a menu and afterwards waiting for another user input (button or keystrokes).