4 #include <mrm-can-bus.h>
5 #include <mrm-common.h>
9 #define COMMAND_SENSORS_MEASURE_CONTINUOUS 0x10
10 #define COMMAND_SENSORS_MEASURE_ONCE 0x11
11 #define COMMAND_SENSORS_MEASURE_STOP 0x12
12 #define COMMAND_SENSORS_MEASURE_SENDING 0x13
13 #define COMMAND_SENSORS_MEASURE_CONTINUOUS_REQUEST_NOTIFICATION 0x14
14 #define COMMAND_SENSORS_MEASURE_CONTINUOUS_AND_RETURN_CALCULATED_DATA 0x15
15 #define COMMAND_SENSORS_MEASURE_CALCULATED_SENDING 0x16
16 #define COMMAND_SENSORS_MEASURE_CONTINUOUS_VERSION_2 0x17
17 #define COMMAND_SENSORS_MEASURE_CONTINUOUS_VERSION_3 0x18
18 #define COMMAND_FIRMWARE_REQUEST 0x19
19 #define COMMAND_FIRMWARE_SENDING 0x1A
20 #define COMMAND_RESET 0x1B
21 #define COMMAND_MESSAGE_SENDING_1 0x1C
22 #define COMMAND_MESSAGE_SENDING_2 0x1D
23 #define COMMAND_MESSAGE_SENDING_3 0x1E
24 #define COMMAND_MESSAGE_SENDING_4 0x1F
25 #define COMMAND_SPEED_SET 0x20
26 #define COMMAND_SPEED_SET_REQUEST_NOTIFICATION 0x21
27 #define COMMAND_DUPLICATE_ID_PING 0x22
28 #define COMMAND_DUPLICATE_ID_ECHO 0x23
29 #define COMMAND_INFO_REQUEST 0x24
30 #define COMMAND_INFO_SENDING_1 0x25
31 #define COMMAND_INFO_SENDING_2 0x26
32 #define COMMAND_INFO_SENDING_3 0x27
33 #define COMMAND_FPS_REQUEST 0x30
34 #define COMMAND_FPS_SENDING 0x31
35 #define COMMAND_ID_CHANGE_REQUEST 0x40
36 #define COMMAND_NOTIFICATION 0x41
37 #define COMMAND_OSCILLATOR_TEST 0x43
38 #define COMMAND_ERROR 0xEE
39 #define COMMAND_REPORT_ALIVE 0xFF
41 #define MAX_MOTORS_IN_GROUP 4
44 #define toRad(x) ((x) / 180.0 * PI)
47 #define toDeg(x) ((x) / PI * 180.0)
50 enum BoardId{ID_MRM_8x8A, ID_ANY, ID_MRM_BLDC2X50, ID_MRM_BLDC4x2_5, ID_MRM_COL_B, ID_MRM_COL_CAN, ID_MRM_FET_CAN, ID_MRM_IR_FINDER_2,
51 ID_MRM_IR_FINDER3, ID_MRM_IR_FINDER_CAN, ID_MRM_LID_CAN_B, ID_MRM_LID_CAN_B2, ID_MRM_MOT2X50, ID_MRM_MOT4X3_6CAN, ID_MRM_MOT4X10,
52 ID_MRM_NODE, ID_MRM_REF_CAN, ID_MRM_SERVO, ID_MRM_SWITCH, ID_MRM_THERM_B_CAN, ID_MRM_US, ID_MRM_US_B, ID_MRM_US1};
54 enum BoardType{MOTOR_BOARD, SENSOR_BOARD};
63 bool _aliveReport =
false;
67 uint8_t devicesOnABoard;
69 uint8_t errorCode = 0;
70 uint8_t errorInDeviceNumber = 0;
71 std::vector<uint16_t>* fpsLast;
73 std::vector<uint32_t>* idIn;
74 std::vector<uint32_t>* idOut;
75 std::vector<uint32_t>* lastMessageReceivedMs;
76 std::vector<uint32_t>* _lastReadingMs;
77 uint8_t maximumNumberOfBoards;
78 uint8_t measuringMode = 0;
79 uint8_t measuringModeLimit = 0;
81 std::vector<char[10]>* _name;
83 Robot* robotContainer;
102 Board(
Robot* robot, uint8_t maxNumberOfBoards, uint8_t devicesOnABoard,
const char * boardName, BoardType boardType, BoardId
id);
109 void add(
char* deviceName, uint16_t canIn, uint16_t canOut);
117 bool alive(uint8_t deviceNumber = 0,
bool checkAgainIfDead =
false,
bool errorIfNotAfterCheckingAgain =
false);
128 void aliveSet(
bool yesOrNo, uint8_t deviceNumber = 0);
130 BoardType boardType(){
return _boardType; }
152 uint8_t
devicesScan(
bool verbose =
true, uint16_t mask = 0xFFFF);
173 uint16_t
fps(uint8_t deviceNumber = 0);
186 BoardId
id() {
return _id; }
192 void idChange(uint16_t newDeviceNumber, uint8_t deviceNumber = 0);
197 void info(uint8_t deviceNumber = 0xFF);
204 bool isForMe(uint32_t canIdOut, uint8_t deviceNumber);
211 bool isFromMe(uint32_t canIdOut, uint8_t deviceNumber);
217 uint32_t
lastMessageMs(uint8_t deviceNumber = 0) {
return (*lastMessageReceivedMs)[deviceNumber]; }
233 bool messagePrint(uint32_t msgId, uint8_t dlc, uint8_t * data,
bool outbound);
240 void messageSend(uint8_t* data, uint8_t dlc, uint8_t deviceNumber = 0);
246 char *
name(uint8_t deviceNumber);
251 char*
name() {
return _boardsName;}
267 void reset(uint8_t deviceNumber = 0xFF);
274 void start(uint8_t deviceNumber = 0xFF, uint8_t measuringModeNow = 0, uint16_t refreshMs = 0);
281 void swap(uint8_t deviceNumber1, uint8_t deviceNumber2);
286 void stop(uint8_t deviceNumber = 0xFF);
292 virtual void test(uint8_t deviceNumber = 0xFF, uint16_t betweenTestsMs = 0) {}
299 std::vector<uint32_t>* encoderCount;
300 std::vector<bool>* reversed;
301 std::vector<int8_t>* lastSpeed;
312 MotorBoard(
Robot* robot, uint8_t devicesOnABoard,
const char * boardName, uint8_t maxNumberOfBoards, BoardId
id);
330 uint16_t
reading(uint8_t deviceNumber);
340 void speedSet(uint8_t motorNumber, int8_t speed);
350 void test(uint8_t deviceNumber = 0xFF, uint16_t betweenTestsMs = 0);
366 SensorBoard(
Robot* robot, uint8_t devicesOnABoard,
const char* boardName, uint8_t maxNumberOfBoards, BoardId
id);
385 MotorBoard* motorBoard[MAX_MOTORS_IN_GROUP] = { NULL, NULL, NULL, NULL };
386 uint8_t motorNumber[MAX_MOTORS_IN_GROUP];
387 Robot* robotContainer;
409 int16_t checkBounds(int16_t speed);
423 MotorBoard* motorBoardForLeft2 = NULL, uint8_t motorNumberForLeft2 = 0,
MotorBoard* motorBoardForRight2 = NULL, uint8_t motorNumberForRight2 = 0);
430 void go(int16_t leftSpeed = 0, int16_t rightSpeed = 0, int16_t lateralSpeedToRight = 0, uint8_t speedLimit = 127);
448 MotorBoard* motorBoardForMinus135Degrees, uint8_t motorNumberForMinus135Degrees,
MotorBoard* motorBoardForMinus45Degrees, uint8_t motorNumberForMinus45Degrees);
458 void go(
float speed,
float angleDegrees = 0,
float rotation = 0, uint8_t speedLimit = 127);
Definition: mrm-board.h:60
void messageSend(uint8_t *data, uint8_t dlc, uint8_t deviceNumber=0)
Definition: mrm-board.cpp:358
void oscillatorTest(uint8_t deviceNumber=0xFF)
Definition: mrm-board.cpp:409
uint8_t devicesScan(bool verbose=true, uint16_t mask=0xFFFF)
Definition: mrm-board.cpp:133
void aliveSet(bool yesOrNo, uint8_t deviceNumber=0)
Definition: mrm-board.cpp:115
void start(uint8_t deviceNumber=0xFF, uint8_t measuringModeNow=0, uint16_t refreshMs=0)
Definition: mrm-board.cpp:441
void reset(uint8_t deviceNumber=0xFF)
Definition: mrm-board.cpp:425
Board(Robot *robot, uint8_t maxNumberOfBoards, uint8_t devicesOnABoard, const char *boardName, BoardType boardType, BoardId id)
Definition: mrm-board.cpp:18
void fpsDisplay()
Definition: mrm-board.cpp:173
uint8_t errorWasInDeviceNumber()
Definition: mrm-board.h:162
uint8_t count()
Definition: mrm-board.cpp:103
uint8_t devicesOnASingleBoard()
Definition: mrm-board.h:140
void swap(uint8_t deviceNumber1, uint8_t deviceNumber2)
Definition: mrm-board.cpp:490
uint8_t deadOrAliveCount()
Definition: mrm-board.cpp:126
virtual void test(uint8_t deviceNumber=0xFF, uint16_t betweenTestsMs=0)
Definition: mrm-board.h:292
bool messagePrint(uint32_t msgId, uint8_t dlc, uint8_t *data, bool outbound)
** Prints a frame
Definition: mrm-board.cpp:328
char * name()
Definition: mrm-board.h:251
void fpsRequest(uint8_t deviceNumber=0xFF)
Definition: mrm-board.cpp:187
bool alive(uint8_t deviceNumber=0, bool checkAgainIfDead=false, bool errorIfNotAfterCheckingAgain=false)
Definition: mrm-board.cpp:69
BoardId id()
Definition: mrm-board.h:186
void stop(uint8_t deviceNumber=0xFF)
Definition: mrm-board.cpp:471
void idChange(uint16_t newDeviceNumber, uint8_t deviceNumber=0)
Definition: mrm-board.cpp:220
bool messageDecodeCommon(uint32_t canId, uint8_t data[8], uint8_t deviceNumber=0)
Definition: mrm-board.cpp:258
void add(char *deviceName, uint16_t canIn, uint16_t canOut)
Definition: mrm-board.cpp:44
uint32_t lastMessageMs(uint8_t deviceNumber=0)
Definition: mrm-board.h:217
void info(uint8_t deviceNumber=0xFF)
Definition: mrm-board.cpp:203
uint16_t fps(uint8_t deviceNumber=0)
Definition: mrm-board.cpp:167
void notificationRequest(uint8_t commandRequestingNotification, uint8_t deviceNumber)
Definition: mrm-board.cpp:383
bool isForMe(uint32_t canIdOut, uint8_t deviceNumber)
Definition: mrm-board.cpp:231
virtual bool messageDecode(uint32_t canId, uint8_t data[8])=0
uint8_t devicesMaximumNumberInAllBoards()
Definition: mrm-board.h:145
void firmwareRequest(uint8_t deviceNumber=0xFF)
Definition: mrm-board.cpp:151
bool isFromMe(uint32_t canIdOut, uint8_t deviceNumber)
Definition: mrm-board.cpp:244
uint8_t errorCodeLast()
Definition: mrm-board.h:157
Definition: mrm-board.h:297
void speedSet(uint8_t motorNumber, int8_t speed)
Definition: mrm-board.cpp:582
void stop()
Definition: mrm-board.cpp:602
void readingsPrint()
Definition: mrm-board.cpp:570
void test(uint8_t deviceNumber=0xFF, uint16_t betweenTestsMs=0)
Definition: mrm-board.cpp:611
void directionChange(uint8_t deviceNumber)
Definition: mrm-board.cpp:521
uint16_t reading(uint8_t deviceNumber)
Definition: mrm-board.cpp:560
MotorBoard(Robot *robot, uint8_t devicesOnABoard, const char *boardName, uint8_t maxNumberOfBoards, BoardId id)
Definition: mrm-board.cpp:511
bool messageDecode(uint32_t canId, uint8_t data[8])
Definition: mrm-board.cpp:533
Definition: mrm-board.h:403
MotorGroupDifferential(Robot *robot, MotorBoard *motorBoardForLeft1, uint8_t motorNumberForLeft1, MotorBoard *motorBoardForRight1, uint8_t motorNumberForRight1, MotorBoard *motorBoardForLeft2=NULL, uint8_t motorNumberForLeft2=0, MotorBoard *motorBoardForRight2=NULL, uint8_t motorNumberForRight2=0)
Definition: mrm-board.cpp:772
void go(int16_t leftSpeed=0, int16_t rightSpeed=0, int16_t lateralSpeedToRight=0, uint8_t speedLimit=127)
Definition: mrm-board.cpp:802
Definition: mrm-board.h:383
void stop()
Definition: mrm-board.cpp:754
float angleNormalized(float angle)
Definition: mrm-board.cpp:744
Definition: mrm-board.h:435
void go(float speed, float angleDegrees=0, float rotation=0, uint8_t speedLimit=127)
Definition: mrm-board.cpp:863
void goToEliminateErrors(float errorX, float errorY, float headingToMaintain, Mrm_pid *pidXY, Mrm_pid *pidRotation, bool verbose=false)
Definition: mrm-board.cpp:907
MotorGroupStar(Robot *robot, MotorBoard *motorBoardFor45Degrees, uint8_t motorNumberFor45Degrees, MotorBoard *motorBoardFor135Degrees, uint8_t motorNumberFor135Degrees, MotorBoard *motorBoardForMinus135Degrees, uint8_t motorNumberForMinus135Degrees, MotorBoard *motorBoardForMinus45Degrees, uint8_t motorNumberForMinus45Degrees)
Definition: mrm-board.cpp:843
Definition: mrm-robot.h:42
Definition: mrm-board.h:356
void continuousReadingCalculatedDataStart(uint8_t deviceNumber=0xFF)
Definition: mrm-board.cpp:716
virtual bool messageDecode(uint32_t canId, uint8_t data[8])
Definition: mrm-board.h:378
SensorBoard(Robot *robot, uint8_t devicesOnABoard, const char *boardName, uint8_t maxNumberOfBoards, BoardId id)
Definition: mrm-board.cpp:709