xx

Committer:
sype
Date:
Tue Nov 24 21:41:45 2015 +0000
Revision:
2:a2c141d922b3
Parent:
1:f76058f9f548
Child:
5:ad00b3431ff5
Documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sype 0:af5cf35e1a25 1 #ifndef ROBOCLAW_H
sype 0:af5cf35e1a25 2 #define ROBOCLAW_H
sype 0:af5cf35e1a25 3 #include "mbed.h"
sype 0:af5cf35e1a25 4 #include "registers.h"
sype 0:af5cf35e1a25 5
sype 2:a2c141d922b3 6 /** The RoboClaw class, yo ucan use the library with : http://www.ionmc.com/RoboClaw-2x15A-Motor-Controller_p_10.html
sype 2:a2c141d922b3 7 * Used to control one or two motors with (or not) encoders
sype 2:a2c141d922b3 8 * @code
sype 2:a2c141d922b3 9 * #include "mbed.h"
sype 2:a2c141d922b3 10 * #include "RoboClaw.h"
sype 0:af5cf35e1a25 11 *
sype 2:a2c141d922b3 12 * RoboClaw roboclaw(115200, PA_11, PA_12);
sype 2:a2c141d922b3 13 *
sype 2:a2c141d922b3 14 * int main() {
sype 2:a2c141d922b3 15 * roboclaw.ForwardM1(ADR, 127);
sype 2:a2c141d922b3 16 * while(1);
sype 2:a2c141d922b3 17 * }
sype 2:a2c141d922b3 18 * @endcode
sype 0:af5cf35e1a25 19 */
sype 0:af5cf35e1a25 20
sype 0:af5cf35e1a25 21 class RoboClaw
sype 0:af5cf35e1a25 22 {
sype 0:af5cf35e1a25 23 public:
sype 2:a2c141d922b3 24 /** Create RoboClaw instance
sype 2:a2c141d922b3 25 */
sype 0:af5cf35e1a25 26 RoboClaw(int baudrate, PinName rx, PinName tx);
sype 0:af5cf35e1a25 27
sype 2:a2c141d922b3 28 /** Forward and Backward functions
sype 2:a2c141d922b3 29 * @param address address of the device
sype 2:a2c141d922b3 30 * @param speed speed of the motor (between 0 and 127)
sype 2:a2c141d922b3 31 * @note Forward and Backward functions
sype 2:a2c141d922b3 32 */
sype 2:a2c141d922b3 33 void ForwardM1(uint8_t address, int speed);
sype 2:a2c141d922b3 34 void BackwardM1(uint8_t address, int speed);
sype 2:a2c141d922b3 35 void ForwardM2(uint8_t address, int speed);
sype 2:a2c141d922b3 36 void BackwardM2(uint8_t address, int speed);
sype 0:af5cf35e1a25 37
sype 2:a2c141d922b3 38 /** Forward and Backward functions
sype 2:a2c141d922b3 39 * @param address address of the device
sype 2:a2c141d922b3 40 * @param speed speed of the motor (between 0 and 127)
sype 2:a2c141d922b3 41 * @note Forward and Backward functions, it turns the two motors
sype 2:a2c141d922b3 42 */
sype 2:a2c141d922b3 43 void Forward(uint8_t address, int speed);
sype 2:a2c141d922b3 44 void Backward(uint8_t address, int speed);
sype 0:af5cf35e1a25 45
sype 2:a2c141d922b3 46 /** Read the Firmware
sype 2:a2c141d922b3 47 * @param address address of the device
sype 2:a2c141d922b3 48 */
sype 2:a2c141d922b3 49 void ReadFirm(uint8_t address);
sype 0:af5cf35e1a25 50
sype 2:a2c141d922b3 51 /** Read encoder and speed of M1 or M2
sype 2:a2c141d922b3 52 * @param address address of the device
sype 2:a2c141d922b3 53 * @note Read encoder in ticks
sype 2:a2c141d922b3 54 * @note Read speed in ticks per second
sype 2:a2c141d922b3 55 */
sype 2:a2c141d922b3 56 int32_t ReadEncM1(uint8_t address);
sype 2:a2c141d922b3 57 int32_t ReadEncM2(uint8_t address);
sype 2:a2c141d922b3 58 int32_t ReadSpeedM1(uint8_t address);
sype 2:a2c141d922b3 59 int32_t ReadSpeedM2(uint8_t address);
sype 0:af5cf35e1a25 60
sype 2:a2c141d922b3 61 /** Set both encoders to zero
sype 2:a2c141d922b3 62 * @param address address of the device
sype 2:a2c141d922b3 63 */
sype 2:a2c141d922b3 64 void ResetEnc(uint8_t address);
sype 0:af5cf35e1a25 65
sype 2:a2c141d922b3 66 /** Set speed of Motor with different parameter (only in ticks)
sype 2:a2c141d922b3 67 * @param address address of the device
sype 2:a2c141d922b3 68 * @note Set the Speed
sype 2:a2c141d922b3 69 * @note Set the Speed and Accel
sype 2:a2c141d922b3 70 * @note Set the Speed and Distance
sype 2:a2c141d922b3 71 * @note Set the Speed, Accel and Distance
sype 2:a2c141d922b3 72 * @note Set the Speed, Accel, Decceleration and Position
sype 2:a2c141d922b3 73 */
sype 2:a2c141d922b3 74 void SpeedM1(uint8_t address, int32_t speed);
sype 2:a2c141d922b3 75 void SpeedM2(uint8_t address, int32_t speed);
sype 2:a2c141d922b3 76 void SpeedAccelM1(uint8_t address, int32_t accel, int32_t speed);
sype 2:a2c141d922b3 77 void SpeedAccelM2(uint8_t address, int32_t accel, int32_t speed);
sype 2:a2c141d922b3 78 void SpeedDistanceM1(uint8_t address, int32_t speed, uint32_t distance, uint8_t buffer);
sype 2:a2c141d922b3 79 void SpeedDistanceM2(uint8_t address, int32_t speed, uint32_t distance, uint8_t buffer);
sype 2:a2c141d922b3 80 void SpeedAccelDistanceM1(uint8_t address, int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer);
sype 2:a2c141d922b3 81 void SpeedAccelDistanceM2(uint8_t address, int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer);
sype 2:a2c141d922b3 82 void SpeedAccelDeccelPositionM1(uint8_t address, uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag);
sype 2:a2c141d922b3 83 void SpeedAccelDeccelPositionM2(uint8_t address, uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag);
sype 2:a2c141d922b3 84 void SpeedAccelDeccelPositionM1M2(uint8_t address,uint32_t accel1,uint32_t speed1,uint32_t deccel1, int32_t position1,uint32_t accel2,uint32_t speed2,uint32_t deccel2, int32_t position2,uint8_t flag);
sype 0:af5cf35e1a25 85
sype 0:af5cf35e1a25 86 private:
sype 0:af5cf35e1a25 87 Serial _roboclaw;
sype 2:a2c141d922b3 88 uint16_t crc;
sype 0:af5cf35e1a25 89 void crc_clear();
sype 2:a2c141d922b3 90 void crc_update(uint8_t data);
sype 2:a2c141d922b3 91 uint16_t crc_get();
sype 0:af5cf35e1a25 92
sype 2:a2c141d922b3 93 void write_n(uint8_t cnt, ...);
sype 2:a2c141d922b3 94 void write_(uint8_t address, uint8_t command, uint8_t data, bool reading, bool crcon);
sype 0:af5cf35e1a25 95
sype 2:a2c141d922b3 96 uint16_t crc16(uint8_t *packet, int nBytes);
sype 2:a2c141d922b3 97 uint8_t read_(void);
sype 0:af5cf35e1a25 98 };
sype 0:af5cf35e1a25 99
sype 0:af5cf35e1a25 100 #endif