8 #include "FlexCAN_T4.h"
22 MotorControl(uint8_t _id, uint8_t _can_port_id,
int _number_of_inner_motor_rotations,
double _position_offset);
double initial_number_of_inner_motor_rotations
Number of rotations of the inner motor during startup This is needed to create position commands.
void setSpeedReference(double _speed)
Set the desired motor speed.
double getTorque()
Return the torque of the MotorClass object.
int16_t torque_current_measured
The measured torque current of the motor.
bool turnOffMotor()
The motor stops exerting a control output. The motor's operating state and previously received contro...
bool stopMotor()
The motor stops exerting a control output. The motor will remain idle until a new control command or ...
double max_torque
The torque in Newton meter has to lie in the interval [-max_torque, max_torque].
double getMultiTurnAngleRaw()
Return the raw int64_t 0.01 degree multi turn angle.
uint16_t address
Motor address = ID + 0x140. Declared for convenience.
CAN_message_t can_message
CAN message for this motor. Only buf field is set for every message sent.
void printPIDParameters()
The function prints the PI parameters of the motor.
bool readMotorStatus()
A request is sent to the motor asking it to send back its state. The private state varibles position,...
int64_t multi_turn_angle_001lsb
This is the 64 bit representation of the raw int64_t multi turn angle in 0.01 degrees.
uint16_t previous_encoder_value
Keep track of previous encoder position. This way you can detect turns. See innerMotorTurnCompleted()...
double temperature
Latest measured temperature of the motor in degree Celsius.
double getPosition()
Return the position of the MotorClass object.
double target_position_offset
If the motor is initialized in certain positions the setPosition function will have zero offset of 60...
double number_of_inner_motor_rotations
Number of rotations of the built-in motor, not the output-shaft.
void setTorqueCurrent(int _torque_current)
Set the desired motor torque current. Scales linearly with torque.
uint8_t can_port_id
Used to decide which CAN port to use. Possible values {1, 2}.
void readMotorControlCommandReply(unsigned char *_can_message)
The state variables position, velocity, and torque are updated based on the latest information from t...
uint8_t id
Motor ID set through the Serial configurator [1 - 32].
int readMessage(CAN_message_t &_can_message)
This function ensures that the message on the correct CAN port is read.
double getVelocity()
Return the velocity of the MotorClass object.
MotorControl()
Default constructor needed for initializing array.
int max_torque_current
All torque values are scaled to the interval [-max_torque_current, max_torque_current].
int16_t torque_current_reference
The torque current reference set for the motor.
bool readPIDParameters()
Read the motor PI parameters and update the private PI values.
double torque
Latest measured shaft torque in Nm.
double position_center_offset
This is used to center the output shaft zero position.
double innerMotorTurnCompleted(uint16_t _previous_encoder_value, uint16_t _new_encoder_value)
This function checks if the inner motor completed a turn. Depending on the difference between the new...
double getMultiTurnAngle()
Return the latest received multi turn angle from the motor.
double speed
Latest measured speed of the shaft in radians/second.
bool writePIDParametersToRAM(double _kp_pos, double _ki_pos, double _kp_speed, double _ki_speed, double _kp_torque, double _ki_torque)
Set the motor PI parameters and store them temporary in RAM.
double raw_position_reference
void requestMotorStatus()
A request is sent to the motor asking it to send back its state, position, velocity,...
void getPIDParameters(double &_kp_pos, double &_ki_pos, double &_kp_speed, double &_ki_speed, double &_kp_torque, double &_ki_torque)
The input parameters are updated to match the PI parameters of the motor.
int32_t multi_turn_angle_32_bit_001lsb
This variable contains the 32 bit representation of the raw 0.01 degree multi turn angle.
uint8_t get_id()
Return the ID of the MotorClass object.
double position
Latest measured position of the shaft in radians.
double position_offset
position offset = true position - position
uint16_t encoder_turn_threshold
If the change in encoder value is larger than this it is safe to assume that the inner motor complete...
double getEncoderValue()
Return the latest received encoder value from the motor.
int64_t multi_turn_angle_64_bit
This is the true 64 bit representation of the multi turn angle in degrees.
bool readCompleteEncoderPosition()
All the encoder data from the motor is read and printed. This includes the encoder value,...
CAN_message_t received_can_message
CAN message object used to receive incomming CAN messages.
void printTorqueCurrents()
void setPositionReference(double _angle)
Set the desired multi turn motor angle.
void sendMessage(CAN_message_t _can_message)
This function ensures that the message is sent to the correct CAN port.
void printState()
The ID, encoder value, multi turn angle, position, speed and torque of the motor are printed.
void setTorqueReference(double _torque)
Set the desired motor torque.
bool readMultiTurnAngle()
The multi turn angle of the motor updated.
int32_t multi_turn_angle_32_bit
This variable contains the multi turn angle read by the motor in degrees.
double kp_pos
Motor PID Parameters.
uint16_t max_encoder_value
The 16 bit encoder measures the position of the inner DC motor, not the shaft.