#include "main.h"\r
\r
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))\r
+#define PI =3.14159\r
/*\r
* Runs the user operator control code. This function will be started in its own task with the\r
* default priority and stack size whenever the robot is enabled via the Field Management System\r
*\r
* This task should never exit; it should end with some kind of infinite loop, even if empty.\r
*\r
-lDist*r=theta\r
-rDist*(r+15)=theta\r
-cDist*(r+7.5)=theta\r
-theta/lDist=r\r
-rDist*(theta/lDist+15)=theta\r
-rDist*theta/lDist+15*rDist=theta\r
-rDist/lDist+15*rDist/theta=1\r
-1-15*rDist/theta=rDist/lDist\r
-theta=(1-15*rDist)*lDist/rDist\r
-theta=(lDist-15*rDist*lDist)/rDist\r
-theta=lDist/rDist-heading*lDist\r
-theta=\r
*/\r
-static int rRot,lRot,cRot,time1,time2,iHeading;\r
-static float lDist,\r
- theta,\r
- rDist,\r
- cDist,\r
- wheelD=3,\r
- pi=3.14159,\r
- heading=15,\r
- startTheta,\r
- fHeading;\r
+\r
/* notes for Clyne:\r
* Other processes should not interupt the collection of data:\r
* rotation calculation should be and data collection should be a high priority/primary task\r
*\r
*\r
*/\r
+static long lVel,rVel,deltaPos,deltaTime,startTheta,\r
+ heading,lDist,rDist,xPos,yPos,\r
+ track=15;\r
void operatorControl() {\r
heading=startTheta;\r
while (1) {\r
- time1=micros();\r
- cRot=(encoderGet(encoder1)-encoderGet(encoder2));\r
- cDist=(cRot*pi)/120;\r
- fHeading=(cDist/12)*(360/(2*pi));\r
- iHeading=round(fHeading)%360;\r
-\r
- lcdPrint(uart2,1,"iHeading: %d",iHeading);\r
-\r
- if(fHeading<360){\r
- motorSet(10,-60);\r
- motorSet(1,20);\r
-\r
- }else{\r
- motorSet(10,0);\r
- motorSet(1,0);\r
\r
- }\r
- /* lRot=encoderGet(encoder1);\r
- rRot=encoderGet(encoder2);\r
- lDist=(lRot*pi)/120;\r
- rDist=(rRot*pi)/120;\r
- lcdPrint(uart2,1,"iHeading: %d",iHeading);\r
- if(digitalRead(1)==0){\r
- motorSet(1,120);\r
- }\r
- else if(digitalRead(2)==0){\r
- motorSet(10,-120);\r
- }\r
- else{\r
- motorSet(1,0);\r
- motorSet(10,0);\r
- }\r
- */\r
+ //get time 1 the first time\r
+ heading=((lDist-rDist)/(track*2*PI))*360+startTheta;//heading in degrees. might need to be radians for cosine functions\r
+ //get time 2\r
+ deltaPos=(lVel+rVel)/2*deltaTime;\r
+ xPos+=cos(heading)*deltaPos;\r
+ yPos+=sin(heading)*deltaPos;\r
+ //get time 1\r
delay(20);\r
\r
}\r