ricreato il link mancante

Committer:
marcodesilva
Date:
Mon Jan 10 20:38:41 2022 +0000
Revision:
4:31695331ce17
compila al 10/01/2022, da testare sul tool

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcodesilva 4:31695331ce17 1 #ifndef ROBOCLAW_H
marcodesilva 4:31695331ce17 2 #define ROBOCLAW_H
marcodesilva 4:31695331ce17 3 #include "mbed.h"
marcodesilva 4:31695331ce17 4 #include "registers.h"
marcodesilva 4:31695331ce17 5 #include "UARTSerial_mio.h"
marcodesilva 4:31695331ce17 6 /** The RoboClaw class, yo ucan use the library with : http://www.ionmc.com/RoboClaw-2x15A-Motor-Controller_p_10.html
marcodesilva 4:31695331ce17 7 * Used to control one or two motors with (or not) encoders
marcodesilva 4:31695331ce17 8 * @code
marcodesilva 4:31695331ce17 9 * #include "mbed.h"
marcodesilva 4:31695331ce17 10 * #include "RoboClaw.h"
marcodesilva 4:31695331ce17 11 *
marcodesilva 4:31695331ce17 12 * RoboClaw roboclaw(115200, PA_11, PA_12);
marcodesilva 4:31695331ce17 13 *
marcodesilva 4:31695331ce17 14 * int main() {
marcodesilva 4:31695331ce17 15 * roboclaw.ForwardM1(ADR, 127);
marcodesilva 4:31695331ce17 16 * while(1);
marcodesilva 4:31695331ce17 17 * }
marcodesilva 4:31695331ce17 18 * @endcode
marcodesilva 4:31695331ce17 19 */
marcodesilva 4:31695331ce17 20
marcodesilva 4:31695331ce17 21 class RoboClaw
marcodesilva 4:31695331ce17 22 {
marcodesilva 4:31695331ce17 23 public:
marcodesilva 4:31695331ce17 24 /** Create RoboClaw instance
marcodesilva 4:31695331ce17 25 */
marcodesilva 4:31695331ce17 26 RoboClaw(uint8_t adr, int baudrate, PinName rx, PinName tx, double _read_timeout);
marcodesilva 4:31695331ce17 27
marcodesilva 4:31695331ce17 28 /** Forward and Backward functions
marcodesilva 4:31695331ce17 29 * @param address address of the device
marcodesilva 4:31695331ce17 30 * @param speed speed of the motor (between 0 and 127)
marcodesilva 4:31695331ce17 31 * @note Forward and Backward functions
marcodesilva 4:31695331ce17 32 */
marcodesilva 4:31695331ce17 33 void ForwardM1(int speed);
marcodesilva 4:31695331ce17 34 void BackwardM1(int speed);
marcodesilva 4:31695331ce17 35 void ForwardM2(int speed);
marcodesilva 4:31695331ce17 36 void BackwardM2(int speed);
marcodesilva 4:31695331ce17 37
marcodesilva 4:31695331ce17 38 /** Forward and Backward functions
marcodesilva 4:31695331ce17 39 * @param address address of the device
marcodesilva 4:31695331ce17 40 * @param speed speed of the motor (between 0 and 127)
marcodesilva 4:31695331ce17 41 * @note Forward and Backward functions, it turns the two motors
marcodesilva 4:31695331ce17 42 */
marcodesilva 4:31695331ce17 43 void Forward(int speed);
marcodesilva 4:31695331ce17 44 void Backward(int speed);
marcodesilva 4:31695331ce17 45
marcodesilva 4:31695331ce17 46 /** Read the Firmware
marcodesilva 4:31695331ce17 47 * @param address address of the device
marcodesilva 4:31695331ce17 48 */
marcodesilva 4:31695331ce17 49 void ReadFirm();
marcodesilva 4:31695331ce17 50
marcodesilva 4:31695331ce17 51 /** Read encoder and speed of M1 or M2
marcodesilva 4:31695331ce17 52 * @param address address of the device
marcodesilva 4:31695331ce17 53 * @note Read encoder in ticks
marcodesilva 4:31695331ce17 54 * @note Read speed in ticks per second
marcodesilva 4:31695331ce17 55 */
marcodesilva 4:31695331ce17 56 bool ReadEncM1(int32_t &encPulse);
marcodesilva 4:31695331ce17 57 bool ReadEncM2(int32_t &encPulse);
marcodesilva 4:31695331ce17 58 bool ReadSpeedM1(int32_t &speed);
marcodesilva 4:31695331ce17 59 bool ReadSpeedM2(int32_t &speed);
marcodesilva 4:31695331ce17 60 bool ReadCurrentM1M2(int32_t &currentM1, int32_t &currentM2);
marcodesilva 4:31695331ce17 61
marcodesilva 4:31695331ce17 62
marcodesilva 4:31695331ce17 63 /** Set both encoders to zero
marcodesilva 4:31695331ce17 64 * @param address address of the device
marcodesilva 4:31695331ce17 65 */
marcodesilva 4:31695331ce17 66 void ResetEnc();
marcodesilva 4:31695331ce17 67
marcodesilva 4:31695331ce17 68 /** Set speed of Motor with different parameter (only in ticks)
marcodesilva 4:31695331ce17 69 * @param address address of the device
marcodesilva 4:31695331ce17 70 * @note Set the Speed
marcodesilva 4:31695331ce17 71 * @note Set the Speed and Accel
marcodesilva 4:31695331ce17 72 * @note Set the Speed and Distance
marcodesilva 4:31695331ce17 73 * @note Set the Speed, Accel and Distance
marcodesilva 4:31695331ce17 74 * @note Set the Speed, Accel, Decceleration and Position
marcodesilva 4:31695331ce17 75 */
marcodesilva 4:31695331ce17 76 void SpeedM1(int32_t speed);
marcodesilva 4:31695331ce17 77 void SpeedM2(int32_t speed);
marcodesilva 4:31695331ce17 78 void SpeedAccelM1(int32_t accel, int32_t speed);
marcodesilva 4:31695331ce17 79 void SpeedAccelM2(int32_t accel, int32_t speed);
marcodesilva 4:31695331ce17 80 void SpeedAccelM1M2(int32_t accel, int32_t speed1, int32_t speed2);
marcodesilva 4:31695331ce17 81 void SpeedDistanceM1(int32_t speed, uint32_t distance, uint8_t buffer);
marcodesilva 4:31695331ce17 82 void SpeedDistanceM2(int32_t speed, uint32_t distance, uint8_t buffer);
marcodesilva 4:31695331ce17 83 void SpeedAccelDistanceM1(int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer);
marcodesilva 4:31695331ce17 84 void SpeedAccelDistanceM2(int32_t accel, int32_t speed, uint32_t distance, uint8_t buffer);
marcodesilva 4:31695331ce17 85 void SpeedAccelDeccelPositionM1(uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag);
marcodesilva 4:31695331ce17 86 void SpeedAccelDeccelPositionM2(uint32_t accel, int32_t speed, uint32_t deccel, int32_t position, uint8_t flag);
marcodesilva 4:31695331ce17 87 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);
marcodesilva 4:31695331ce17 88
marcodesilva 4:31695331ce17 89 private:
marcodesilva 4:31695331ce17 90 UARTSerial_mio _roboclaw;
marcodesilva 4:31695331ce17 91 uint16_t crc;
marcodesilva 4:31695331ce17 92 uint8_t address;
marcodesilva 4:31695331ce17 93 void crc_clear();
marcodesilva 4:31695331ce17 94 void crc_update(uint8_t data);
marcodesilva 4:31695331ce17 95 uint16_t crc_get();
marcodesilva 4:31695331ce17 96
marcodesilva 4:31695331ce17 97 void write_n(uint8_t cnt, ...);
marcodesilva 4:31695331ce17 98 void write_(uint8_t command, uint8_t data, bool reading, bool crcon);
marcodesilva 4:31695331ce17 99
marcodesilva 4:31695331ce17 100 uint16_t crc16(uint8_t *packet, int nBytes);
marcodesilva 4:31695331ce17 101 int16_t read_(void);
marcodesilva 4:31695331ce17 102 bool read_n(uint8_t address, uint8_t cmd, int n_byte, int32_t &value);
marcodesilva 4:31695331ce17 103 void flushSerialBuffer(void);
marcodesilva 4:31695331ce17 104 void Rx_interrupt();
marcodesilva 4:31695331ce17 105 // Circular buffers for serial TX and RX data - used by interrupt routines
marcodesilva 4:31695331ce17 106 const int buffer_size = 7;
marcodesilva 4:31695331ce17 107 // might need to increase buffer size for high baud rates
marcodesilva 4:31695331ce17 108 char rx_buffer[7];
marcodesilva 4:31695331ce17 109 // Circular buffer pointers
marcodesilva 4:31695331ce17 110 // volatile makes read-modify-write atomic
marcodesilva 4:31695331ce17 111 //Timer readTimer;
marcodesilva 4:31695331ce17 112 //double readTime;
marcodesilva 4:31695331ce17 113 //double readTimePrec;
marcodesilva 4:31695331ce17 114 volatile int rx_in;
marcodesilva 4:31695331ce17 115 double read_timeout;
marcodesilva 4:31695331ce17 116 // Line buffers for sprintf and sscanf
marcodesilva 4:31695331ce17 117
marcodesilva 4:31695331ce17 118 char rx_line[80];
marcodesilva 4:31695331ce17 119 };
marcodesilva 4:31695331ce17 120
marcodesilva 4:31695331ce17 121 #endif