thread working with sonar and demo
Dependencies: C12832 PixelArray RangeFinder WS2812 mbed-rtos mbed
Revision 1:6ce5517b28b8, committed 2015-04-27
- Comitter:
- cathal66
- Date:
- Mon Apr 27 14:26:42 2015 +0000
- Parent:
- 0:fb0c24069b95
- Commit message:
- All working. but without serial comms
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 27 12:13:07 2015 +0000
+++ b/main.cpp Mon Apr 27 14:26:42 2015 +0000
@@ -75,7 +75,7 @@
Distance_Mutex.lock();
Distance = ping_sensor.read_m();
Distance_Mutex.unlock();
- Thread::wait(250);
+ Thread::wait(100);
}
}
@@ -252,9 +252,37 @@
}
}
+void Smooth_Fade_Thread(void const *args)
+{
+ int speed = 10;
+ int h = 1;
+ while(1)
+ {
+ Thread::signal_wait(0x2); //wait for flag to be set
+ for(int j = 0; j<=h;j++)
+ {
+ for(int i = 0;i<=255;i=i+speed)
+ {
+ LED_All_Colour(i, 0 ,255-i , 255);
+ //wait(0.01);
+ }
+ for(int i = 0;i<=255;i=i+speed)
+ {
+ LED_All_Colour(255-i, i ,0 , 255);
+ //wait(0.01);
+ }
+ for(int i = 0;i<=255;i=i+speed)
+ {
+ LED_All_Colour(0, 255-i ,i , 255);
+ //wait(0.01);
+ }
+ }
+ }
+}
void Smooth_Fade(int h , int speed)
{
+
for(int j = 0; j<=h;j++)
{
for(int i = 0;i<=255;i=i+speed)
@@ -272,10 +300,14 @@
LED_All_Colour(0, 255-i ,i , 255);
//wait(0.01);
}
- }
+ }
+
}
void Demo_thread(void const *argument) {
+
+ Thread thread_smooth_fade(Smooth_Fade_Thread);
+
while (true)
{
Thread::signal_wait(0x1); //wait for flag to be set
@@ -283,9 +315,9 @@
/////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// X //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
- Servo_Y = 0.05;
- Servo_X = 0.06;
- Servo_z_smooth = 0.01;
+ Servo_Y = 0.06;
+ Servo_X = 0.075;
+ Servo_z_smooth = 0.09;
LED_Colour_Pos(0,255,0,0,128);
LED_Colour_Pos(1,0,255,0,128);
LED_Colour_Pos(2,0,0,255,128);
@@ -298,9 +330,9 @@
LED_Colour_Pos(9,128,128,255,128);
LED_Colour_Pos_Set();
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4 \n\r",Servo_X, Servo_Y, Servo_z_smooth);
- Thread::wait(1000);
- Servo_Y = 0.05;
- Servo_X = 0.06;
+ Thread::wait(500);
+ Servo_Y = 0.06;
+ Servo_X = 0.075;
Servo_z_smooth = 0.05;
LED_Colour_Pos(0,128,255,0,128);
LED_Colour_Pos(1,128,50,0,255);
@@ -315,7 +347,7 @@
LED_Colour_Pos_Set();
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
- Servo_Y = 0.05;
+ Servo_Y = 0.06;
Servo_X = 0.08;
Servo_z_smooth = 0.08;
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
@@ -326,25 +358,25 @@
LED_All_Colour(255, 0 , 0 , 255);
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
- Servo_Y = 0.05;
+ Servo_Y = 0.06;
Servo_X = 0.05;
Servo_z_smooth = 0.05;
LED_All_Colour(255, 255 , 0 , 255);
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
- Servo_Y = 0.05;
+ Servo_Y = 0.06;
Servo_X = 0.09;
Servo_z_smooth = 0.05;
LED_All_Colour(0, 0 , 255 , 255);
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
- Servo_Y = 0.05;
+ Servo_Y = 0.06;
Servo_X = 0.05;
Servo_z_smooth = 0.05;
LED_All_Colour(0, 255 , 0 , 255);
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
- Servo_Y = 0.05;
+ Servo_Y = 0.06;
Servo_X = 0.09;
Servo_z_smooth = 0.05;
LED_Colour_Pos(0,255,0,0,128);
@@ -360,12 +392,13 @@
LED_Colour_Pos_Set();
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
- Servo_Y = 0.05;
+ Servo_Y = 0.06;
Servo_X = 0.05;
Servo_z_smooth = 0.05;
+ thread_smooth_fade.signal_set(0x2);
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
- Servo_Y = 0.05;
+ Servo_Y = 0.055;
Servo_X = 0.08;
Servo_z_smooth = 0.05;
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
@@ -380,7 +413,7 @@
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
Servo_Y = 0.08;
- Servo_X = 0.075;
+ Servo_X = 0.04;
Servo_z_smooth = 0.05;
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
@@ -390,7 +423,7 @@
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
Servo_Y = 0.065;
- Servo_X = 0.075;
+ Servo_X = 0.09;
Servo_z_smooth = 0.05;
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(1000);
@@ -410,7 +443,7 @@
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
Servo_Y = 0.065;
- Servo_X = 0.075;
+ Servo_X = 0.04;
Servo_z_smooth = 0.05;
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
@@ -429,17 +462,17 @@
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
Servo_Y = 0.06;
- Servo_X = 0.075;
- Servo_z_smooth = 0.1;
+ Servo_X = 0.9;
+ Servo_z_smooth = 0.03;
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
- Thread::wait(500);
+ Thread::wait(1000);
Servo_Y = 0.06;
Servo_X = 0.075;
Servo_z_smooth = 0.07;
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(500);
Servo_Y = 0.06;
- Servo_X = 0.075;
+ Servo_X = 0.04;
Servo_z_smooth = 0.11;
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(750);
@@ -454,7 +487,7 @@
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(750);
Servo_Y = 0.06;
- Servo_X = 0.075;
+ Servo_X = 0.08;
Servo_z_smooth = 0.07;
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(750);
@@ -464,15 +497,18 @@
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
Thread::wait(750);
Servo_Y = 0.06;
- Servo_X = 0.075;
+ Servo_X = 0.04;
Servo_z_smooth = 0.07;
printf("Servo X: %f 1.4 Servo Y: %f 1.4 Servo Z: %f 1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
- Thread::wait(1500);
- Servo_Y = 0.06;
- Servo_X = 0.75;
+ Thread::wait(1000);
+ Servo_Y = 0.09;
+ Servo_X = 0.075;
Servo_z_smooth = 0.03;
+ LED_All_Colour(0, 0 , 0 , 255);
printf("Servo X: %f1.4 Servo Y: %f1.4 Servo Z: %f1.4\n\r",Servo_X, Servo_Y, Servo_z_smooth);
- Thread::wait(1500);
+ Thread::wait(30000);
+ Thread::signal_wait(0x1); //wait for flag to be set
+ Thread::wait(1000);
}
}
@@ -493,11 +529,8 @@
}
}
-void Demo()
-{
-
-}
-
+
+
int main (void)
{
@@ -508,6 +541,7 @@
Thread thread_Servo_Z(Servo_Z_Thread );
Thread thread_Demo(Demo_thread );
Thread thread_Sonar_Read(read_sonar_thread );
+
//RtosTimer timer(timeout_event, osTimerPeriodic, (void *)0);
int state = PAN_TILT;