Raphael Schmidt
/
GrannyStepper
Projekt
Diff: main.cpp
- Revision:
- 40:47997e887235
- Parent:
- 39:c0c2e33a2181
- Child:
- 41:e86f6f2e2bfc
--- a/main.cpp Wed Apr 13 10:58:34 2022 +0200 +++ b/main.cpp Wed Apr 20 08:22:36 2022 +0200 @@ -6,6 +6,7 @@ //Eingänge DigitalIn user_button(PC_13); +DigitalIn mechanical_button(PC_5); //Ausgänge DigitalOut enable_motors(PB_15); // Motoren freischalten @@ -28,9 +29,11 @@ float kp = 0.1f; // define custom kp, this is the default speed controller gain for gear box 78.125:1 // SpeedController speedController_M2(counts_per_turn, kn, max_voltage, pwm_M2, encoder_M2); // default 78.125:1 gear box with default contoller parameters -SpeedController speedController_M1(counts_per_turn * k_gear, kn / k_gear, max_voltage, pwm_M1, encoder_M1); // parameters adjusted to 100:1 gear +//SpeedController speedController_M1(counts_per_turn * k_gear, kn / k_gear, max_voltage, pwm_M1, encoder_M1); // parameters adjusted to 100:1 gear float max_speed_rps = 0.5f; // define maximum speed that the position controller is changig the speed, has to be smaller or equal to kn * max_voltage +// PositionController positionController_M3(counts_per_turn, kn, max_voltage, pwm_M3, encoder_M3); // default 78.125:1 gear with default contoller parameters +PositionController positionController_M1(counts_per_turn * k_gear, kn / k_gear, kp * k_gear, max_voltage, pwm_M1, encoder_M1); // parameters adjusted to 100:1 gear, we need a different speed controller gain here int main(){ @@ -49,25 +52,34 @@ if (user_button.read()){ counter_stopp = 0; } - if (counter_user_button >= 4){ + if (counter_user_button >= 5){ counter_user_button = 1; } float speed_counter; switch (counter_user_button){ case 1: - enable_motors = 0; + enable_motors = 1; speed_counter = 0.0f; + positionController_M1.setDesiredRotation(0.0f, 0.0f); break; case 2: enable_motors = 1; speed_counter = 0.1f; + positionController_M1.setDesiredRotation(1.5f, 0.2f); break; case 3: + enable_motors = 1; + speed_counter = 0.0f; + positionController_M1.setDesiredRotation(0.0f, 0.0f); + break; + case 4: + enable_motors = 1; speed_counter = 1.0f; + positionController_M1.setDesiredRotation(1.5f, 1.0f); break; } - + //positionController_M1.setDesiredRotation(1.5f, speed_counter); /*if (counter_user_button == 1 || counter_user_button == 3 || counter_user_button == 5){ speedController_M1.setDesiredSpeedRPS(speed_counter);