Projekt

Dependencies:   PM2_Libary

main.cpp

Committer:
schmir06
Date:
2022-03-30
Revision:
33:cce9a88a307a
Parent:
32:2dc6fbd004fd
Child:
34:f035a1869c34

File content as of revision 33:cce9a88a307a:

//GrannyStepper
#include "mbed.h"
#include "PM2_Libary.h"

//Eingänge
InterruptIn user_button(PC_13); //Blauer Taster für Startsignal
//Ausgänge
DigitalOut enable_motors(PB_15); // Motoren freischalten

//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