oklm

Dependents:   RoboClaw TestMyPathFind Robot2016_2-0_STATIC Stressed ... more

Committer:
sype
Date:
Thu Apr 28 08:22:13 2016 +0000
Revision:
9:0fc5514faed9
Parent:
5:ad00b3431ff5
Child:
10:f82bc24e3bd4
D?claration de l'adresse dans le constructeur, cette fois on est s?r ?a fonctionne (mais faudrait essayer)

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 9:0fc5514faed9 26 RoboClaw(uint8_t adr, 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 9:0fc5514faed9 33 void ForwardM1(int speed);
sype 9:0fc5514faed9 34 void BackwardM1(int speed);
sype 9:0fc5514faed9 35 void ForwardM2(int speed);
sype 9:0fc5514faed9 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 9:0fc5514faed9 43 void Forward(int speed);
sype 9:0fc5514faed9 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 9:0fc5514faed9 49 void ReadFirm();
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 9:0fc5514faed9 56 int32_t ReadEncM1();
sype 9:0fc5514faed9 57 int32_t ReadEncM2();
sype 9:0fc5514faed9 58 int32_t ReadSpeedM1();
sype 9:0fc5514faed9 59 int32_t ReadSpeedM2();
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 9:0fc5514faed9 64 void ResetEnc();
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 9:0fc5514faed9 74 void SpeedM1(int32_t speed);
sype 9:0fc5514faed9 75 void SpeedM2(int32_t speed);
sype 9:0fc5514faed9 76 void SpeedAccelM1(int32_t accel, int32_t speed);
sype 9:0fc5514faed9 77 void SpeedAccelM2(int32_t accel, int32_t speed);
sype 9:0fc5514faed9 78 void SpeedAccelM1M2(int32_t accel1, int32_t speed1, int32_t accel2, int32_t speed2);
sype 9:0fc5514faed9 79 void SpeedDistanceM1(int32_t speed, uint32_t distance, uint8_t buffer);
sype 9:0fc5514faed9 80 void SpeedDistanceM2(int32_t speed, uint32_t distance, uint8_t buffer);
sype 9:0fc5514faed9 81 void SpeedAccelDistanceM1(int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer);
sype 9:0fc5514faed9 82 void SpeedAccelDistanceM2(int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer);
sype 9:0fc5514faed9 83 void SpeedAccelDeccelPositionM1(uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag);
sype 9:0fc5514faed9 84 void SpeedAccelDeccelPositionM2(uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag);
sype 9:0fc5514faed9 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 9:0fc5514faed9 90 uint8_t address;
sype 0:af5cf35e1a25 91 void crc_clear();
sype 2:a2c141d922b3 92 void crc_update(uint8_t data);
sype 2:a2c141d922b3 93 uint16_t crc_get();
sype 0:af5cf35e1a25 94
sype 2:a2c141d922b3 95 void write_n(uint8_t cnt, ...);
sype 9:0fc5514faed9 96 void write_(uint8_t command, uint8_t data, bool reading, bool crcon);
sype 0:af5cf35e1a25 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