A Roboteq controller c++ interface to allow a Brushless motor control on a CAN bus. Used for a FBL2360 reference.
Dependencies: CAN_FIFO_Triporteur
RoboteqController.h@2:d61b4a989cab, 2018-05-17 (annotated)
- Committer:
- garivetm
- Date:
- Thu May 17 14:26:20 2018 +0000
- Revision:
- 2:d61b4a989cab
- Parent:
- 1:57b8f6ed930b
- Child:
- 3:a03c91082856
Ajout des attributs moteur principaux
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
garivetm | 0:faf0960419c1 | 1 | #ifndef ROBOTEQ_CONTROLLER_H |
garivetm | 0:faf0960419c1 | 2 | #define ROBOTEQ_CONTROLLER_H |
garivetm | 0:faf0960419c1 | 3 | |
garivetm | 0:faf0960419c1 | 4 | #include "mbed.h" |
garivetm | 0:faf0960419c1 | 5 | #include "PeripheralCAN.h" |
garivetm | 0:faf0960419c1 | 6 | #include "object_dict.h" |
garivetm | 0:faf0960419c1 | 7 | |
garivetm | 0:faf0960419c1 | 8 | // Client Command Specifier |
garivetm | 0:faf0960419c1 | 9 | #define CSS_CMD 2 |
garivetm | 0:faf0960419c1 | 10 | #define CSS_QUERY 4 |
garivetm | 0:faf0960419c1 | 11 | #define CSS_SUCCES 6 |
garivetm | 0:faf0960419c1 | 12 | #define CSS_ERR 8 |
garivetm | 0:faf0960419c1 | 13 | |
garivetm | 0:faf0960419c1 | 14 | // CAN id |
garivetm | 0:faf0960419c1 | 15 | #define SDO_REQUEST 0x600 |
garivetm | 0:faf0960419c1 | 16 | #define SDO_ANSWER 0x580 |
garivetm | 0:faf0960419c1 | 17 | |
garivetm | 2:d61b4a989cab | 18 | // Motor modes |
garivetm | 2:d61b4a989cab | 19 | #define MODE_OPEN_LOOP 0 // Open-loop |
garivetm | 2:d61b4a989cab | 20 | #define MODE_CLOSED_SPEED 1 // Closed-loop speed |
garivetm | 2:d61b4a989cab | 21 | #define MODE_CLOSED_POS_REL 2 // Closed-loop position relative |
garivetm | 2:d61b4a989cab | 22 | #define MODE_CLOSED_COUNT_POS 3 // Closed-loop count position |
garivetm | 2:d61b4a989cab | 23 | #define MODE_CLOSED_POS_TRACK 4 // Closed-loop position tracking |
garivetm | 2:d61b4a989cab | 24 | #define MODE_CLOSED_TORQUE 5 // Torque |
garivetm | 2:d61b4a989cab | 25 | #define MODE_CLOSED_SPEED_POS 6 // Closed-loop speed position |
garivetm | 2:d61b4a989cab | 26 | |
garivetm | 2:d61b4a989cab | 27 | // Temperatures |
garivetm | 2:d61b4a989cab | 28 | #define TEMPERATURE_MCU 1 // Mcu temperature |
garivetm | 2:d61b4a989cab | 29 | #define TEMPERATURE_CH1 2 // Channel 1 heatsink |
garivetm | 2:d61b4a989cab | 30 | #define TEMPERATURE_CH2 3 // Channel 2 heatsink |
garivetm | 2:d61b4a989cab | 31 | |
garivetm | 0:faf0960419c1 | 32 | class RoboteqController : public PeripheralCAN{ |
garivetm | 0:faf0960419c1 | 33 | public: |
garivetm | 0:faf0960419c1 | 34 | /** Constructors and destructor |
garivetm | 0:faf0960419c1 | 35 | */ |
garivetm | 0:faf0960419c1 | 36 | RoboteqController(); |
garivetm | 1:57b8f6ed930b | 37 | RoboteqController(ControllerCAN* controller, uint8_t node_id, uint8_t mot_num); |
garivetm | 0:faf0960419c1 | 38 | ~RoboteqController(); |
garivetm | 0:faf0960419c1 | 39 | |
garivetm | 0:faf0960419c1 | 40 | /** Update callback by the CANController |
garivetm | 0:faf0960419c1 | 41 | * |
garivetm | 0:faf0960419c1 | 42 | * @param Id Id of the concerned data structure |
garivetm | 0:faf0960419c1 | 43 | * @param msg CANMessage instance containing the new data |
garivetm | 0:faf0960419c1 | 44 | */ |
garivetm | 0:faf0960419c1 | 45 | void update(const unsigned short& Id, const CANMessage& msg); |
garivetm | 0:faf0960419c1 | 46 | |
garivetm | 0:faf0960419c1 | 47 | |
garivetm | 0:faf0960419c1 | 48 | |
garivetm | 0:faf0960419c1 | 49 | private: |
garivetm | 0:faf0960419c1 | 50 | typedef struct { |
garivetm | 0:faf0960419c1 | 51 | uint8_t css; |
garivetm | 0:faf0960419c1 | 52 | uint8_t n; |
garivetm | 0:faf0960419c1 | 53 | uint16_t index; |
garivetm | 0:faf0960419c1 | 54 | uint8_t subindex; |
garivetm | 0:faf0960419c1 | 55 | uint8_t data[4]; |
garivetm | 0:faf0960419c1 | 56 | } SDOMessage; |
garivetm | 0:faf0960419c1 | 57 | /* 1> SDO CMD OR QUERY FRAME: |
garivetm | 0:faf0960419c1 | 58 | ----------------------------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 59 | Header | DLC | Payload |
garivetm | 0:faf0960419c1 | 60 | ----------------------------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 61 | | | Byte0 | Byte1-2 | Byte 3 | Bytes4-7 |
garivetm | 0:faf0960419c1 | 62 | --------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 63 | 0x600+nd | 8 | bits 4-7 bits2-3 bits0-1 | | | |
garivetm | 0:faf0960419c1 | 64 | --------------------------- |
garivetm | 0:faf0960419c1 | 65 | | | css n xx | index | subindex | data |
garivetm | 0:faf0960419c1 | 66 | Note: |
garivetm | 0:faf0960419c1 | 67 | • nd is the destination node id. |
garivetm | 0:faf0960419c1 | 68 | • ccs is the Client Command Specifier, if 2 it is command if 4 it is query. |
garivetm | 0:faf0960419c1 | 69 | • n is the Number of bytes in the data part which do not contain data |
garivetm | 0:faf0960419c1 | 70 | • xx not necessary for basic operation. For more details advise CANOpen standard. |
garivetm | 0:faf0960419c1 | 71 | • index is the object dictionary index of the data to be accessed |
garivetm | 0:faf0960419c1 | 72 | • subindex is the subindex of the object dictionary variable |
garivetm | 0:faf0960419c1 | 73 | • data contains the data to be uploaded. |
garivetm | 0:faf0960419c1 | 74 | |
garivetm | 0:faf0960419c1 | 75 | 2> SDO ANSWER FRAME: |
garivetm | 0:faf0960419c1 | 76 | ----------------------------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 77 | Header | DLC | Payload |
garivetm | 0:faf0960419c1 | 78 | ----------------------------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 79 | | | Byte0 | Byte1-2 | Byte 3 | Bytes4-7 |
garivetm | 0:faf0960419c1 | 80 | --------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 81 | 0x580+nd | 8 | bits 4-7 bits2-3 bits0-1 | | | |
garivetm | 0:faf0960419c1 | 82 | --------------------------- |
garivetm | 0:faf0960419c1 | 83 | | | css n xx | index | subindex | data |
garivetm | 0:faf0960419c1 | 84 | Note: |
garivetm | 0:faf0960419c1 | 85 | • nd is the source node id. |
garivetm | 0:faf0960419c1 | 86 | • ccs is the Client Command Specifier, if 4 it is query response, 6 it is a successful |
garivetm | 0:faf0960419c1 | 87 | response to command, 8 is an error in message received. |
garivetm | 0:faf0960419c1 | 88 | • n is the Number of bytes in the data part which do not contain data |
garivetm | 0:faf0960419c1 | 89 | • xx not necessary for the simplistic way. For more details advise CANOpen standard. |
garivetm | 0:faf0960419c1 | 90 | • index is the object dictionary index of the data to be accessed. |
garivetm | 0:faf0960419c1 | 91 | • subindex is the subindex of the object dictionary variable |
garivetm | 0:faf0960419c1 | 92 | • data contains the data to be uploaded. Applicable only if css=4. |
garivetm | 0:faf0960419c1 | 93 | */ |
garivetm | 0:faf0960419c1 | 94 | void SDO_query(uint8_t n, uint16_t idx, uint8_t sub_idx); |
garivetm | 0:faf0960419c1 | 95 | void SDO_command(uint8_t n, uint16_t idx, uint8_t sub_idx, uint8_t *data); |
garivetm | 0:faf0960419c1 | 96 | void CANMsg2SDO(const CANMessage& CANmsg, SDOMessage& SDOmsg); |
garivetm | 0:faf0960419c1 | 97 | |
garivetm | 0:faf0960419c1 | 98 | uint8_t node_id; // Node id of the controller |
garivetm | 0:faf0960419c1 | 99 | uint8_t mot_num; // Motor number within the controller |
garivetm | 0:faf0960419c1 | 100 | |
garivetm | 2:d61b4a989cab | 101 | /* General Configuration and Safety */ |
garivetm | 2:d61b4a989cab | 102 | // TBD |
garivetm | 2:d61b4a989cab | 103 | |
garivetm | 2:d61b4a989cab | 104 | /* Analog, Digital, Pulse IO Configurations */ |
garivetm | 2:d61b4a989cab | 105 | // TBD |
garivetm | 0:faf0960419c1 | 106 | |
garivetm | 2:d61b4a989cab | 107 | /* Motor configuration (non-exhaustiv list) */ |
garivetm | 2:d61b4a989cab | 108 | uint16_t alim; // Motor ampere limit (0.1 A) |
garivetm | 2:d61b4a989cab | 109 | uint8_t kp; // PID proportionnal gain |
garivetm | 2:d61b4a989cab | 110 | uint8_t ki; // PID integral gain |
garivetm | 2:d61b4a989cab | 111 | uint8_t kd; // PID derivative gain |
garivetm | 2:d61b4a989cab | 112 | int32_t mac; // Motor acceleration rate (0.1 RPM) |
garivetm | 2:d61b4a989cab | 113 | int32_t mdec; // Motor deceleration rate (0.1 RPM) |
garivetm | 2:d61b4a989cab | 114 | uint8_t mmod; // Motor mode |
garivetm | 2:d61b4a989cab | 115 | uint16_t mxrpm; // Maximal RPM value (eq to a cmd of 1000) |
garivetm | 2:d61b4a989cab | 116 | |
garivetm | 2:d61b4a989cab | 117 | int16_t amp_bat; // Battery current (0.1 A) |
garivetm | 2:d61b4a989cab | 118 | int16_t amp_motor; // Motor current (0.1 A) |
garivetm | 2:d61b4a989cab | 119 | int16_t feedback; // Closed loop feedback |
garivetm | 2:d61b4a989cab | 120 | int32_t error // Closed loop error |
garivetm | 2:d61b4a989cab | 121 | int8_t temp_MCU; // MCU temperature |
garivetm | 2:d61b4a989cab | 122 | int8_t temp_ch1 // channel 1 temperature |
garivetm | 2:d61b4a989cab | 123 | int8_t temp_ch2; // channel 2 temperature |
garivetm | 2:d61b4a989cab | 124 | int32_t vars[16]; // Integer user variables |
garivetm | 2:d61b4a989cab | 125 | bool booleans[16]; // Boolean user variables |
garivetm | 2:d61b4a989cab | 126 | int16_t speed; // Rotor speed |
garivetm | 2:d61b4a989cab | 127 | |
garivetm | 2:d61b4a989cab | 128 | /* CAN Identifiers */ |
garivetm | 0:faf0960419c1 | 129 | unsigned short Id_CSS_REQ; // CAN ID : CSS request (query or command) |
garivetm | 0:faf0960419c1 | 130 | unsigned short Id_CSS_ANS; // CAN ID : CSS answer (from query or command) |
garivetm | 0:faf0960419c1 | 131 | |
garivetm | 0:faf0960419c1 | 132 | }; |
garivetm | 0:faf0960419c1 | 133 | |
garivetm | 0:faf0960419c1 | 134 | #endif |