下半身制御用ライブラリ Odometry...自己位置推定 Mecanum...メカナムホイール用 Bezier...ベジエ曲線 RoboClaw...MD用
Dependents: TOUTEKI_all_mbed mbed_test_program
RoboClaw.h@0:62707e16531a, 2018-09-01 (annotated)
- Committer:
- yuki17100
- Date:
- Sat Sep 01 09:07:35 2018 +0000
- Revision:
- 0:62707e16531a
???????????????MD??????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yuki17100 | 0:62707e16531a | 1 | #ifndef ROBOCLAW_H |
yuki17100 | 0:62707e16531a | 2 | #define ROBOCLAW_H |
yuki17100 | 0:62707e16531a | 3 | #include "mbed.h" |
yuki17100 | 0:62707e16531a | 4 | #include "registers.h" |
yuki17100 | 0:62707e16531a | 5 | |
yuki17100 | 0:62707e16531a | 6 | /* |
yuki17100 | 0:62707e16531a | 7 | * 一般公開されているライブラリのマイナーチェンジである |
yuki17100 | 0:62707e16531a | 8 | * Serial -> RawSerial |
yuki17100 | 0:62707e16531a | 9 | * 指令時にアドレスを指定できるものを利用した |
yuki17100 | 0:62707e16531a | 10 | * |
yuki17100 | 0:62707e16531a | 11 | */ |
yuki17100 | 0:62707e16531a | 12 | |
yuki17100 | 0:62707e16531a | 13 | /** The RoboClaw class, yo ucan use the library with : http://www.ionmc.com/RoboClaw-2x15A-Motor-Controller_p_10.html |
yuki17100 | 0:62707e16531a | 14 | * Used to control one or two motors with (or not) encoders |
yuki17100 | 0:62707e16531a | 15 | * @code |
yuki17100 | 0:62707e16531a | 16 | * #include "mbed.h" |
yuki17100 | 0:62707e16531a | 17 | * #include "RoboClaw.h" |
yuki17100 | 0:62707e16531a | 18 | * |
yuki17100 | 0:62707e16531a | 19 | * RoboClaw roboclaw(115200, PA_11, PA_12); |
yuki17100 | 0:62707e16531a | 20 | * |
yuki17100 | 0:62707e16531a | 21 | * int main() { |
yuki17100 | 0:62707e16531a | 22 | * roboclaw.ForwardM1(ADR, 127); |
yuki17100 | 0:62707e16531a | 23 | * while(1); |
yuki17100 | 0:62707e16531a | 24 | * } |
yuki17100 | 0:62707e16531a | 25 | * @endcode |
yuki17100 | 0:62707e16531a | 26 | */ |
yuki17100 | 0:62707e16531a | 27 | |
yuki17100 | 0:62707e16531a | 28 | class RoboClaw |
yuki17100 | 0:62707e16531a | 29 | { |
yuki17100 | 0:62707e16531a | 30 | public: |
yuki17100 | 0:62707e16531a | 31 | /** Create RoboClaw instance |
yuki17100 | 0:62707e16531a | 32 | */ |
yuki17100 | 0:62707e16531a | 33 | RoboClaw(int baudrate, PinName rx, PinName tx); |
yuki17100 | 0:62707e16531a | 34 | |
yuki17100 | 0:62707e16531a | 35 | /** Forward and Backward functions |
yuki17100 | 0:62707e16531a | 36 | * @param address address of the device |
yuki17100 | 0:62707e16531a | 37 | * @param speed speed of the motor (between 0 and 127) |
yuki17100 | 0:62707e16531a | 38 | * @note Forward and Backward functions |
yuki17100 | 0:62707e16531a | 39 | */ |
yuki17100 | 0:62707e16531a | 40 | void ForwardM1(uint8_t address, int speed); |
yuki17100 | 0:62707e16531a | 41 | void BackwardM1(uint8_t address, int speed); |
yuki17100 | 0:62707e16531a | 42 | void ForwardM2(uint8_t address, int speed); |
yuki17100 | 0:62707e16531a | 43 | void BackwardM2(uint8_t address, int speed); |
yuki17100 | 0:62707e16531a | 44 | |
yuki17100 | 0:62707e16531a | 45 | /** Forward and Backward functions |
yuki17100 | 0:62707e16531a | 46 | * @param address address of the device |
yuki17100 | 0:62707e16531a | 47 | * @param speed speed of the motor (between 0 and 127) |
yuki17100 | 0:62707e16531a | 48 | * @note Forward and Backward functions, it turns the two motors |
yuki17100 | 0:62707e16531a | 49 | */ |
yuki17100 | 0:62707e16531a | 50 | void Forward(uint8_t address, int speed); |
yuki17100 | 0:62707e16531a | 51 | void Backward(uint8_t address, int speed); |
yuki17100 | 0:62707e16531a | 52 | |
yuki17100 | 0:62707e16531a | 53 | /** Read the Firmware |
yuki17100 | 0:62707e16531a | 54 | * @param address address of the device |
yuki17100 | 0:62707e16531a | 55 | */ |
yuki17100 | 0:62707e16531a | 56 | void ReadFirm(uint8_t address); |
yuki17100 | 0:62707e16531a | 57 | |
yuki17100 | 0:62707e16531a | 58 | /** Read encoder and speed of M1 or M2 |
yuki17100 | 0:62707e16531a | 59 | * @param address address of the device |
yuki17100 | 0:62707e16531a | 60 | * @note Read encoder in ticks |
yuki17100 | 0:62707e16531a | 61 | * @note Read speed in ticks per second |
yuki17100 | 0:62707e16531a | 62 | */ |
yuki17100 | 0:62707e16531a | 63 | int32_t ReadEncM1(uint8_t address); |
yuki17100 | 0:62707e16531a | 64 | int32_t ReadEncM2(uint8_t address); |
yuki17100 | 0:62707e16531a | 65 | int32_t ReadSpeedM1(uint8_t address); |
yuki17100 | 0:62707e16531a | 66 | int32_t ReadSpeedM2(uint8_t address); |
yuki17100 | 0:62707e16531a | 67 | |
yuki17100 | 0:62707e16531a | 68 | /** Set both encoders to zero |
yuki17100 | 0:62707e16531a | 69 | * @param address address of the device |
yuki17100 | 0:62707e16531a | 70 | */ |
yuki17100 | 0:62707e16531a | 71 | void ResetEnc(uint8_t address); |
yuki17100 | 0:62707e16531a | 72 | |
yuki17100 | 0:62707e16531a | 73 | /** Set speed of Motor with different parameter (only in ticks) |
yuki17100 | 0:62707e16531a | 74 | * @param address address of the device |
yuki17100 | 0:62707e16531a | 75 | * @note Set the Speed |
yuki17100 | 0:62707e16531a | 76 | * @note Set the Speed and Accel |
yuki17100 | 0:62707e16531a | 77 | * @note Set the Speed and Distance |
yuki17100 | 0:62707e16531a | 78 | * @note Set the Speed, Accel and Distance |
yuki17100 | 0:62707e16531a | 79 | * @note Set the Speed, Accel, Decceleration and Position |
yuki17100 | 0:62707e16531a | 80 | */ |
yuki17100 | 0:62707e16531a | 81 | void SpeedM1(uint8_t address, int32_t speed); |
yuki17100 | 0:62707e16531a | 82 | void SpeedM2(uint8_t address, int32_t speed); |
yuki17100 | 0:62707e16531a | 83 | void SpeedAccelM1(uint8_t address, int32_t accel, int32_t speed); |
yuki17100 | 0:62707e16531a | 84 | void SpeedAccelM2(uint8_t address, int32_t accel, int32_t speed); |
yuki17100 | 0:62707e16531a | 85 | void SpeedAccelM1M2(uint8_t address, int32_t accel1, int32_t speed1, int32_t accel2, int32_t speed2); |
yuki17100 | 0:62707e16531a | 86 | void SpeedDistanceM1(uint8_t address, int32_t speed, uint32_t distance, uint8_t buffer); |
yuki17100 | 0:62707e16531a | 87 | void SpeedDistanceM2(uint8_t address, int32_t speed, uint32_t distance, uint8_t buffer); |
yuki17100 | 0:62707e16531a | 88 | void SpeedAccelDistanceM1(uint8_t address, int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer); |
yuki17100 | 0:62707e16531a | 89 | void SpeedAccelDistanceM2(uint8_t address, int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer); |
yuki17100 | 0:62707e16531a | 90 | void SpeedAccelDeccelPositionM1(uint8_t address, uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag); |
yuki17100 | 0:62707e16531a | 91 | void SpeedAccelDeccelPositionM2(uint8_t address, uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag); |
yuki17100 | 0:62707e16531a | 92 | 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); |
yuki17100 | 0:62707e16531a | 93 | |
yuki17100 | 0:62707e16531a | 94 | private: |
yuki17100 | 0:62707e16531a | 95 | RawSerial _roboclaw; |
yuki17100 | 0:62707e16531a | 96 | uint16_t crc; |
yuki17100 | 0:62707e16531a | 97 | void crc_clear(); |
yuki17100 | 0:62707e16531a | 98 | void crc_update(uint8_t data); |
yuki17100 | 0:62707e16531a | 99 | uint16_t crc_get(); |
yuki17100 | 0:62707e16531a | 100 | |
yuki17100 | 0:62707e16531a | 101 | void write_n(uint8_t cnt, ...); |
yuki17100 | 0:62707e16531a | 102 | void write_(uint8_t address, uint8_t command, uint8_t data, bool reading, bool crcon); |
yuki17100 | 0:62707e16531a | 103 | |
yuki17100 | 0:62707e16531a | 104 | uint16_t crc16(uint8_t *packet, int nBytes); |
yuki17100 | 0:62707e16531a | 105 | uint8_t read_(void); |
yuki17100 | 0:62707e16531a | 106 | }; |
yuki17100 | 0:62707e16531a | 107 | |
yuki17100 | 0:62707e16531a | 108 | #endif |