Tetrapod Project
make_can_msg.cpp
Go to the documentation of this file.
1 #include "make_can_msg.h"
2 
3 void make_can_msg::readPIDParameters(unsigned char* _can_message)
4 {
5  emptyCanMessage(_can_message);
6  _can_message[0] = MOTOR_COMMAND_READ_PID_PARAMETERS;
7 }
8 
9 void make_can_msg::writePIDParametersToRAM(unsigned char* _can_message,
10  unsigned char _k_p_position,
11  unsigned char _k_i_position,
12  unsigned char _k_p_speed,
13  unsigned char _k_i_speed,
14  unsigned char _k_p_torque,
15  unsigned char _k_i_torque)
16 {
17  emptyCanMessage(_can_message);
19  _can_message[2] = _k_p_position;
20  _can_message[3] = _k_i_position;
21  _can_message[4] = _k_p_speed;
22  _can_message[5] = _k_i_speed;
23  _can_message[6] = _k_p_torque;
24  _can_message[7] = _k_i_torque;
25 }
26 
27 void make_can_msg::writePIDParametersToROM(unsigned char* _can_message,
28  unsigned char _k_p_position,
29  unsigned char _k_i_position,
30  unsigned char _k_p_speed,
31  unsigned char _k_i_speed,
32  unsigned char _k_p_torque,
33  unsigned char _k_i_torque)
34 {
35  emptyCanMessage(_can_message);
37  _can_message[2] = _k_p_position;
38  _can_message[3] = _k_i_position;
39  _can_message[4] = _k_p_speed;
40  _can_message[5] = _k_i_speed;
41  _can_message[6] = _k_p_torque;
42  _can_message[7] = _k_i_torque;
43 }
44 
45 void make_can_msg::readAcceleration(unsigned char* _can_message)
46 {
47  emptyCanMessage(_can_message);
48  _can_message[0] = MOTOR_COMMAND_READ_ACCELERATION;
49 }
50 
51 void make_can_msg::writeAccelerationToRAM(unsigned char* _can_message, int32_t _acceleration)
52 {
53  emptyCanMessage(_can_message);
55  _can_message[4] = *(uint8_t *)(&_acceleration);
56  _can_message[5] = *((uint8_t *)(&_acceleration) + 1);
57  _can_message[6] = *((uint8_t *)(&_acceleration) + 2);
58  _can_message[7] = *((uint8_t *)(&_acceleration) + 3);
59 }
60 
61 void make_can_msg::readEncoderPosition(unsigned char* _can_message)
62 {
63  emptyCanMessage(_can_message);
64  _can_message[0] = MOTOR_COMMAND_READ_ENCODER_POSITION;
65 }
66 
67 void make_can_msg::writeEncoderPositionOffset(unsigned char* _can_message, uint16_t _encoder_offset)
68 {
69  emptyCanMessage(_can_message);
71  _can_message[6] = *(uint8_t *)(&_encoder_offset);
72  _can_message[7] = *((uint8_t *)(&_encoder_offset) + 1);
73 }
74 
75 void make_can_msg::writeCurrentPositionToROM(unsigned char* _can_message)
76 {
77  emptyCanMessage(_can_message);
79 }
80 
81 void make_can_msg::readMultiTurnAngle(unsigned char* _can_message)
82 {
83  emptyCanMessage(_can_message);
84  _can_message[0] = MOTOR_COMMAND_READ_MULTI_TURN_ANGLE;
85 }
86 
87 void make_can_msg::readCircleTurnAngle(unsigned char* _can_message)
88 {
89  emptyCanMessage(_can_message);
91 }
92 
93 void make_can_msg::motorOff(unsigned char* _can_message)
94 {
95  emptyCanMessage(_can_message);
96  _can_message[0] = MOTOR_COMMAND_MOTOR_OFF;
97 }
98 
99 void make_can_msg::motorStop(unsigned char* _can_message)
100 {
101  emptyCanMessage(_can_message);
102  _can_message[0] = MOTOR_COMMAND_MOTOR_STOP;
103 }
104 void make_can_msg::motorRunning(unsigned char* _can_message)
105 {
106  emptyCanMessage(_can_message);
107  _can_message[0] = MOTOR_COMMAND_MOTOR_RUNNING;
108 }
109 
110 void make_can_msg::readMotorStatus1AndErrorFlag(unsigned char* _can_message)
111 {
112  emptyCanMessage(_can_message);
114 }
115 
116 void make_can_msg::clearMotorErrorFlag(unsigned char* _can_message)
117 {
118  emptyCanMessage(_can_message);
119  _can_message[0] = MOTOR_COMMAND_CLEAR_MOTOR_ERROR_FLAG;
120 }
121 
122 void make_can_msg::readMotorStatus2(unsigned char* _can_message)
123 {
124  emptyCanMessage(_can_message);
125  _can_message[0] = MOTOR_COMMAND_READ_MOTOR_STATUS_2;
126 }
127 
128 void make_can_msg::readMotorStatus3(unsigned char* _can_message)
129 {
130  emptyCanMessage(_can_message);
131  _can_message[0] = MOTOR_COMMAND_READ_MOTOR_STATUS_3;
132 }
133 
134 void make_can_msg::torqueCurrentControl(unsigned char* _can_message, int16_t _torque_current)
135 {
136  emptyCanMessage(_can_message);
137  _can_message[0] = MOTOR_COMMAND_TORQUE_CLOSED_LOOP;
138  _can_message[4] = *(uint8_t *)(&_torque_current);
139  _can_message[5] = *((uint8_t *)(&_torque_current) + 1);
140 }
141 
142 void make_can_msg::speedControl(unsigned char* _can_message, int32_t _speed)
143 {
144  emptyCanMessage(_can_message);
145  _can_message[0] = MOTOR_COMMAND_SPEED_CLOSED_LOOP;
146  _can_message[4] = *(uint8_t *)(&_speed);
147  _can_message[5] = *((uint8_t *)(&_speed) + 1);
148  _can_message[6] = *((uint8_t *)(&_speed) + 2);
149  _can_message[7] = *((uint8_t *)(&_speed) + 3);
150 }
151 
152 void make_can_msg::positionControl1(unsigned char* _can_message, int32_t _multiturn_angle)
153 {
154  emptyCanMessage(_can_message);
155  _can_message[0] = MOTOR_COMMAND_POSITION_CLOSED_LOOP_1;
156  _can_message[4] = *(uint8_t *)(&_multiturn_angle);
157  _can_message[5] = *((uint8_t *)(&_multiturn_angle) + 1);
158  _can_message[6] = *((uint8_t *)(&_multiturn_angle) + 2);
159  _can_message[7] = *((uint8_t *)(&_multiturn_angle) + 3);
160 }
161 
162 void make_can_msg::positionControl2(unsigned char* _can_message, int32_t _multiturn_angle, uint16_t _max_speed)
163 {
164  emptyCanMessage(_can_message);
165  _can_message[0] = MOTOR_COMMAND_POSITION_CLOSED_LOOP_2;
166  _can_message[2] = *(uint8_t *)(&_max_speed);
167  _can_message[3] = *((uint8_t *)(&_max_speed) + 1);
168  _can_message[4] = *(uint8_t *)(&_multiturn_angle);
169  _can_message[5] = *((uint8_t *)(&_multiturn_angle) + 1);
170  _can_message[6] = *((uint8_t *)(&_multiturn_angle) + 2);
171  _can_message[7] = *((uint8_t *)(&_multiturn_angle) + 3);
172 }
173 
174 void make_can_msg::positionControl3(unsigned char* _can_message, uint16_t _singleturn_angle, uint8_t _spin_direction)
175 {
176  emptyCanMessage(_can_message);
177  _can_message[0] = MOTOR_COMMAND_POSITION_CLOSED_LOOP_3;
178  _can_message[1] = _spin_direction;
179  _can_message[4] = *(uint8_t *)(&_singleturn_angle);
180  _can_message[5] = *((uint8_t *)(&_singleturn_angle) + 1);
181 }
182 
183 void make_can_msg::positionControl4(unsigned char* _can_message, uint16_t _single_turn_angle, uint8_t _spin_direction, uint16_t _max_speed)
184 {
185  emptyCanMessage(_can_message);
186  _can_message[0] = MOTOR_COMMAND_POSITION_CLOSED_LOOP_4;
187  _can_message[1] = _spin_direction;
188  _can_message[2] = *(uint8_t *)(&_max_speed);
189  _can_message[3] = *((uint8_t *)(&_max_speed) + 1);
190  _can_message[4] = *(uint8_t *)(&_single_turn_angle);
191  _can_message[5] = *((uint8_t *)(&_single_turn_angle) + 1);
192 }
#define MOTOR_COMMAND_MOTOR_STOP
#define MOTOR_COMMAND_MOTOR_OFF
#define MOTOR_COMMAND_READ_SINGLE_CIRCLE_COMMAND
#define MOTOR_COMMAND_WRITE_CURRENT_POSITION_TO_ROM
#define MOTOR_COMMAND_POSITION_CLOSED_LOOP_4
#define MOTOR_COMMAND_READ_MULTI_TURN_ANGLE
#define MOTOR_COMMAND_WRITE_PID_PARAMETERS_TO_ROM
#define MOTOR_COMMAND_SPEED_CLOSED_LOOP
#define MOTOR_COMMAND_MOTOR_RUNNING
#define MOTOR_COMMAND_READ_MOTOR_STATUS_2
#define MOTOR_COMMAND_POSITION_CLOSED_LOOP_1
#define MOTOR_COMMAND_POSITION_CLOSED_LOOP_2
#define MOTOR_COMMAND_WRITE_ENCODER_POSITION_OFFSET
#define MOTOR_COMMAND_WRITE_ACCELERATION_TO_RAM
#define MOTOR_COMMAND_READ_PID_PARAMETERS
#define MOTOR_COMMAND_READ_MOTOR_STATUS_1_AND_ERROR_FLAG
#define MOTOR_COMMAND_WRITE_PID_PARAMETERS_TO_RAM
#define MOTOR_COMMAND_READ_MOTOR_STATUS_3
#define MOTOR_COMMAND_READ_ACCELERATION
#define MOTOR_COMMAND_TORQUE_CLOSED_LOOP
#define MOTOR_COMMAND_CLEAR_MOTOR_ERROR_FLAG
#define MOTOR_COMMAND_READ_ENCODER_POSITION
#define MOTOR_COMMAND_POSITION_CLOSED_LOOP_3
void readMotorStatus1AndErrorFlag(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to send back a CAN mess...
void motorStop(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to stop its controller ...
void positionControl3(unsigned char *_can_message, uint16_t _singleturn_angle, uint8_t _spin_direction)
The function creates a CAN data message that can be used to set the motor's single turn position with...
void readAcceleration(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to send back a CAN mess...
void readMotorStatus2(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to send back a CAN mess...
void torqueCurrentControl(unsigned char *_can_message, int16_t _torque_current)
The function creates a CAN data message that can be used to set the motor's torque current....
void speedControl(unsigned char *_can_message, int32_t speed)
The function creates a CAN data message that can be used to set the motor's speed....
void writeAccelerationToRAM(unsigned char *_can_message, int32_t _acceleration)
The function creates a CAN data message that can be used to set the acceleration of the motor.
void positionControl1(unsigned char *_can_message, int32_t _multiturn_angle)
The function creates a CAN data message that can be used to set the motor's multi turn position....
void motorRunning(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to resume its control o...
void readCircleTurnAngle(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to send back a CAN mess...
void positionControl4(unsigned char *_can_message, uint16_t _single_turn_angle, uint8_t _spin_direction, uint16_t max_speed)
The function creates a CAN data message that can be used to set the motor's single turn position with...
void motorOff(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to turn off its control...
void clearMotorErrorFlag(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to clear its error stat...
void readMultiTurnAngle(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to send back a CAN mess...
void readPIDParameters(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to send back a CAN mess...
Definition: make_can_msg.cpp:3
void writePIDParametersToROM(unsigned char *_can_message, unsigned char _k_p_position, unsigned char _k_i_position, unsigned char _k_p_speed, unsigned char _k_i_speed, unsigned char _k_p_torque, unsigned char _k_i_torque)
The function creates a CAN data message that can be used to set the PI parameters of the motor....
void readEncoderPosition(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to send back a CAN mess...
void writePIDParametersToRAM(unsigned char *_can_message, unsigned char _k_p_position, unsigned char _k_i_position, unsigned char _k_p_speed, unsigned char _k_i_speed, unsigned char _k_p_torque, unsigned char _k_i_torque)
The function creates a CAN data message that can be used to set the PI parameters of the motor in RAM...
Definition: make_can_msg.cpp:9
void writeCurrentPositionToROM(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to set the current posi...
void writeEncoderPositionOffset(unsigned char *_can_message, uint16_t _encoder_offset)
The function creates a CAN data message that can be used to request the motor to set the encoder posi...
void positionControl2(unsigned char *_can_message, int32_t _multiturn_angle, uint16_t _max_speed)
The function creates a CAN data message that can be used to set the motor's multi turn position with ...
void readMotorStatus3(unsigned char *_can_message)
The function creates a CAN data message that can be used to request the motor to send back a CAN mess...
void emptyCanMessage(unsigned char *_can_message)
The function takes in an array are converts the first 8 elements to zero.
Definition: utilities.cpp:20