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: FastPWM mbed QEI biquadFilter HIDScope MODSERIAL
Diff: main.cpp
- Revision:
- 33:ec07e11676ec
- Parent:
- 32:a5b411833d1e
- Child:
- 35:ba556f2d0fcc
--- a/main.cpp Tue Oct 30 18:28:26 2018 +0000 +++ b/main.cpp Wed Oct 31 09:26:55 2018 +0000 @@ -102,9 +102,9 @@ float PIDcontroller(float refvalue,float CurAngle) // PID controller for the motors, based on the reference value and the current angle of the motor { //float Kp = Kpcontr(); - float Kp = 10.42f; + float Kp = 10.37f; float Ki = 1.02f; - float Kd = 0.0493f; + float Kd = 0.0514f; //float Kd = Kdcontr(); float error = ErrorCalc(refvalue,CurAngle); static float error_integral = 0.0; @@ -130,20 +130,28 @@ return angle; } -void turn1() // main function for movement of motor 1, all above functions with an extra tab are called + + +float* turn1() // main function for movement of motor 1, all above functions with an extra tab are called { - //float refvalue1 = pi/4.0; - float refvalue1 = DesiredAngle(); - int counts1 = Counts1input(); - float currentangle1 = CurrentAngle(counts1); - float PIDcontrol1 = PIDcontroller(refvalue1,currentangle1); - float error1 = ErrorCalc(refvalue1,currentangle1); + //float refvalue1 = pi/4.0f; + float refvalue1 = DesiredAngle(); // different minus sign per motor + int counts1 = Counts1input(); // different encoder pins per motor + float currentangle1 = CurrentAngle(counts1); // different minus sign per motor + float PIDcontrol1 = PIDcontroller(refvalue1,currentangle1); // same for every motor + float error1 = ErrorCalc(refvalue1,currentangle1); // same for every motor - pin6 = fabs(PIDcontrol1); - pin7 = PIDcontrol1 > 0.0f; + pin6 = fabs(PIDcontrol1); // different pins for every motor + pin7 = PIDcontrol1 > 0.0f; // different pins for every motor //pin6 = 0.4+0.6*fabs(PIDcontr); //geschaald //pin6 = fabs(PIDcontr)/pi; - pc.printf(" error: %f ref: %f angle: %f \r\n",error1,refvalue1,currentangle1); + //pc.printf(" error: %f ref: %f angle: %f \r\n",error1,refvalue1,currentangle1); + float* outcome; + float turninfo[3] = {error1, refvalue1, currentangle1}; + //float ( &fillarr( float (&outcome)[3] ) )[3] { // no decay; argument must be size 3 + outcome = turninfo; + + return outcome; } float ActualPosition(int counts, int offsetcounts) // After calibration, this function is used to return the counts (and thus the angle of the system) to 0 @@ -158,14 +166,21 @@ pc.baud(115200); pin3.period_us(15); // If you give a period on one pin, c++ gives all pins this period - //motor.attach(turn1,dt); - + //float motoroutcome1 = motor.attach(turn1,dt); + emergencybutton.rise(Emergency); //If the button is pressed, stop program //pin6 = 0.01; while (true) { - turn1(); - wait(dt); + float* motoroutcome1 = turn1(); + float motor11 = motoroutcome1[0]; + float motor12 = motoroutcome1[1]; + float motor13 = motoroutcome1[2]; + + pc.printf(" error1: %f ref1: %f angle1: %f \r\n",motor11,motor12,motor13); + wait(dt); + //wait(dt*10); + //wait(printingfreq); --> still needs to be defined } }