Motor calibration
Dependencies: BioroboticsMotorControl mbed BioroboticsEMGFilter MODSERIAL
main.cpp@0:61f4586742be, 2018-10-31 (annotated)
- Committer:
- MAHCSnijders
- Date:
- Wed Oct 31 09:12:19 2018 +0000
- Revision:
- 0:61f4586742be
- Child:
- 1:9c75e4cca419
Motor Calibration without break at final angles (home state)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MAHCSnijders | 0:61f4586742be | 1 | #include "mbed.h" |
MAHCSnijders | 0:61f4586742be | 2 | |
MAHCSnijders | 0:61f4586742be | 3 | Motor motor1(D6, D7, D13, D12); // Defining motor pins (PWM, direction, encoder) |
MAHCSnijders | 0:61f4586742be | 4 | Motor motor2(D5, D4, D10, D11); // Defining motor pins (PWM, direction, encoder) |
MAHCSnijders | 0:61f4586742be | 5 | |
MAHCSnijders | 0:61f4586742be | 6 | const double Kp = 10.0; |
MAHCSnijders | 0:61f4586742be | 7 | const double Ki = 0.1; |
MAHCSnijders | 0:61f4586742be | 8 | const double Kd = 0.5; |
MAHCSnijders | 0:61f4586742be | 9 | |
MAHCSnijders | 0:61f4586742be | 10 | Ticker motor_cali; |
MAHCSnijders | 0:61f4586742be | 11 | |
MAHCSnijders | 0:61f4586742be | 12 | void Motor_Calibration() |
MAHCSnijders | 0:61f4586742be | 13 | { |
MAHCSnijders | 0:61f4586742be | 14 | float motor_angle1 = motor1.get_current_angle; |
MAHCSnijders | 0:61f4586742be | 15 | motor_angle1--; |
MAHCSnijders | 0:61f4586742be | 16 | motor1.set_target_angle(motor_angle1); |
MAHCSnijders | 0:61f4586742be | 17 | |
MAHCSnijders | 0:61f4586742be | 18 | float motor_angle2 = motor2.get_current_angle; |
MAHCSnijders | 0:61f4586742be | 19 | motor_angle2--; |
MAHCSnijders | 0:61f4586742be | 20 | motor2.set_target_angle(motor_angle2); |
MAHCSnijders | 0:61f4586742be | 21 | } |
MAHCSnijders | 0:61f4586742be | 22 | |
MAHCSnijders | 0:61f4586742be | 23 | int main() |
MAHCSnijders | 0:61f4586742be | 24 | { |
MAHCSnijders | 0:61f4586742be | 25 | motor1.set_pid_k_values(Kp, Ki, Kd); // Attach PID-controller |
MAHCSnijders | 0:61f4586742be | 26 | motor2.set_pid_k_values(Kp, Ki, Kd); |
MAHCSnijders | 0:61f4586742be | 27 | motor1.start(pid_period) // Attach PID time |
MAHCSnijders | 0:61f4586742be | 28 | motor2.start(pid_period); |
MAHCSnijders | 0:61f4586742be | 29 | motor.attach(Motor_Calibration,0.5); // Ticker for motor calibration fucntion |
MAHCSnijders | 0:61f4586742be | 30 | while (true) {} // Empty while loop to keep function from stopping |
MAHCSnijders | 0:61f4586742be | 31 | } |