Reference.RobotMotorWriteYourOwnFirmware History

Hide minor edits - Show changes to markup

May 13, 2013, at 01:39 PM by Scott Fitzgerald -
Changed lines 48-52 from:
  • Find the part with mode definition: "#define COMMAND_SWITCH_MODE 0 ...", add a line in the end "#define COMMAND_MY_COMMAND_NAME num", the "num" should be different from all previous command number. If your command is 2-directional query, define another command code here:"#define COMMAND_MY_COMMAND_NAME_RE num" which will be used for the returning command.
  • Plan the structure of your command. You can have byte or int stored in the command, just remember when sending/receiving the command, write/read of the corresponding data should be in the same order. Take the comment starting with "A message structure will be:" as example.
  • Sending the command. Typically it'll be a function in RobotControl library. See "motorsWrite()" in motors.cpp, "updateIR()" in sensors.cpp as example
  • Identifying the command. In RobotMotorBoard library, find "parseCommand()" in ArduinoRobotMotorBoard.cpp. Add a new condition to the case clause. Take the other conditions as example
  • If you command is a 1-directional order, just write another function to carry out the logics and it's done. If it's a 2-directional query, take "_digitalRead()" as example of a returning command.
to:
May 13, 2013, at 01:25 PM by Scott Fitzgerald -
Changed lines 5-26 from:

The Robot Motor Board is intended to work as a "state machine", which means it only receive commands from the Robot Control Board and execute them accordingly, as well as returning data as required. In this way the motor board does not house much intelligence, and does not need to have its sketch adjusted for different applications.

However, you can extend the commands/functionality by modifying the library files.

There're two ways of adding more features: Define your own Mode or create your own Command.

New Mode

When you call setMode() from the Robot Control Board, the Motor Board will enter another mode. Different behaviours can be defined for different modes, so if the desired feature only uses parts of the Motor Board, you can write the logics there instead of returning all sensor values to the Control Board first.

One example of the existing modes is line following mode. When entering line following mode, the motor board will read values from the infrared sensor array mounted on the bottom of the board, calculate the desired direction of robot and manipulate the motors directly. Everything is contained in the Motor Board.

To create a new mode, you need to define the mode in both Control Board and Motor Board, and write the logics for behaviours of the mode

Define the New Mode

  • Open "libraries/Robot_Control/ArduinoRobot.h" and "libraries/Robot_Motor/ArduinoRobotMotorBoard.h"
  • find the part with mode definition: "#define MODE_SIMPLE 0...", add a line in the end "#define MODE_MY_MODE_NAME num", the "num" should be different from all previous mode number
  • In "ArduinoRobotMotorBoard.cpp", find the definition of "process()". Add in new condition corresponding to the mode. Code here will be carried out in each loop, so just write your logics as in the loop.
  • In your sketch for Robot Control Board, you can now use "setMode(MODE_MY_MODE_NAME )" to switch mode

New Command

To create a new command, first you need to define the command code in both libraries. Then depending on the type of command, write the send/receive code for it.

to:
Changed lines 39-46 from:
  • order(1-directional), like in "RobotControl::motorsWrite()", the Control board sends the command, Motor Board receives it and carries out its actions without sending anything back.

  • query(2-directional), like in "RobotControl::updateIR()",

after the Motor Board receives its command from Control Board, it sends back a command with the corresponding data.

Depending on which type of command you want to create, take the existing functions as example.

Define New Command

to:
  • orders (1-directional communication) : Similar to motorsWrite(), the Control board sends a command, that the Motor Board receives and carries out. Nothing is sent back to the command board.

  • queries (2-directional communications) : Like with updateIR(), the control board sends a message to the motor board, which then returns data to the control.

To create a new command, you need to define the command code and write the send/receive code for it.

Define a New Command

  • In your OS, navigate to the Arduino sketches folder.
May 03, 2013, at 11:42 AM by Xun Yang -
Changed lines 1-2 from:
to:
April 14, 2013, at 04:26 PM by Xun Yang -
Changed lines 38-40 from:
  • Find the part with mode definition: "#define COMMAND_SWITCH_MODE 0 ...", add a line in the end "#define COMMAND_MY_COMMAND_NAME num", the "num" should be different from all previous command number
  • Plan the structure of your command. You can have byte or int stored in the command, just remember when sending/receiving the command, write/read of the corresponding data should be in the right order. Take the comment starting with "A message structure will be:" as example.
to:
  • Find the part with mode definition: "#define COMMAND_SWITCH_MODE 0 ...", add a line in the end "#define COMMAND_MY_COMMAND_NAME num", the "num" should be different from all previous command number. If your command is 2-directional query, define another command code here:"#define COMMAND_MY_COMMAND_NAME_RE num" which will be used for the returning command.
  • Plan the structure of your command. You can have byte or int stored in the command, just remember when sending/receiving the command, write/read of the corresponding data should be in the same order. Take the comment starting with "A message structure will be:" as example.
  • Sending the command. Typically it'll be a function in RobotControl library. See "motorsWrite()" in motors.cpp, "updateIR()" in sensors.cpp as example
  • Identifying the command. In RobotMotorBoard library, find "parseCommand()" in ArduinoRobotMotorBoard.cpp. Add a new condition to the case clause. Take the other conditions as example
  • If you command is a 1-directional order, just write another function to carry out the logics and it's done. If it's a 2-directional query, take "_digitalRead()" as example of a returning command.
April 14, 2013, at 03:56 PM by Xun Yang -
Changed lines 22-40 from:
  • In
to:
  • In your sketch for Robot Control Board, you can now use "setMode(MODE_MY_MODE_NAME )" to switch mode

New Command

To create a new command, first you need to define the command code in both libraries. Then depending on the type of command, write the send/receive code for it.

There are two different types of commands:

  • order(1-directional), like in "RobotControl::motorsWrite()", the Control board sends the command, Motor Board receives it and carries out its actions without sending anything back.

  • query(2-directional), like in "RobotControl::updateIR()",

after the Motor Board receives its command from Control Board, it sends back a command with the corresponding data.

Depending on which type of command you want to create, take the existing functions as example.

Define New Command

  • Open "libraries/Robot_Control/ArduinoRobot.h" and "libraries/Robot_Motor/ArduinoRobotMotorBoard.h"
  • Find the part with mode definition: "#define COMMAND_SWITCH_MODE 0 ...", add a line in the end "#define COMMAND_MY_COMMAND_NAME num", the "num" should be different from all previous command number
  • Plan the structure of your command. You can have byte or int stored in the command, just remember when sending/receiving the command, write/read of the corresponding data should be in the right order. Take the comment starting with "A message structure will be:" as example.
April 14, 2013, at 03:13 PM by Xun Yang -
Changed lines 3-6 from:

Write Your Own Motor Board Firmware

The Robot Motor Board is intended to work as a "state machine". It only receives commands from the Robot Control Board and executes them accordingly, and returns data when requested. In this way the motor board does not house much intelligence, and does not need to have its sketch adjusted for different applications.

to:

Write Your Own Firmware

The Robot Motor Board is intended to work as a "state machine", which means it only receive commands from the Robot Control Board and execute them accordingly, as well as returning data as required. In this way the motor board does not house much intelligence, and does not need to have its sketch adjusted for different applications.

Changed lines 9-10 from:

There are two ways of adding more features: Define your own Mode or create your own Command.

to:

There're two ways of adding more features: Define your own Mode or create your own Command.

Added lines 16-22:

To create a new mode, you need to define the mode in both Control Board and Motor Board, and write the logics for behaviours of the mode

Define the New Mode

  • Open "libraries/Robot_Control/ArduinoRobot.h" and "libraries/Robot_Motor/ArduinoRobotMotorBoard.h"
  • find the part with mode definition: "#define MODE_SIMPLE 0...", add a line in the end "#define MODE_MY_MODE_NAME num", the "num" should be different from all previous mode number
  • In "ArduinoRobotMotorBoard.cpp", find the definition of "process()". Add in new condition corresponding to the mode. Code here will be carried out in each loop, so just write your logics as in the loop.
  • In
April 14, 2013, at 03:13 PM by Xun Yang -
April 14, 2013, at 02:24 PM by Scott Fitzgerald -
Changed lines 3-6 from:

Write Your Own Firmware

The Robot Motor Board is intended to work as a "state machine", which means it only receive commands from the Robot Control Board and execute them accordingly, as well as returning data as required. In this way the motor board does not house much intelligence, and does not need to have its sketch adjusted for different applications.

to:

Write Your Own Motor Board Firmware

The Robot Motor Board is intended to work as a "state machine". It only receives commands from the Robot Control Board and executes them accordingly, and returns data when requested. In this way the motor board does not house much intelligence, and does not need to have its sketch adjusted for different applications.

Changed lines 9-10 from:

There're two ways of adding more features: Define your own Mode or create your own Command.

to:

There are two ways of adding more features: Define your own Mode or create your own Command.

April 14, 2013, at 01:37 PM by Xun Yang -
Added lines 1-15:

Robot?

Write Your Own Firmware

The Robot Motor Board is intended to work as a "state machine", which means it only receive commands from the Robot Control Board and execute them accordingly, as well as returning data as required. In this way the motor board does not house much intelligence, and does not need to have its sketch adjusted for different applications.

However, you can extend the commands/functionality by modifying the library files.

There're two ways of adding more features: Define your own Mode or create your own Command.

New Mode

When you call setMode() from the Robot Control Board, the Motor Board will enter another mode. Different behaviours can be defined for different modes, so if the desired feature only uses parts of the Motor Board, you can write the logics there instead of returning all sensor values to the Control Board first.

One example of the existing modes is line following mode. When entering line following mode, the motor board will read values from the infrared sensor array mounted on the bottom of the board, calculate the desired direction of robot and manipulate the motors directly. Everything is contained in the Motor Board.

Share