|
Thunderbots Project
|
#include <motor.h>
Classes | |
| struct | MotorFaultIndicator |
Public Member Functions | |
| MotorService (const RobotConstants_t &robot_constants, int control_loop_frequency_hz) | |
| TbotsProto::MotorStatus | poll (const TbotsProto::MotorControl &motor_control, double time_elapsed_since_last_poll_s) |
| uint8_t | tmc4671ReadWriteByte (uint8_t motor, uint8_t data, uint8_t last_transfer) |
| uint8_t | tmc6100ReadWriteByte (uint8_t motor, uint8_t data, uint8_t last_transfer) |
| void | startEncoderCalibration (uint8_t motor) |
| void | endEncoderCalibration (uint8_t motor) |
| void | runOpenLoopCalibrationRoutine (uint8_t motor, size_t num_samples) |
| void | resetMotorBoard () |
| void | setup () |
| struct MotorFaultIndicator | checkDriverFault (uint8_t motor) |
| void | setUpDriveMotor (uint8_t motor) |
| void | writeIntToTMC4671 (uint8_t motor, uint8_t address, int32_t value) |
| int | readIntFromTMC4671 (uint8_t motor, uint8_t address) |
A service that interacts with the motor.
It is responsible for:
| MotorService | ( | const RobotConstants_t & | robot_constants, |
| int | control_loop_frequency_hz | ||
| ) |
Service that interacts with the motor board. Opens all the required ports and maintains them until destroyed.
| RobotConstants_t | The robot constants |
| control_loop_frequency_hz | The frequency the main loop will call poll at |
| MotorService::MotorFaultIndicator checkDriverFault | ( | uint8_t | motor | ) |
Log the driver fault in a human readable log msg
| motor | The motor to log the status for |
| TbotsProto::MotorStatus poll | ( | const TbotsProto::MotorControl & | motor_control, |
| double | time_elapsed_since_last_poll_s | ||
| ) |
When the motor service is polled with a DirectControlPrimitive msg, call the appropriate trinamic api function to spin the appropriate motor.
| motor | The motor msg to unpack and execute on the motors |
| time_elapsed_since_last_poll_s | The time since last poll was called in seconds |
| int readIntFromTMC4671 | ( | uint8_t | motor, |
| uint8_t | address | ||
| ) |
Used for testing purposes:
Wrapper function that reads int from the TMC4671
| motor | drive motor number |
| address | motor address |
| void resetMotorBoard | ( | ) |
Reset the motor board by toggling the reset GPIO appropriately. Effectively stops the motors from moving.
| void runOpenLoopCalibrationRoutine | ( | uint8_t | motor, |
| size_t | num_samples | ||
| ) |
Spin the motor in openloop mode (safe to run before encoder initialization)
Captures TMC4671_OPENLOOP_PHI and TMC4671_ABN_DECODER_PHI_E and stores it in encoder_calibration.csv
Captures adc_iv, adc_ux, adc_wy and pwm_iv, pwm_ux, pwm_wy.
WARNING: Make sure adc_iv is in phase with pwm_iv, adc_ux is in phase with pwm_ux, and adc_wy is in phase with pwm_wy.
If you dont do this, you can risk burning the motor.
| motor | The motor to spin in openloop mode |
| num_samples | The number of samples to take on each |
| void setup | ( | ) |
Clears previous faults, configures the motor and checks encoder connections.
| void setUpDriveMotor | ( | uint8_t | motor | ) |
Sets up motor as drive motor controllers
| motor | drive motor number |
| uint8_t tmc4671ReadWriteByte | ( | uint8_t | motor, |
| uint8_t | data, | ||
| uint8_t | last_transfer | ||
| ) |
Trinamic API binding, sets spi_demux_select_0|1 pins appropriately and calls readWriteByte. See C++ implementation file for more info
| motor | Which motor to talk to (in our case, the chip select) |
| data | The data to send |
| last_transfer | The last transfer of uint8_t data for this transaction. |
| void writeIntToTMC4671 | ( | uint8_t | motor, |
| uint8_t | address, | ||
| int32_t | value | ||
| ) |
Used for testing purposes:
Wrapper function that writes int to the TMC4671
| motor | drive motor number |
| address | motor address |
| value | write value |