2014 Eurobot fork

Dependencies:   mbed-rtos mbed QEI

Committer:
madcowswe
Date:
Sun Apr 14 17:22:20 2013 +0000
Revision:
66:f1d75e51398d
Parent:
57:d434ceab6892
Child:
67:be3ea5450cc7
Obstacle avoidance working smoothly, fairly hacked motion-ai communication of override

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rsavitski 30:791739422122 1 #include "ai.h"
rsavitski 55:0c8897da6b3a 2 #include "rtos.h"
rsavitski 55:0c8897da6b3a 3 #include "globals.h"
rsavitski 55:0c8897da6b3a 4 #include "motion.h"
rsavitski 55:0c8897da6b3a 5 #include "Colour.h"
rsavitski 55:0c8897da6b3a 6 #include "supportfuncs.h"
rsavitski 55:0c8897da6b3a 7
rsavitski 30:791739422122 8
rsavitski 30:791739422122 9 namespace AI
rsavitski 30:791739422122 10 {
rsavitski 30:791739422122 11
rsavitski 30:791739422122 12 void ailayer(void const *dummy)
rsavitski 30:791739422122 13 {
rsavitski 54:99d3158c9207 14 Waypoint current_waypoint;
rsavitski 38:c9058a401410 15
rsavitski 54:99d3158c9207 16 current_waypoint.x = 2.2;
rsavitski 54:99d3158c9207 17 current_waypoint.y = 1.85;
rsavitski 54:99d3158c9207 18 current_waypoint.theta = PI;
rsavitski 54:99d3158c9207 19 current_waypoint.pos_threshold = 0.01;
rsavitski 54:99d3158c9207 20 current_waypoint.angle_threshold = 0.02*PI;
rsavitski 39:44d3dea4adcc 21
rsavitski 57:d434ceab6892 22 motion::setNewWaypoint(Thread::gettid(),&current_waypoint);
madcowswe 66:f1d75e51398d 23 motion::collavoiden = 1;
rsavitski 39:44d3dea4adcc 24
madcowswe 50:937e860f4621 25 Colour c_upper(P_COLOR_SENSOR_BLUE_UPPER, P_COLOR_SENSOR_RED_UPPER, P_COLOR_SENSOR_IN_UPPER, UPPER);
madcowswe 50:937e860f4621 26 Colour c_lower(P_COLOR_SENSOR_BLUE_LOWER, P_COLOR_SENSOR_RED_LOWER, P_COLOR_SENSOR_IN_LOWER, LOWER);
rsavitski 55:0c8897da6b3a 27
rsavitski 55:0c8897da6b3a 28 float r = 0.61+0.02;
rsavitski 53:b013df99b747 29
madcowswe 66:f1d75e51398d 30 bool firstavoidstop = 1;
rsavitski 54:99d3158c9207 31 for (float phi=(180-11.25)/180*PI; phi > 11.25/180*PI;)
rsavitski 30:791739422122 32 {
rsavitski 39:44d3dea4adcc 33 motion::waypoint_flag_mutex.lock();
madcowswe 66:f1d75e51398d 34 if (motion::checkMotionStatus() && (c_lower.getColour()==RED || firstavoidstop))
rsavitski 30:791739422122 35 {
rsavitski 54:99d3158c9207 36 phi -= 22.5/180*PI;
rsavitski 54:99d3158c9207 37 current_waypoint.x = 1.5-r*cos(phi);
rsavitski 54:99d3158c9207 38 current_waypoint.y = 2-r*sin(phi);
rsavitski 54:99d3158c9207 39 current_waypoint.theta = constrainAngle(phi+PI/2);
rsavitski 56:ed585a82092b 40
rsavitski 56:ed585a82092b 41 //arm offset
rsavitski 56:ed585a82092b 42 current_waypoint.x += 0.0425*cos(current_waypoint.theta);
rsavitski 56:ed585a82092b 43 current_waypoint.y += 0.0425*sin(current_waypoint.theta);
rsavitski 57:d434ceab6892 44
rsavitski 57:d434ceab6892 45 motion::setNewWaypoint(Thread::gettid(),&current_waypoint);
madcowswe 66:f1d75e51398d 46 if (firstavoidstop){
madcowswe 66:f1d75e51398d 47 motion::collavoiden = 0;
madcowswe 66:f1d75e51398d 48 firstavoidstop = 0;
madcowswe 66:f1d75e51398d 49 }
madcowswe 66:f1d75e51398d 50 else
madcowswe 66:f1d75e51398d 51 motion::collavoiden = 1;
rsavitski 30:791739422122 52 }
rsavitski 54:99d3158c9207 53 motion::waypoint_flag_mutex.unlock();
rsavitski 54:99d3158c9207 54
rsavitski 54:99d3158c9207 55 Thread::wait(50);
rsavitski 30:791739422122 56 }
rsavitski 30:791739422122 57 }
rsavitski 30:791739422122 58
rsavitski 30:791739422122 59 } //namespace