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