Luccas Eagles
/
CONTROL_MOTOR_MELODY
added melody to old motorcontol
Diff: main.cpp
- Revision:
- 26:7f88907d7c54
- Parent:
- 25:4b893287d750
- Child:
- 27:f2e43189b0f4
diff -r 4b893287d750 -r 7f88907d7c54 main.cpp --- a/main.cpp Sat Apr 11 10:43:48 2020 +0000 +++ b/main.cpp Sat Apr 11 13:44:39 2020 +0000 @@ -297,7 +297,7 @@ void process_melody(std::string input){ - melody_length = 1; + melody_length = 0; for(int i = 0; i < 16; i++){ notes[i] = 0; @@ -400,8 +400,10 @@ float get_period(){ + int curr_note_length = note_durations[melody_index]; float curr_note_period = notes[melody_index]; + if( note_count >= curr_note_length ){ @@ -411,7 +413,10 @@ else{ note_count = note_count + 1; } - + + + pc.printf("Period = %f, melody_index = %d, note_count = %d\r\n", curr_note_period, melody_index, note_count); + return curr_note_period; } @@ -461,7 +466,7 @@ thread_motorCtrl.signal_wait(0x1); current_position = get_current_position(); - //pwm_period = get_period(); + pwm_period = get_period(); float current_velocity = get_current_velocity(current_position); float velocity_error = target_velocity - current_velocity; @@ -475,9 +480,9 @@ update_lead(velocity_out); MotorPWM.period(pwm_period); - MotorPWM.write(motor_out); + MotorPWM.write(0.6f); - // pc.printf("Period = %f, melody_index = %d, note_count = %d\r\n", pwm_period, melody_index, note_count); + } }