A Roboteq controller c++ interface to allow a Brushless motor control on a CAN bus. Used for a FBL2360 reference.
Dependencies: CAN_FIFO_Triporteur
Diff: RoboteqController.h
- Revision:
- 3:a03c91082856
- Parent:
- 2:d61b4a989cab
- Child:
- 4:1ee0a235c997
diff -r d61b4a989cab -r a03c91082856 RoboteqController.h --- a/RoboteqController.h Thu May 17 14:26:20 2018 +0000 +++ b/RoboteqController.h Fri May 18 09:32:45 2018 +0000 @@ -14,6 +14,10 @@ // CAN id #define SDO_REQUEST 0x600 #define SDO_ANSWER 0x580 +#define ID_TPDO1 0x180 +#define ID_TPDO2 0x280 +#define ID_TPDO3 0x380 +#define ID_TPDO4 0x480 // Motor modes #define MODE_OPEN_LOOP 0 // Open-loop @@ -34,7 +38,15 @@ /** Constructors and destructor */ RoboteqController(); - RoboteqController(ControllerCAN* controller, uint8_t node_id, uint8_t mot_num); + + /** Constructor + * + * @param controller A pointer on the CAN controller + * @param node_id The controller node id + * @param mot_num Message number inside the controller + * @param TPDO_enabled A flag that enables reception of TPDO messages + */ + RoboteqController(ControllerCAN* controller, uint8_t node_id, uint8_t mot_num, bool TPDO_enabled); ~RoboteqController(); /** Update callback by the CANController @@ -44,9 +56,10 @@ */ void update(const unsigned short& Id, const CANMessage& msg); - + protected: - private: + static const uint16_t RPDO_ID[4]; // RPDO msg IDs to send data to the controller + typedef struct { uint8_t css; uint8_t n; @@ -93,8 +106,38 @@ */ 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); + + /** Helper function that convert a CAN message to a SDO message + * + * @param CANmsg A reference to the CAN message + * @param CANmsg A reference to the SDO message + */ void CANMsg2SDO(const CANMessage& CANmsg, SDOMessage& SDOmsg); + /** Send an RPDO message to the controller + * + * @param n The RPDO message number (from 1 to 4) + * @param user_var1 The first signed 32-bit integer to be send (the first 4 bytes) + * @param user_var2 The second signed 32-bit integer to be send (the last 4 bytes) + */ + void RPDO_send(uint8_t n, int32_t user_var1, int32_t user_var2); + + /** Parse a TPDO message to user variables + * + * @param CANmsg A reference to the CAN message + * @param user_var1 The first signed 32-bit integer to be read (the first 4 bytes) + * @param user_var2 The second signed 32-bit integer to be read (the last 4 bytes) + */ + void TPDO_parse(const CANMessage& CANmsg, int32_t &user_var1, int32_t &user_var2); + + /** Receive TPDO frames from the controller. If TPDO are used, this virtual + * method must be redefined in a class that inherits from this one. + * + * @param n The TPDO message number (from 1 to 4) + * @param CANmsg A reference to the CAN message + */ + virtual void TPDO_receive(uint8_t n, const CANMessage& CANmsg); + uint8_t node_id; // Node id of the controller uint8_t mot_num; // Motor number within the controller @@ -117,9 +160,9 @@ int16_t amp_bat; // Battery current (0.1 A) int16_t amp_motor; // Motor current (0.1 A) int16_t feedback; // Closed loop feedback - int32_t error // Closed loop error + int32_t error; // Closed loop error int8_t temp_MCU; // MCU temperature - int8_t temp_ch1 // channel 1 temperature + int8_t temp_ch1; // channel 1 temperature int8_t temp_ch2; // channel 2 temperature int32_t vars[16]; // Integer user variables bool booleans[16]; // Boolean user variables @@ -128,7 +171,10 @@ /* CAN Identifiers */ 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) - + unsigned short Id_TPDO1; // CAN ID : TPDO1 message + unsigned short Id_TPDO2; // CAN ID : TPDO2 message + unsigned short Id_TPDO3; // CAN ID : TPDO3 message + unsigned short Id_TPDO4; // CAN ID : TPDO4 message }; #endif \ No newline at end of file