Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Encoder HIDScope MODSERIAL QEI biquadFilter mbed
Diff: main.cpp
- Revision:
- 18:6c065915f474
- Parent:
- 17:aa167ab3cf75
- Child:
- 19:c6dc35b4cc0c
--- a/main.cpp Thu Oct 08 10:32:07 2015 +0000 +++ b/main.cpp Thu Oct 08 10:41:56 2015 +0000 @@ -24,7 +24,6 @@ volatile bool looptimerflag; const double cw=0; // zero is clockwise (front view) const double ccw=1; // one is counterclockwise (front view) -double reference_turn = 0; const double Gain_P_turn=0.0067; // stel setpoint tussen (0 en 360) en position tussen (0 en 360) @@ -46,6 +45,7 @@ // One revolution = 360 degrees // degrees_per_encoder_tick = 360/(gear_ratio*ticks_per_magnet_rotation)=360/131*32=0.085877862594198 + const double sample_time=0.01; // tijd voor een sample (100Hz) // PID motor constants @@ -66,7 +66,7 @@ QEI motor_turn(D12,D13,NC,32); // Encoder for motor Turn PwmOut pwm_motor_turn(D5); // Pwm for motor Turn DigitalOut motordirection_turn(D4); // Direction of the motor Turn - double reference_turn; // Set constant to store reference value of the Turn motor + double reference_turn=0; // Set constant to store reference value of the Turn motor double position_turn; // Set constant to store current position of the Turn motor double error; double pwm_to_motor_turn; @@ -97,11 +97,17 @@ pwm_motor_turn = 0.5f; // motorspeed pc.printf("positie = %d \r\n", motor_turn.getPulses()); } - // Change Reference button - if (buttonL1.read() < 0.5){ //if button pressed - pc.printf("Reference after = %d \r\n", Reference); - change_reference_positive(Reference_turn) - pc.printf("Reference after = %d \r\n", Reference); } + // Change Reference button Positive + if (buttonH1.read() < 0.5){ //if button pressed + pc.printf("Reference after = %d \r\n", reference_turn); + reference_turn=reference_turn+45; + pc.printf("Reference after = %d \r\n", reference_turn); } + + // Change Reference button Negative + if (buttonH1.read() < 0.5){ //if button pressed + pc.printf("Reference after = %d \r\n", reference_turn); + reference_turn=reference_turn-45; + pc.printf("Reference after = %d \r\n", reference_turn); } // Wait until looptimer flag is true then execute PID controller. else @@ -221,9 +227,3 @@ //{ // get_sample = 1; //} - - -void change_reference_positive (double Reference) -{ - Reference=Reference+45; -} \ No newline at end of file