Motor calibration
Dependencies: BioroboticsMotorControl mbed BioroboticsEMGFilter MODSERIAL
main.cpp
- Committer:
- MAHCSnijders
- Date:
- 2018-10-31
- Revision:
- 1:9c75e4cca419
- Parent:
- 0:61f4586742be
- Child:
- 2:9d23d93d097f
File content as of revision 1:9c75e4cca419:
#include "mbed.h" Motor motor1(D6, D7, D13, D12); // Defining motor pins (PWM, direction, encoder) Motor motor2(D5, D4, D10, D11); // Defining motor pins (PWM, direction, encoder) DigitalOut calibLED1(LED_BLUE); // LED to check if calibration motor 1 is done DigitalOut calibLED2(LED_RED); // LED to check if calibration motor 2 is done const float pid_period = 0.001; // PID sample period in seconds. const double Kp = 10.0; // PID proportional const double Ki = 0.1; // PID integral const double Kd = 0.5; // PID differential Ticker motor_calib; // Ticker for motor calibration void Motor_Calibration() { if (motor_angle1 = motor1.get_current_angle) { motor1.set_current_angle_as_zero(); calibLED1 = 0; break } if (motor_angle2 = motor2.get_current_angle) { motor2.set_current_angle_as_zero(); calibLED2 = 0; break } float motor_angle1 = motor1.get_current_angle; motor_angle1--; motor1.set_target_angle(motor_angle1); float motor_angle2 = motor2.get_current_angle; motor_angle2--; motor2.set_target_angle(motor_angle2); } int main() { calibLED1 = 1; calibLED2 = 1; motor1.set_pid_k_values(Kp, Ki, Kd); // Attach PID-controller values motor2.set_pid_k_values(Kp, Ki, Kd); motor1.start(pid_period) // Attach PID sample time motor2.start(pid_period); motor_calib.attach(Motor_Calibration,0.5); // Ticker for motor calibration fucntion while (true) {} // Empty while loop to keep function from stopping }