#include <main.h>\r
#include <stdint.h>\r
-#include <string.h>\r
-\r
-enum MOTOR_PORT_MAP {\r
- UNUSED = 0,\r
- INTAKE1,\r
- DRIVEL ,\r
- DRIVER ,\r
- LIFT1 ,\r
- LIFT2 ,\r
- UNUSED6,\r
- INTAKE2,\r
- INTAKE3,\r
- INTAKE4,\r
- ROTATER,\r
-};\r
-\r
-extern Gyro gyro;\r
+#include <math.h>\r
+\r
+extern Gyro gyro; // Originally defined in init.c\r
+\r
+/*\r
+ * These keep track of the current LCD 'window' and the number of 'windows' that exist.\r
+*/\r
\r
static signed int ctty=0;\r
-const unsigned int mtty=3;\r
+const unsigned int mtty=4;\r
+\r
+static double imeDriveLeft;\r
+static double imeDriveRight;\r
+static double imeRotater;\r
+\r
+static double gyroRotation;\r
+\r
+/*\r
+ * This runs as a separate task to update the LCD.\r
+*/\r
\r
void operatorLCD(void *unused){\r
+ static int ime;\r
+\r
while(1){\r
+\r
+ /*\r
+ * Display information according to the current 'window'.\r
+ */\r
+\r
switch(ctty){\r
default:\r
- case 0:\r
+\r
+ case 0: // Welcome screen\r
+\r
lcdSetText(uart1,1," JOHN CENA ");\r
- lcdSetText(uart1,2," ============ ");\r
+ lcdPrint(uart1,2," ===========%3d",motorGet(CANNON1));\r
break;\r
- case 1:\r
+\r
+ case 1: // Battery levels in volts\r
+\r
lcdPrint(uart1,1,"MAIN: %0.3f",(float)(powerLevelMain()/1000.0f));\r
- lcdPrint(uart1,2,"EXP : %0.3f",(float)(analogRead(1) / 210.0f));\r
+ lcdPrint(uart1,2,"EXP : %0.3f",(float)(analogRead(1) / 280.0f));\r
+ break;\r
+\r
+ case 2: // Gyroscope readings\r
+\r
+ imeGet(IROTATER,&ime);\r
+\r
+ double rot = ime / 3.0L / 627.2L * 10;\r
+\r
+ rot = floor(rot) / 10;\r
+\r
+ lcdPrint(uart1,1,"Gyro: %d",gyroGet(gyro));\r
+ lcdPrint(uart1,2,"Rot.: %.1lf",rot);\r
+\r
+ break;\r
+\r
+ case 3:\r
+\r
+ lcdPrint(uart1,1,"%.3lf",imeDriveLeft);\r
+ lcdPrint(uart1,2,"%.3lf",imeDriveRight);\r
+\r
break;\r
- case 2:\r
- lcdPrint(uart1,1,"Gyro: %u",gyroGet(gyro));\r
}\r
- delay(2000);\r
+\r
+ delay(500);\r
+ }\r
+}\r
+\r
+void operatorPoll(){\r
+ static int idl,idr,ir,gr;\r
+ while(1){\r
+\r
+ /*\r
+ * Read in rotations of motors and the current angle of the robot.\r
+ */\r
+\r
+ imeGet(DRIVEL,&idl); // Get reading\r
+ imeDriveLeft = idl / 627.0L; // Convert to wheel rotations\r
+ imeDriveLeft *= 8.64L; // Convert to distance in inches\r
+\r
+ imeGet(DRIVER,&idr); // Get reading\r
+ imeDriveRight = idr / 627.0L; // Convert to wheel rotations\r
+ imeDriveRight *= 8.64L; // Convert to distance in inches\r
+\r
+ imeGet(ROTATER,&ir);\r
+ imeRotater = ir / 627.0L;\r
+\r
+ gyroRotation = gyroGet(gyro);\r
+\r
+ delay(100);\r
}\r
}\r
\r
void operatorControl(){\r
\r
-#define getJoy(n) joy[n-1]\r
+ static bool selfAim = false;\r
\r
- static int8_t joy[8],\r
- lift = 0,\r
- rotate = 0,\r
- intake = 0,\r
- uiinc = 0;\r
+ static char uiinc = 0; // See below\r
\r
- // Start the LCD task\r
- taskCreate(operatorLCD,TASK_DEFAULT_STACK_SIZE,NULL,TASK_PRIORITY_DEFAULT);\r
+ static char in,lift; // Used to set the multiple cannon motors to the same joy-stick reading.\r
+\r
+ taskCreate(operatorLCD ,TASK_DEFAULT_STACK_SIZE,NULL,TASK_PRIORITY_DEFAULT);\r
+ taskCreate(operatorPoll,TASK_DEFAULT_STACK_SIZE,NULL,TASK_PRIORITY_DEFAULT);\r
\r
while(1){\r
\r
- joy[0]=joystickGetAnalog(1,1);\r
- joy[1]=joystickGetAnalog(1,2);\r
- joy[2]=joystickGetAnalog(1,3);\r
- joy[3]=joystickGetAnalog(1,4);\r
- joy[4]=joystickGetAnalog(2,1);\r
- joy[5]=joystickGetAnalog(2,2);\r
- joy[6]=joystickGetAnalog(2,3);\r
- joy[7]=joystickGetAnalog(2,4);\r
-\r
- intake = getJoy(7);\r
- rotate =-getJoy(5);\r
- lift = joystickGetDigital(2,6,JOY_UP ) ? 127 :\r
- joystickGetDigital(2,6,JOY_DOWN) ? -127 :\r
- 0;\r
-\r
- motorSet(INTAKE1,intake);\r
- motorSet(INTAKE2,intake);\r
- motorSet(INTAKE3,intake);\r
- motorSet(INTAKE4,intake);\r
- motorSet(ROTATER,rotate);\r
+ // Set the drive motors speeds.\r
+\r
+ motorSet(DRIVEL,joystickGetAnalog(1,3));\r
+ motorSet(DRIVER,joystickGetAnalog(1,2));\r
+\r
+ // Set the rotating motor speed.\r
+\r
+ if(!selfAim){\r
+\r
+ motorSet(ROTATER,-joystickGetAnalog(2,1)/2);\r
+\r
+ }else{\r
+\r
+ //static int gc=0,gl=0;\r
+\r
+ //gl = gc;\r
+ //gc = gyroGet(gyro);\r
+\r
+ }\r
+\r
+ // Set the cannon's speed.\r
+\r
+ in=joystickGetAnalog(2,3);\r
+\r
+ motorSet(CANNON1,in);\r
+ motorSet(CANNON2,in);\r
+ motorSet(CANNON3,in);\r
+ motorSet(CANNON4,in);\r
+\r
+ // Set the intake's speed.\r
+\r
+ motorSet(INTAKE,joystickGetDigital(1,6,JOY_UP )? 127 :\r
+ joystickGetDigital(1,6,JOY_DOWN)? -127 :\r
+ 0 );\r
+\r
+ // Set the lift's speed.\r
+\r
+ lift=joystickGetDigital(2,6,JOY_UP )? 127 :\r
+ joystickGetDigital(2,6,JOY_DOWN)? -127 :\r
+ 0 ;\r
+\r
motorSet(LIFT1,lift);\r
motorSet(LIFT2,lift);\r
\r
- motorSet(DRIVEL,-getJoy(2));\r
- motorSet(DRIVER, getJoy(3));\r
-\r
- /*motorSet(PULLER,joystickGetDigital(2,6,JOY_UP ) ? 127 :\r
- joystickGetDigital(2,6,JOY_DOWN) ? -127 :\r
- 0);*/\r
+ /*\r
+ * Miscellaneous operation handlers.\r
+ */\r
\r
- if(++uiinc==20){\r
+ if(++uiinc==20){ // Equates to every 200ms\r
uiinc=0;\r
+\r
+ // Goto next 'window'.\r
+\r
if(joystickGetDigital(1,7,JOY_UP) ||\r
joystickGetDigital(2,7,JOY_UP) ){\r
if(++ctty==mtty)ctty=0;\r
}\r
- else if(joystickGetDigital(1,7,JOY_DOWN) ||\r
+\r
+ // Goto previous 'window'.\r
+\r
+ if(joystickGetDigital(1,7,JOY_DOWN) ||\r
joystickGetDigital(2,7,JOY_DOWN) ){\r
if(--ctty==-1)ctty=mtty-1;\r
}\r
+\r
+ // Run autonomous (for testing wo/ competition switch).\r
+\r
+ if(joystickGetDigital(1,7,JOY_RIGHT))\r
+ autonomous();\r
+\r
+ // Goto test area.\r
+\r
+ if(joystickGetDigital(1,7,JOY_LEFT)){\r
+ static double target = 0;\r
+\r
+ if(!target) target = (imeDriveLeft+imeDriveRight) / 2 + 13;\r
+\r
+ motorSet(DRIVEL,60);\r
+ motorSet(DRIVER,60);\r
+\r
+ while((imeDriveLeft+imeDriveRight) / 2 < target)\r
+ delay(10);\r
+\r
+ motorSet(DRIVEL,0);\r
+ motorSet(DRIVER,0);\r
+\r
+ }\r
+\r
}\r
\r
- delay(10);\r
+ delay(10); // Short delay to allow task switching.\r
}\r
}\r