xx
RoboClaw.h@8:68669cccd769, 2016-04-28 (annotated)
- Committer:
- sype
- Date:
- Thu Apr 28 08:09:55 2016 +0000
- Revision:
- 8:68669cccd769
- Parent:
- 7:af0e3da221a9
R?vision librairie roboclaw
Who changed what in which revision?
User | Revision | Line number | New 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 | 8:68669cccd769 | 26 | RoboClaw(uint8_t ID, 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 | 7:af0e3da221a9 | 33 | void ForwardM1(int speed); |
sype | 7:af0e3da221a9 | 34 | void BackwardM1(int speed); |
sype | 7:af0e3da221a9 | 35 | void ForwardM2(int speed); |
sype | 7:af0e3da221a9 | 36 | void BackwardM2(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 | 7:af0e3da221a9 | 43 | void Forward(int speed); |
sype | 7:af0e3da221a9 | 44 | void Backward(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 | 7:af0e3da221a9 | 49 | void ReadFirm(void); |
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 | 7:af0e3da221a9 | 56 | int32_t ReadEncM1(void); |
sype | 7:af0e3da221a9 | 57 | int32_t ReadEncM2(void); |
sype | 7:af0e3da221a9 | 58 | int32_t ReadSpeedM1(void); |
sype | 7:af0e3da221a9 | 59 | int32_t ReadSpeedM2(void); |
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 | 7:af0e3da221a9 | 64 | void ResetEnc(void); |
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 | 7:af0e3da221a9 | 74 | void SpeedM1(int32_t speed); |
sype | 7:af0e3da221a9 | 75 | void SpeedM2(int32_t speed); |
sype | 7:af0e3da221a9 | 76 | void SpeedAccelM1(int32_t accel, int32_t speed); |
sype | 7:af0e3da221a9 | 77 | void SpeedAccelM2(int32_t accel, int32_t speed); |
sype | 7:af0e3da221a9 | 78 | void SpeedAccelM1M2(int32_t accel1, int32_t speed1, int32_t accel2, int32_t speed2); |
sype | 7:af0e3da221a9 | 79 | void SpeedDistanceM1(int32_t speed, uint32_t distance, uint8_t buffer); |
sype | 7:af0e3da221a9 | 80 | void SpeedDistanceM2(int32_t speed, uint32_t distance, uint8_t buffer); |
sype | 7:af0e3da221a9 | 81 | void SpeedAccelDistanceM1(int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer); |
sype | 7:af0e3da221a9 | 82 | void SpeedAccelDistanceM2(int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer); |
sype | 7:af0e3da221a9 | 83 | void SpeedAccelDeccelPositionM1(uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag); |
sype | 7:af0e3da221a9 | 84 | void SpeedAccelDeccelPositionM2(uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag); |
sype | 7:af0e3da221a9 | 85 | void SpeedAccelDeccelPositionM1M2(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 | 86 | |
sype | 0:af5cf35e1a25 | 87 | private: |
sype | 0:af5cf35e1a25 | 88 | Serial _roboclaw; |
sype | 2:a2c141d922b3 | 89 | uint16_t crc; |
sype | 0:af5cf35e1a25 | 90 | void crc_clear(); |
sype | 2:a2c141d922b3 | 91 | void crc_update(uint8_t data); |
sype | 2:a2c141d922b3 | 92 | uint16_t crc_get(); |
sype | 8:68669cccd769 | 93 | uint8_t address; |
sype | 0:af5cf35e1a25 | 94 | |
sype | 2:a2c141d922b3 | 95 | void write_n(uint8_t cnt, ...); |
sype | 7:af0e3da221a9 | 96 | void write_(uint8_t command, uint8_t data, bool reading, bool crcon); |
sype | 8:68669cccd769 | 97 | |
sype | 2:a2c141d922b3 | 98 | uint16_t crc16(uint8_t *packet, int nBytes); |
sype | 2:a2c141d922b3 | 99 | uint8_t read_(void); |
sype | 0:af5cf35e1a25 | 100 | }; |
sype | 0:af5cf35e1a25 | 101 | |
sype | 0:af5cf35e1a25 | 102 | #endif |