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.
Diff: main.cpp
- Revision:
- 1:63edfaecc73e
- Parent:
- 0:bb0fd6c1d178
- Child:
- 2:5ec7af981b32
--- a/main.cpp Fri Oct 09 07:49:40 2015 +0000
+++ b/main.cpp Wed Oct 14 10:33:11 2015 +0000
@@ -26,14 +26,27 @@
double Rotation = 2; // rotation in degree
double movement = Rotation * 360 * resolution; // times 360 to make Rotations degree.
+// defining flags
+volatile bool flag_motor = false;
+volatile bool flag_pcprint = false;
+// making flags.
+void Go_flag_motor()
+{
+ flag_motor = true;
+}
+
+void Go_flag_pcprint()
+{
+ flag_pcprint = true;
+}
// Reusable P controller
double P(double error, const double Kp)
{
double error_normalised_degree = error / resolution; // calculate how much degree the motor has to turn.
double error_normalised_rotation = error_normalised_degree / 360; //calculate how much the rotaions the motor has to turn
-
+
double P_output = Kp * error_normalised_rotation;
return P_output;
}
@@ -52,10 +65,11 @@
directionPin.write(cw);
PWM.write(output);
//pc.printf("ref %.0f count%.0f cw\n",movement,position);
-
- } if(error < 0) {
+
+ }
+ if(error < 0) {
directionPin.write(ccw);
- PWM.write(-output); //min output to get output possitif
+ PWM.write(-output); //min output to get output positive
//pc.printf("a");
}
@@ -65,18 +79,30 @@
void counts_showing()
-{
+{
- double kijken = wheel.getPulses();
-pc.printf("ref %.0f count%.0f \n",movement,kijken);
-
- }
+ double kijken = wheel.getPulses();
+ pc.printf("ref %.0f count%.0f \n",movement,kijken);
+
+}
int main()
{
- aansturen.attach( &motor1_Controller, 0.1f ); // 100 Hz
- Printen.attach(&counts_showing,1); // 10 Hz // printstatement here because printing cost to much time. the motor void wouldn't be completed
- while( 1 ) { }
+ aansturen.attach( &Go_flag_motor, 0.001f ); // 100 Hz // timer 0.00001f motor keeps spinning
+ Printen.attach(&Go_flag_pcprint,0.1f); // 10 Hz // printstatement here because printing cost to much time. the motor void wouldn't be completed
+ while( 1 ) {
+
+ if(flag_motor) {
+ flag_motor = false;
+ motor1_Controller();
+ }
+
+ if(flag_pcprint) {
+ flag_pcprint = false;
+ counts_showing();
+ }
+
+ }
}