Raphael Schmidt
/
GrannyStepper
Projekt
main.cpp
- Committer:
- schmir06
- Date:
- 2022-04-06
- Revision:
- 35:57b39290aaea
- Parent:
- 34:f035a1869c34
- Child:
- 36:f678d693969f
File content as of revision 35:57b39290aaea:
//GrannyStepper #include "mbed.h" #include "PM2_Libary.h" #include <iostream> using namespace std; //Eingänge DigitalIn user_button(PC_13); //Ausgänge DigitalOut enable_motors(PB_15); // Motoren freischalten // while loop gets executed every main_task_period_ms milliseconds int main_task_period_ms = 50; // define main task period time in ms e.g. 50 ms -> main task runns 20 times per second Timer main_task_timer; // create Timer object which we use to run the main task every main task period time in ms //DC-Motoren float pwm_period_s = 0.00005f; //PWM-Periode fürd DC-Motoren definiert FastPWM pwm_M1(PB_13); //Endcoder EncoderCounter encoder_M1(PA_6, PC_7); // create SpeedController and PositionController objects, default parametrization is for 78.125:1 gear box float max_voltage = 12.0f; // define maximum voltage of battery packs, adjust this to 6.0f V if you only use one batterypack float counts_per_turn = 20.0f * 78.125f; // define counts per turn at gearbox end: counts/turn * gearratio float kn = 180.0f / 12.0f; // define motor constant in rpm per V float k_gear = 100.0f / 78.125f; // define additional ratio in case you are using a dc motor with a different gear box, e.g. 100:1 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_M2(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 int main(){ int counter_user_button = 0; bool counter_stopp = 0; enable_motors = 0; while(1){ if (user_button.read() & !counter_stopp) { counter_user_button++; counter_stopp = 1; } if (!user_button.read()){ counter_stopp = 0; } if (counter_user_button >= 3){ counter_user_button = 1; } switch (counter_user_button){ case 1: cout <<"case1"; enable_motors = 1; break; case 2: cout <<"case2"; enable_motors = 0; break; } } }