Projekt

Dependencies:   PM2_Libary

Committer:
schmir06
Date:
Wed Mar 30 10:34:39 2022 +0200
Revision:
33:cce9a88a307a
Parent:
32:2dc6fbd004fd
Child:
34:f035a1869c34
Motoren ansteuern

Who changed what in which revision?

UserRevisionLine numberNew contents of line
schmir06 32:2dc6fbd004fd 1 //GrannyStepper
pmic 1:93d997d6b232 2 #include "mbed.h"
pmic 17:c19b471f05cb 3 #include "PM2_Libary.h"
pmic 6:e1fa1a2d7483 4
schmir06 33:cce9a88a307a 5 //Eingänge
schmir06 33:cce9a88a307a 6 InterruptIn user_button(PC_13); //Blauer Taster für Startsignal
schmir06 33:cce9a88a307a 7 //Ausgänge
schmir06 33:cce9a88a307a 8 DigitalOut enable_motors(PB_15); // Motoren freischalten
pmic 17:c19b471f05cb 9
schmir06 33:cce9a88a307a 10 //DC-Motoren
schmir06 33:cce9a88a307a 11 float pwm_period_s = 0.00005f; //PWM-Periode fürd DC-Motoren definiert
schmir06 33:cce9a88a307a 12 FastPWM pwm_M1(PB_13);
schmir06 33:cce9a88a307a 13 //Endcoder
schmir06 33:cce9a88a307a 14 EncoderCounter encoder_M1(PA_6, PC_7);
pmic 17:c19b471f05cb 15
pmic 30:1e8295770bc1 16 // create SpeedController and PositionController objects, default parametrization is for 78.125:1 gear box
pmic 24:86f1a63e35a0 17 float max_voltage = 12.0f; // define maximum voltage of battery packs, adjust this to 6.0f V if you only use one batterypack
pmic 24:86f1a63e35a0 18 float counts_per_turn = 20.0f * 78.125f; // define counts per turn at gearbox end: counts/turn * gearratio
pmic 25:ea1d6e27c895 19 float kn = 180.0f / 12.0f; // define motor constant in rpm per V
pmic 30:1e8295770bc1 20 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
pmic 30:1e8295770bc1 21 float kp = 0.1f; // define custom kp, this is the default speed controller gain for gear box 78.125:1
pmic 6:e1fa1a2d7483 22
pmic 30:1e8295770bc1 23 // SpeedController speedController_M2(counts_per_turn, kn, max_voltage, pwm_M2, encoder_M2); // default 78.125:1 gear box with default contoller parameters
schmir06 33:cce9a88a307a 24 SpeedController speedController_M2(counts_per_turn * k_gear, kn / k_gear, max_voltage, pwm_M1, encoder_M1); // parameters adjusted to 100:1 gear
pmic 24:86f1a63e35a0 25 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
pmic 6:e1fa1a2d7483 26
pmic 6:e1fa1a2d7483 27
pmic 6:e1fa1a2d7483 28
pmic 24:86f1a63e35a0 29