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
- Committer:
- garivetm
- Date:
- 2018-05-05
- Revision:
- 1:57b8f6ed930b
- Parent:
- 0:faf0960419c1
- Child:
- 2:d61b4a989cab
File content as of revision 1:57b8f6ed930b:
#ifndef ROBOTEQ_CONTROLLER_H #define ROBOTEQ_CONTROLLER_H #include "mbed.h" #include "PeripheralCAN.h" #include "object_dict.h" // Client Command Specifier #define CSS_CMD 2 #define CSS_QUERY 4 #define CSS_SUCCES 6 #define CSS_ERR 8 // CAN id #define SDO_REQUEST 0x600 #define SDO_ANSWER 0x580 class RoboteqController : public PeripheralCAN{ public: /** Constructors and destructor */ RoboteqController(); RoboteqController(ControllerCAN* controller, uint8_t node_id, uint8_t mot_num); ~RoboteqController(); /** Update callback by the CANController * * @param Id Id of the concerned data structure * @param msg CANMessage instance containing the new data */ void update(const unsigned short& Id, const CANMessage& msg); private: typedef struct { uint8_t css; uint8_t n; uint16_t index; uint8_t subindex; uint8_t data[4]; } SDOMessage; /* 1> SDO CMD OR QUERY FRAME: ----------------------------------------------------------------------------- Header | DLC | Payload ----------------------------------------------------------------------------- | | Byte0 | Byte1-2 | Byte 3 | Bytes4-7 --------------------------------------------------------- 0x600+nd | 8 | bits 4-7 bits2-3 bits0-1 | | | --------------------------- | | css n xx | index | subindex | data Note: • nd is the destination node id. • ccs is the Client Command Specifier, if 2 it is command if 4 it is query. • n is the Number of bytes in the data part which do not contain data • xx not necessary for basic operation. For more details advise CANOpen standard. • index is the object dictionary index of the data to be accessed • subindex is the subindex of the object dictionary variable • data contains the data to be uploaded. 2> SDO ANSWER FRAME: ----------------------------------------------------------------------------- Header | DLC | Payload ----------------------------------------------------------------------------- | | Byte0 | Byte1-2 | Byte 3 | Bytes4-7 --------------------------------------------------------- 0x580+nd | 8 | bits 4-7 bits2-3 bits0-1 | | | --------------------------- | | css n xx | index | subindex | data Note: • nd is the source node id. • ccs is the Client Command Specifier, if 4 it is query response, 6 it is a successful response to command, 8 is an error in message received. • n is the Number of bytes in the data part which do not contain data • xx not necessary for the simplistic way. For more details advise CANOpen standard. • index is the object dictionary index of the data to be accessed. • subindex is the subindex of the object dictionary variable • data contains the data to be uploaded. Applicable only if css=4. */ void SDO_query(uint8_t n, uint16_t idx, uint8_t sub_idx); void SDO_command(uint8_t n, uint16_t idx, uint8_t sub_idx, uint8_t *data); void CANMsg2SDO(const CANMessage& CANmsg, SDOMessage& SDOmsg); uint8_t node_id; // Node id of the controller uint8_t mot_num; // Motor number within the controller int16_t rotor_speed; // Rotor speed unsigned short Id_CSS_REQ; // CAN ID : CSS request (query or command) unsigned short Id_CSS_ANS; // CAN ID : CSS answer (from query or command) }; #endif