diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-30 14:30:46 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-30 14:30:46 -0400 |
commit | 7afd68829c049cb61e4610836bda8adcf1f7ccee (patch) | |
tree | 649f9c7ed316ce1722c659c56fcc7810f5e89396 | |
parent | f60fcd1bb7b1044a7da5f6ecff89289f091a2773 (diff) |
first real commit
-rw-r--r-- | .project | 2 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | include/5106z.h | 121 | ||||
-rw-r--r-- | include/main.h | 2 | ||||
-rw-r--r-- | src/5106z.c | 105 | ||||
-rw-r--r-- | src/init.c | 5 | ||||
-rw-r--r-- | src/opcontrol.c | 150 | ||||
-rw-r--r-- | src/robot.cpp | 1 | ||||
-rw-r--r-- | src/robot.h | 6 |
9 files changed, 80 insertions, 314 deletions
@@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <projectDescription> - <name>VEX1516</name> + <name>VEX_1516</name> <comment></comment> <projects> </projects> diff --git a/README.md b/README.md deleted file mode 100644 index 1b6f7c4..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# vex5106z -The Kennett Coders 5106z codebase for our fantastic robot that will win everything diff --git a/include/5106z.h b/include/5106z.h deleted file mode 100644 index 2f2f5c3..0000000 --- a/include/5106z.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef _5106Z_H_ -#define _5106Z_H_ - -#include <API.h> -#include <stdint.h> -#include <stdarg.h> - -/* - * motor_init - Initialize motors - * - * `count` - The number of motors to enable - * `...` - The port numbers of the motors to enable - * - * Enables motors on the ports specified in the `...` arguments after - * `count`, which should say how many ports are currently being - * initialized. Motors not initialized now will be unusable until they - * are enabled. - * -*/ -void motor_init(uint8_t count,...); -/* - * motor_initIMEs - * - * Sets up IMEs for the motors that have them. This function expects the - * motors passed to it to be in order of how they are plugged in to the - * cortex. There is _no_ error checking, so... yeah. - * -*/ -void motor_initIMEs(uint8_t count,...); -/* - * motor_imeReset - * - * Resets the IME on the motor at port `port` if the motor was init'd - * using motor_initIMEs() and is enabled. - * -*/ -int motor_imeReset(uint8_t port); -/* - * motor_imeRead - * - * Returns the IME reading of the port `port` if it was init'd using - * motor_initIMEs() and is enabled. - * -*/ -int motor_imeRead(uint8_t port); -/* - * motor_enable & motor_disable - * - * `port` - The port of the motor to enable/disable - * - * These calls modify the `enable` bit of the motor. If a motor is disabled - * its speed will be set to 0 and rendered unchangeable until the motor is - * re-enabled. Any motor_* calls made to a disabled motor will immediately - * return -1. - * -*/ -void motor_enable(uint8_t port); -void motor_disable(uint8_t port); -/* - * motor_togglePolarity - * - * `port` - The port to toggle polarity on - * - * Flips the polarity of the motor on port `port` if its enabled. When a - * motor's polarity is enabled the speed written to it is inverted as it - * is passed to motorSet(). For example, if a motor's speed is 127 and it's - * polarity is enabled, the speed passed to motorSet() is -127. - * -*/ -int motor_togglePolarity(uint8_t port); -/* - * motor_setSpeed - * - * `port` - The port to set the speed of - * `speed` - The speed to set the motor to - * - * Sets the motor to the given speed, if it is enabled. Keep in mind that - * the change is not applied immediately, to apply the speeds you must - * call motor_applySpeeds(). - * -*/ -int motor_setSpeed(uint8_t port,int8_t speed); -/* - * motor_setSpeedSum - * - * `port` - The port to set the speed of - * `args` - The number of arguments following this one - * `...` - `args` variables to use for setting the speed - * - * Functions the same as motor_setSpeed(), but sets the speed to the sum - * of the arguments passed after `args`. - * -*/ -int motor_setSpeedSum(uint8_t port,uint8_t args,...); -/* - * TODO - * -*/ -int motor_setSpeedPointer(uint8_t port,int8_t *sp); -/* - * motor_setThreshold - * - * `port` - The port to set the threshold of - * `threshold` - The threshold to give the motor - * - * Sets a threshold for the motor's speed. This means that when calls to - * set this motor's speed are made in the future, the speed will only be - * applied if it's greater than `threshold` or less than -`threshold`. - * Otherwise, the speed is set to 0. - * -*/ -int motor_setThreshold(uint8_t port,uint8_t threshold); -/* - * motor_applySpeeds - * - * Applys the speeds of the enabled motors to the actual motors. - * -*/ -int motor_applySpeeds(void); - -#endif // _5106Z_H_ diff --git a/include/main.h b/include/main.h index 9b87513..ebe72a6 100644 --- a/include/main.h +++ b/include/main.h @@ -3,7 +3,7 @@ #include <API.h>
-#define LCD_PORT uart2
+#define LCD_PORT uart1
#define ANALOG_PORT(x) (x+13)
diff --git a/src/5106z.c b/src/5106z.c deleted file mode 100644 index 83462ce..0000000 --- a/src/5106z.c +++ /dev/null @@ -1,105 +0,0 @@ -#include <5106z.h> -#include <string.h> - -typedef struct { - int8_t *speedP; - int8_t speed; - uint8_t thresh; - uint8_t polarity :1; - uint8_t enable :1; - uint8_t useptr :1; - uint8_t imeable :3; -} __attribute__ ((packed)) motor_t; - -static motor_t motor[11]; - -void motor_init(uint8_t count,...){ - va_list m; - uint8_t i; - memset(motor,0,11*sizeof(motor_t)); - va_start(m,count); - for(i=0;i<count;i++){ - motor[va_arg(m,int)].enable=true; - } - va_end(m); -} - -void motor_initIMEs(uint8_t count,...){ - va_list m; - uint8_t i; - va_start(m,count); - for(i=0;i<count;i++){ - motor[va_arg(m,int)].imeable=i; - } - va_end(m); -} - -int motor_imeReset(uint8_t port){ - if(!motor[port].enable) return -1; - if(!motor[port].imeable)return -2; - imeReset(motor[port].imeable); - return 0; -} - -int motor_imeRead(uint8_t port){ - int imeValue; - if(!motor[port].enable) return -1; - if(!motor[port].imeable)return -2; - if(!imeGet(motor[port].imeable,&imeValue))return -3; - return imeValue; -} - -void motor_enable(uint8_t port){ - motor[port].enable=true; -} - -void motor_disable(uint8_t port){ - motor[port].enable=false; -} - -int motor_togglePolarity(uint8_t port){ - if(!motor[port].enable)return -1; - return (motor[port].polarity^=true); -} - -int motor_setSpeed(uint8_t port,int8_t speed){ - if(!motor[port].enable)return -1; - return (motor[port].speed=abs(speed)>motor[port].thresh?speed:0); -} - -int motor_setSpeedSum(uint8_t port,uint8_t args,...){ - va_list s; - uint8_t i; - int8_t speed=0; - if(!motor[port].enable)return -1; - va_start(s,args); - for(i=0;i<args;i++){ - speed+=va_arg(s,int); - } - va_end(s); - return motor_setSpeed(port,speed); -} - -int motor_setSpeedPointer(uint8_t port,int8_t *sp){ - if(!motor[port].enable)return -1; - motor[port].useptr=true; - motor[port].speedP=sp; - return 0; -} - -int motor_setThreshold(uint8_t port,uint8_t threshold){ - if(!motor[port].enable)return -1; - return (motor[port].thresh=threshold); -} - -int motor_applySpeeds(void){ - uint8_t i; - for(i=0;i<10;i++){ - if(motor[i].enable){ - if(motor[i].useptr) - motor[i].speed=*motor[i].speedP; - motorSet(i,motor[i].speed*(motor[i].polarity?-1:1)); - } - } - return 0; -} @@ -1,5 +1,6 @@ #include <main.h>
+Gyro gyro;
unsigned int imeCount;
void initializeIO(){
@@ -8,4 +9,8 @@ void initializeIO(){ void initialize(){
imeCount = imeInitializeAll();
+ gyro=gyroInit(2,0);
+ lcdInit(uart1);
+ lcdClear(uart1);
+ lcdSetBacklight(uart1,1);
}
diff --git a/src/opcontrol.c b/src/opcontrol.c index 6a2adee..bd3118a 100644 --- a/src/opcontrol.c +++ b/src/opcontrol.c @@ -1,106 +1,102 @@ #include <main.h>
+#include <stdint.h>
#include <string.h>
-#include <5106z.h>
enum MOTOR_PORT_MAP {
UNUSED = 0,
- ROTATER,
- DRIVEL,
- DRIVER,
- LIFT1,
- LIFT2,
INTAKE1,
+ DRIVEL ,
+ DRIVER ,
+ LIFT1 ,
+ LIFT2 ,
+ UNUSED6,
INTAKE2,
INTAKE3,
INTAKE4,
- PULLER,
+ ROTATER,
};
-static int8_t joyx = 0, // Contains the left joystick's x position
- joyy = 0, // Contains the left joystick's y position
- lift = 0, // Contains the desired speed for the lift
- rotate = 0; // Contains the desired speed for the lift's axis
+extern Gyro gyro;
+
+static signed int ctty=0;
+const unsigned int mtty=3;
-void shell(void *unused){
- char *input=(char *)malloc(4*sizeof(char));
+void operatorLCD(void *unused){
while(1){
- printf("debug@5106Z > ");
- memset(input,0,4);
- //fgets(input,4,stdin);
- input[0]=fgetc(stdin);
- printf("\n\r");
- switch(input[0]){
- case 'v':
- input[2]=fgetc(stdin);
- printf("\n\r");
- if(input[2]=='m')
- printf("Main voltage: %1.3f V\n\r",powerLevelMain()/1000.0f);
- else if(input[2]=='e')
- printf("Expander voltage: %1.3f V\n\r",analogRead(1)/70.0f);
+ switch(ctty){
+ default:
+ case 0:
+ lcdSetText(uart1,1," JOHN CENA ");
+ lcdSetText(uart1,2," ============ ");
break;
- case 't':
- printf("Test\n\r");
+ case 1:
+ lcdPrint(uart1,1,"MAIN: %0.3f",(float)(powerLevelMain()/1000.0f));
+ lcdPrint(uart1,2,"EXP : %0.3f",(float)(analogRead(1) / 210.0f));
break;
+ case 2:
+ lcdPrint(uart1,1,"Gyro: %u",gyroGet(gyro));
}
+ delay(2000);
}
}
void operatorControl(){
- motor_init(10, // Initialize 6 motor ports
- ROTATER,
- DRIVEL,
- DRIVER,
- LIFT1,
- LIFT2,
- INTAKE1,
- INTAKE2,
- INTAKE3,
- INTAKE4,
- PULLER);
-
- motor_togglePolarity(DRIVER ); // Flip the right drive motors
- motor_togglePolarity(ROTATER); // Flip the lift's rotation motor
-
-
+#define getJoy(n) joy[n-1]
- motor_setSpeedPointer(LIFT1 ,&lift ); // Always set the lift speed with `lift`
- motor_setSpeedPointer(LIFT2 ,&lift ); //
- motor_setSpeedPointer(ROTATER,&rotate); // Always set the lift's axis speed
- // with `rotate`
+ static int8_t joy[8],
+ lift = 0,
+ rotate = 0,
+ intake = 0,
+ uiinc = 0;
- extern unsigned int imeCount;
- motor_initIMEs(imeCount,
- DRIVER,
- DRIVEL,
- 0,
- 0,
- ROTATER);
-
- // Launch the shell
- taskCreate(shell,TASK_DEFAULT_STACK_SIZE,NULL,TASK_PRIORITY_DEFAULT);
+ // Start the LCD task
+ taskCreate(operatorLCD,TASK_DEFAULT_STACK_SIZE,NULL,TASK_PRIORITY_DEFAULT);
while(1){
- digitalWrite(1,lcdReadButtons(LCD_PORT));
-
- joyx = joystickGetAnalog(1,4); // Get joystick positions
- joyy = joystickGetAnalog(1,3); //
- lift = joystickGetAnalog(1,2); //
- rotate = joystickGetAnalog(1,1); //
-
- motor_setSpeedSum(DRIVEL,2,joyy, joyx); // Set drive speeds
- motor_setSpeedSum(DRIVER,2,joyy,-joyx); //
-
- static char huh;
- huh=joystickGetDigital(1,8,JOY_UP)?127:joystickGetDigital(1,8,JOY_DOWN)?-127:0;
- motor_setSpeed(INTAKE1,huh);
- motor_setSpeed(INTAKE2,huh);
- motor_setSpeed(INTAKE3,huh);
- motor_setSpeed(INTAKE4,huh);
-
- motor_setSpeed(PULLER,joystickGetDigital(1,7,JOY_UP)?127:joystickGetDigital(1,7,JOY_DOWN)?-127:0);
+ joy[0]=joystickGetAnalog(1,1);
+ joy[1]=joystickGetAnalog(1,2);
+ joy[2]=joystickGetAnalog(1,3);
+ joy[3]=joystickGetAnalog(1,4);
+ joy[4]=joystickGetAnalog(2,1);
+ joy[5]=joystickGetAnalog(2,2);
+ joy[6]=joystickGetAnalog(2,3);
+ joy[7]=joystickGetAnalog(2,4);
+
+ intake = getJoy(7);
+ rotate =-getJoy(5);
+ lift = joystickGetDigital(2,6,JOY_UP ) ? 127 :
+ joystickGetDigital(2,6,JOY_DOWN) ? -127 :
+ 0;
+
+ motorSet(INTAKE1,intake);
+ motorSet(INTAKE2,intake);
+ motorSet(INTAKE3,intake);
+ motorSet(INTAKE4,intake);
+ motorSet(ROTATER,rotate);
+ motorSet(LIFT1,lift);
+ motorSet(LIFT2,lift);
+
+ motorSet(DRIVEL,-getJoy(2));
+ motorSet(DRIVER, getJoy(3));
+
+ /*motorSet(PULLER,joystickGetDigital(2,6,JOY_UP ) ? 127 :
+ joystickGetDigital(2,6,JOY_DOWN) ? -127 :
+ 0);*/
+
+ if(++uiinc==20){
+ uiinc=0;
+ if(joystickGetDigital(1,7,JOY_UP) ||
+ joystickGetDigital(2,7,JOY_UP) ){
+ if(++ctty==mtty)ctty=0;
+ }
+ else if(joystickGetDigital(1,7,JOY_DOWN) ||
+ joystickGetDigital(2,7,JOY_DOWN) ){
+ if(--ctty==-1)ctty=mtty-1;
+ }
+ }
- motor_applySpeeds(); // Apply the motor speeds
+ delay(10);
}
}
diff --git a/src/robot.cpp b/src/robot.cpp deleted file mode 100644 index 82c45cd..0000000 --- a/src/robot.cpp +++ /dev/null @@ -1 +0,0 @@ -#include <robot.h> diff --git a/src/robot.h b/src/robot.h deleted file mode 100644 index f8887da..0000000 --- a/src/robot.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef ROBOT_H_ -#define ROBOT_H_ - -#include <API.h> - -#endif /* ROBOT_H_ */ |