Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RoboClaw TestMyPathFind Robot2016_2-0_STATIC Stressed ... more
RoboClaw.h
00001 #ifndef ROBOCLAW_H 00002 #define ROBOCLAW_H 00003 #include "mbed.h" 00004 #include "registers.h" 00005 00006 /** The RoboClaw class, yo ucan use the library with : http://www.ionmc.com/RoboClaw-2x15A-Motor-Controller_p_10.html 00007 * Used to control one or two motors with (or not) encoders 00008 * @code 00009 * #include "mbed.h" 00010 * #include "RoboClaw.h" 00011 * 00012 * RoboClaw roboclaw(115200, PA_11, PA_12); 00013 * 00014 * int main() { 00015 * roboclaw.ForwardM1(ADR, 127); 00016 * while(1); 00017 * } 00018 * @endcode 00019 */ 00020 00021 class RoboClaw 00022 { 00023 public: 00024 /** Create RoboClaw instance 00025 */ 00026 RoboClaw(uint8_t adr, int baudrate, PinName rx, PinName tx); 00027 00028 /** Forward and Backward functions 00029 * @param address address of the device 00030 * @param speed speed of the motor (between 0 and 127) 00031 * @note Forward and Backward functions 00032 */ 00033 void ForwardM1(int speed); 00034 void BackwardM1(int speed); 00035 void ForwardM2(int speed); 00036 void BackwardM2(int speed); 00037 00038 /** Forward and Backward functions 00039 * @param address address of the device 00040 * @param speed speed of the motor (between 0 and 127) 00041 * @note Forward and Backward functions, it turns the two motors 00042 */ 00043 void Forward(int speed); 00044 void Backward(int speed); 00045 00046 /** Read the Firmware 00047 * @param address address of the device 00048 */ 00049 void ReadFirm(); 00050 00051 /** Read encoder and speed of M1 or M2 00052 * @param address address of the device 00053 * @note Read encoder in ticks 00054 * @note Read speed in ticks per second 00055 */ 00056 int32_t ReadEncM1(); 00057 int32_t ReadEncM2(); 00058 int32_t ReadSpeedM1(); 00059 int32_t ReadSpeedM2(); 00060 00061 /** Set both encoders to zero 00062 * @param address address of the device 00063 */ 00064 void ResetEnc(); 00065 00066 /** Set speed of Motor with different parameter (only in ticks) 00067 * @param address address of the device 00068 * @note Set the Speed 00069 * @note Set the Speed and Accel 00070 * @note Set the Speed and Distance 00071 * @note Set the Speed, Accel and Distance 00072 * @note Set the Speed, Accel, Decceleration and Position 00073 */ 00074 void SpeedM1(int32_t speed); 00075 void SpeedM2(int32_t speed); 00076 void SpeedAccelM1(int32_t accel, int32_t speed); 00077 void SpeedAccelM2(int32_t accel, int32_t speed); 00078 void SpeedAccelM1M2(int32_t accel, int32_t speed1, int32_t speed2); 00079 void SpeedDistanceM1(int32_t speed, uint32_t distance, uint8_t buffer); 00080 void SpeedDistanceM2(int32_t speed, uint32_t distance, uint8_t buffer); 00081 void SpeedAccelDistanceM1(int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer); 00082 void SpeedAccelDistanceM2(int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer); 00083 void SpeedAccelDeccelPositionM1(uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag); 00084 void SpeedAccelDeccelPositionM2(uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag); 00085 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); 00086 00087 private: 00088 Serial _roboclaw; 00089 uint16_t crc; 00090 uint8_t address; 00091 void crc_clear(); 00092 void crc_update(uint8_t data); 00093 uint16_t crc_get(); 00094 00095 void write_n(uint8_t cnt, ...); 00096 void write_(uint8_t command, uint8_t data, bool reading, bool crcon); 00097 00098 uint16_t crc16(uint8_t *packet, int nBytes); 00099 uint8_t read_(void); 00100 }; 00101 00102 #endif
Generated on Tue Jul 12 2022 19:03:11 by
1.7.2