Colour sensors calibrated
Dependencies: mbed-rtos mbed Servo QEI
Fork of ICRSEurobot13 by
Revision 29:4e20b44251c6, committed 2013-04-10
- Comitter:
- madcowswe
- Date:
- Wed Apr 10 04:20:40 2013 +0000
- Parent:
- 28:664e81033846
- Child:
- 30:00e1493b44f0
- Commit message:
- Idle CPU measure implemented, not tested
Changed in this revision
--- a/Processes/MotorControl/MotorControl.cpp Wed Apr 10 03:48:42 2013 +0000 +++ b/Processes/MotorControl/MotorControl.cpp Wed Apr 10 04:20:40 2013 +0000 @@ -3,6 +3,7 @@ #include "Encoder.h" #include "globals.h" #include <algorithm> +#include "system.h" namespace MotorControl {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/System/system.cpp Wed Apr 10 04:20:40 2013 +0000 @@ -0,0 +1,34 @@ + +#include "rtos.h" +#include "mbed.h" +#include "Printing.h" + +Timer SystemTime; + +Ticker CPUIdleMeasureTicker; +volatile unsigned int nopctr = 0; +const float s_per_nopcycle = 1.0f/24000000.0f; + +float CpuUsage = 0; + +void nopwait(int ms){ +while(ms--) + for (volatile int i = 0; i < 24000; i++); +} + +void PostAndResetCPUIdle(){ + CpuUsage = 1.0f - (s_per_nopcycle * nopctr); + Printing::updateval(10,CpuUsage); + nopctr = 0; +} + +void measureCPUidle (void const*){ + + osThreadSetPriority (osThreadGetId(), osPriorityIdle); + Printing::registerID(10, 1); + + CPUIdleMeasureTicker.attach(PostAndResetCPUIdle, 1); + + while(1) + nopctr++; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/System/system.h Wed Apr 10 04:20:40 2013 +0000 @@ -0,0 +1,6 @@ + +extern Timer SystemTime; +extern float CpuUsage; //1.0f = completely busy, 0.0f = completely idle + +//run this on an "idle" priority thread to measure cpu usage +void measureCPUidle (void const* = NULL);
--- a/globals.cpp Wed Apr 10 03:48:42 2013 +0000 +++ b/globals.cpp Wed Apr 10 04:20:40 2013 +0000 @@ -3,5 +3,4 @@ //Store global objects here pos beaconpos[] = {{0,1}, {3,0}, {3,2}}; -Timer SystemTime; Waypoint* AI::current_waypoint; \ No newline at end of file
--- a/globals.h Wed Apr 10 03:48:42 2013 +0000 +++ b/globals.h Wed Apr 10 04:20:40 2013 +0000 @@ -18,8 +18,6 @@ const float xyvarpertime = 0.0005; //(very poorly) accounts for hitting things const float angvarpertime = 0.001; -extern Timer SystemTime; - const float MOTORCONTROLLER_FILTER_K = 0.5;// TODO: tune this const float MOTOR_MAX_POWER = 0.4f;
--- a/main.cpp Wed Apr 10 03:48:42 2013 +0000 +++ b/main.cpp Wed Apr 10 04:20:40 2013 +0000 @@ -12,6 +12,7 @@ #include <algorithm> #include "motion.h" #include "MotorControl.h" +#include "system.h" void motortest(); void encodertest(); @@ -92,6 +93,7 @@ Thread::wait(3500); Thread printingThread(Printing::printingloop, NULL, osPriorityLow, 2048); + //measureCPUidle(); //repurpose thread for idle measurement Thread::wait(osWaitForever); }