Eurobot2012_Primary
Dependencies: mbed Eurobot_2012_Primary
Eurobot_shared/ai/ai.cpp@26:0995f61cb7b8, 2012-10-17 (annotated)
- Committer:
- narshu
- Date:
- Wed Oct 17 22:22:47 2012 +0000
- Revision:
- 26:0995f61cb7b8
Eurobot 2012 Primary;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
narshu | 26:0995f61cb7b8 | 1 | #include "ai.h" |
narshu | 26:0995f61cb7b8 | 2 | #include "rtos.h" |
narshu | 26:0995f61cb7b8 | 3 | #include "globals.h" |
narshu | 26:0995f61cb7b8 | 4 | |
narshu | 26:0995f61cb7b8 | 5 | |
narshu | 26:0995f61cb7b8 | 6 | |
narshu | 26:0995f61cb7b8 | 7 | AI::AI() : |
narshu | 26:0995f61cb7b8 | 8 | thr_AI(aithreadwrapper,this,osPriorityNormal,1024) { |
narshu | 26:0995f61cb7b8 | 9 | flag_terminate = false; |
narshu | 26:0995f61cb7b8 | 10 | flag_motorStop = true; |
narshu | 26:0995f61cb7b8 | 11 | flag_manOverride = false; |
narshu | 26:0995f61cb7b8 | 12 | //printf("aistart\r\n"); |
narshu | 26:0995f61cb7b8 | 13 | } |
narshu | 26:0995f61cb7b8 | 14 | |
narshu | 26:0995f61cb7b8 | 15 | |
narshu | 26:0995f61cb7b8 | 16 | void AI::settarget(float targetX, float targetY, float targetTheta, bool targetfacing, bool colour, int maxSpeed) { |
narshu | 26:0995f61cb7b8 | 17 | targetlock.lock(); |
narshu | 26:0995f61cb7b8 | 18 | MOVE_SPEED = maxSpeed; |
narshu | 26:0995f61cb7b8 | 19 | target.x = targetX; |
narshu | 26:0995f61cb7b8 | 20 | target.y = targetY; |
narshu | 26:0995f61cb7b8 | 21 | target.theta = targetTheta; |
narshu | 26:0995f61cb7b8 | 22 | target.facing = targetfacing; |
narshu | 26:0995f61cb7b8 | 23 | target.reached = false; |
narshu | 26:0995f61cb7b8 | 24 | if (!colour) { |
narshu | 26:0995f61cb7b8 | 25 | target.x = 3000 - target.x; |
narshu | 26:0995f61cb7b8 | 26 | target.theta = PI - target.theta; |
narshu | 26:0995f61cb7b8 | 27 | |
narshu | 26:0995f61cb7b8 | 28 | target.theta -= (floor(target.theta/(2*PI)))*2*PI; |
narshu | 26:0995f61cb7b8 | 29 | if (target.theta < -PI) { |
narshu | 26:0995f61cb7b8 | 30 | target.theta += 2*PI; |
narshu | 26:0995f61cb7b8 | 31 | } |
narshu | 26:0995f61cb7b8 | 32 | if (target.theta > PI) { |
narshu | 26:0995f61cb7b8 | 33 | target.theta -= 2*PI; |
narshu | 26:0995f61cb7b8 | 34 | } |
narshu | 26:0995f61cb7b8 | 35 | |
narshu | 26:0995f61cb7b8 | 36 | |
narshu | 26:0995f61cb7b8 | 37 | } |
narshu | 26:0995f61cb7b8 | 38 | targetlock.unlock(); |
narshu | 26:0995f61cb7b8 | 39 | } |
narshu | 26:0995f61cb7b8 | 40 | |
narshu | 26:0995f61cb7b8 | 41 | void AI::settarget(Target targetin) { |
narshu | 26:0995f61cb7b8 | 42 | targetlock.lock(); |
narshu | 26:0995f61cb7b8 | 43 | target = targetin; |
narshu | 26:0995f61cb7b8 | 44 | targetlock.unlock(); |
narshu | 26:0995f61cb7b8 | 45 | } |
narshu | 26:0995f61cb7b8 | 46 | |
narshu | 26:0995f61cb7b8 | 47 | AI::Target AI::gettarget() { |
narshu | 26:0995f61cb7b8 | 48 | targetlock.lock(); |
narshu | 26:0995f61cb7b8 | 49 | Target temptarget = target; |
narshu | 26:0995f61cb7b8 | 50 | targetlock.unlock(); |
narshu | 26:0995f61cb7b8 | 51 | return temptarget; |
narshu | 26:0995f61cb7b8 | 52 | } |