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@0:faf0960419c1, 2018-05-05 (annotated)
- Committer:
- garivetm
- Date:
- Sat May 05 15:41:25 2018 +0000
- Revision:
- 0:faf0960419c1
- Child:
- 1:57b8f6ed930b
First commit class structure and minimal stuff
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 | 0:faf0960419c1 | 18 | class RoboteqController : public PeripheralCAN{ |
garivetm | 0:faf0960419c1 | 19 | public: |
garivetm | 0:faf0960419c1 | 20 | /** Constructors and destructor |
garivetm | 0:faf0960419c1 | 21 | */ |
garivetm | 0:faf0960419c1 | 22 | RoboteqController(); |
garivetm | 0:faf0960419c1 | 23 | RoboteqController(uint8_t node_id, uint8_t mot_num); |
garivetm | 0:faf0960419c1 | 24 | ~RoboteqController(); |
garivetm | 0:faf0960419c1 | 25 | |
garivetm | 0:faf0960419c1 | 26 | /** Update callback by the CANController |
garivetm | 0:faf0960419c1 | 27 | * |
garivetm | 0:faf0960419c1 | 28 | * @param Id Id of the concerned data structure |
garivetm | 0:faf0960419c1 | 29 | * @param msg CANMessage instance containing the new data |
garivetm | 0:faf0960419c1 | 30 | */ |
garivetm | 0:faf0960419c1 | 31 | void update(const unsigned short& Id, const CANMessage& msg); |
garivetm | 0:faf0960419c1 | 32 | |
garivetm | 0:faf0960419c1 | 33 | |
garivetm | 0:faf0960419c1 | 34 | |
garivetm | 0:faf0960419c1 | 35 | private: |
garivetm | 0:faf0960419c1 | 36 | typedef struct { |
garivetm | 0:faf0960419c1 | 37 | uint8_t css; |
garivetm | 0:faf0960419c1 | 38 | uint8_t n; |
garivetm | 0:faf0960419c1 | 39 | uint16_t index; |
garivetm | 0:faf0960419c1 | 40 | uint8_t subindex; |
garivetm | 0:faf0960419c1 | 41 | uint8_t data[4]; |
garivetm | 0:faf0960419c1 | 42 | } SDOMessage; |
garivetm | 0:faf0960419c1 | 43 | /* 1> SDO CMD OR QUERY FRAME: |
garivetm | 0:faf0960419c1 | 44 | ----------------------------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 45 | Header | DLC | Payload |
garivetm | 0:faf0960419c1 | 46 | ----------------------------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 47 | | | Byte0 | Byte1-2 | Byte 3 | Bytes4-7 |
garivetm | 0:faf0960419c1 | 48 | --------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 49 | 0x600+nd | 8 | bits 4-7 bits2-3 bits0-1 | | | |
garivetm | 0:faf0960419c1 | 50 | --------------------------- |
garivetm | 0:faf0960419c1 | 51 | | | css n xx | index | subindex | data |
garivetm | 0:faf0960419c1 | 52 | Note: |
garivetm | 0:faf0960419c1 | 53 | • nd is the destination node id. |
garivetm | 0:faf0960419c1 | 54 | • ccs is the Client Command Specifier, if 2 it is command if 4 it is query. |
garivetm | 0:faf0960419c1 | 55 | • n is the Number of bytes in the data part which do not contain data |
garivetm | 0:faf0960419c1 | 56 | • xx not necessary for basic operation. For more details advise CANOpen standard. |
garivetm | 0:faf0960419c1 | 57 | • index is the object dictionary index of the data to be accessed |
garivetm | 0:faf0960419c1 | 58 | • subindex is the subindex of the object dictionary variable |
garivetm | 0:faf0960419c1 | 59 | • data contains the data to be uploaded. |
garivetm | 0:faf0960419c1 | 60 | |
garivetm | 0:faf0960419c1 | 61 | 2> SDO ANSWER FRAME: |
garivetm | 0:faf0960419c1 | 62 | ----------------------------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 63 | Header | DLC | Payload |
garivetm | 0:faf0960419c1 | 64 | ----------------------------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 65 | | | Byte0 | Byte1-2 | Byte 3 | Bytes4-7 |
garivetm | 0:faf0960419c1 | 66 | --------------------------------------------------------- |
garivetm | 0:faf0960419c1 | 67 | 0x580+nd | 8 | bits 4-7 bits2-3 bits0-1 | | | |
garivetm | 0:faf0960419c1 | 68 | --------------------------- |
garivetm | 0:faf0960419c1 | 69 | | | css n xx | index | subindex | data |
garivetm | 0:faf0960419c1 | 70 | Note: |
garivetm | 0:faf0960419c1 | 71 | • nd is the source node id. |
garivetm | 0:faf0960419c1 | 72 | • ccs is the Client Command Specifier, if 4 it is query response, 6 it is a successful |
garivetm | 0:faf0960419c1 | 73 | response to command, 8 is an error in message received. |
garivetm | 0:faf0960419c1 | 74 | • n is the Number of bytes in the data part which do not contain data |
garivetm | 0:faf0960419c1 | 75 | • xx not necessary for the simplistic way. For more details advise CANOpen standard. |
garivetm | 0:faf0960419c1 | 76 | • index is the object dictionary index of the data to be accessed. |
garivetm | 0:faf0960419c1 | 77 | • subindex is the subindex of the object dictionary variable |
garivetm | 0:faf0960419c1 | 78 | • data contains the data to be uploaded. Applicable only if css=4. |
garivetm | 0:faf0960419c1 | 79 | */ |
garivetm | 0:faf0960419c1 | 80 | void SDO_query(uint8_t n, uint16_t idx, uint8_t sub_idx); |
garivetm | 0:faf0960419c1 | 81 | void SDO_command(uint8_t n, uint16_t idx, uint8_t sub_idx, uint8_t *data); |
garivetm | 0:faf0960419c1 | 82 | void CANMsg2SDO(const CANMessage& CANmsg, SDOMessage& SDOmsg); |
garivetm | 0:faf0960419c1 | 83 | |
garivetm | 0:faf0960419c1 | 84 | uint8_t node_id; // Node id of the controller |
garivetm | 0:faf0960419c1 | 85 | uint8_t mot_num; // Motor number within the controller |
garivetm | 0:faf0960419c1 | 86 | |
garivetm | 0:faf0960419c1 | 87 | int16_t rotor_speed; // Rotor speed |
garivetm | 0:faf0960419c1 | 88 | |
garivetm | 0:faf0960419c1 | 89 | unsigned short Id_CSS_REQ; // CAN ID : CSS request (query or command) |
garivetm | 0:faf0960419c1 | 90 | unsigned short Id_CSS_ANS; // CAN ID : CSS answer (from query or command) |
garivetm | 0:faf0960419c1 | 91 | |
garivetm | 0:faf0960419c1 | 92 | }; |
garivetm | 0:faf0960419c1 | 93 | |
garivetm | 0:faf0960419c1 | 94 | #endif |