|
jayseninid
Rookie
Joined: Mon Dec 10, 2012 3:20 pm Posts: 1
|
 my robot go when i press start.
#pragma config(Hubs, S1, HTServo, HTMotor, HTMotor, HTMotor) #pragma config(Sensor, S1, , sensorI2CMuxController) #pragma config(Motor, mtr_S1_C2_1, left, tmotorTetrix, openLoop, reversed) #pragma config(Motor, mtr_S1_C2_2, front, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C3_1, liftleft, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C3_2, liftright, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C4_1, right, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C4_2, back, tmotorTetrix, openLoop) #pragma config(Servo, srvo_S1_C1_1, servo1, tServoNone) #pragma config(Servo, srvo_S1_C1_2, hand, tServoStandard) #pragma config(Servo, srvo_S1_C1_3, servo3, tServoNone) #pragma config(Servo, srvo_S1_C1_4, servo4, tServoNone) #pragma config(Servo, srvo_S1_C1_5, servo5, tServoNone) #pragma config(Servo, srvo_S1_C1_6, servo6, tServoNone) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// { #include "JoystickDriver.c" //allows computer and robot to communicate, also allows the Brick to talk to Joysticks
int joy1y1; //left motor int joy1y2; //right motor int joy1x2; //crab motors int joy2y1; //lift int position; //position of hands
int scaleForMotor(int joyvalue){ //ratios joystick value to motor values, exponentially squared
if(joyvalue == 0){ joyvalue=1; }
float scaledval = ((joyvalue / 127)^2)*100*(joyvalue/abs(joyvalue));
if(abs(scaledval) < 1){ scaledval=0; } return scaledval; }
task main(){
waitForStart();
motor[left]=0; //stop moving, set hands motor[front]=0; motor[liftleft]=0; motor[liftright]=0; motor[right]=0; motor[back]=0; servo[hand]=192;
while(true){
getJoystickSettings(joystick); //reads the current state of the joysticks.
joy1y1=scaleForMotor(joystick.joy1_y1); //interger that translates joysticks to motor values,exponential. joy1y2=scaleForMotor(joystick.joy1_y2); joy1x2=scaleForMotor(joystick.joy1_x2);
motor[left]=joy1y1; motor[right]=joy1y2;
if(joy1y1 > 0 && joy1y2 < 0){ //if rotating clockwise skidsteer, then front and back motors assist the turn motor[front] = (abs(joy1y1)+ abs(joy1y2))/2; motor[back]= -1*(abs(joy1y1)+ abs(joy1y2))/2; } else{ //otherwise front and back moters crab off of right joystick,x motor[front]=joy1x2; motor[back]=joy1x2; }
if(joy1y1 < 0 && joy1y2 > 0){ //if rotating counter clockwise skidsteer, then front and back motors assist the turn motor[front] = -1*(abs(joy1y1)+ abs(joy1y2))/2; motor[back]= (abs(joy1y1)+ abs(joy1y2))/2; } else{ //otherwise front and back moters crab off of right joystick,x motor[front]=joy1x2; motor[back]=joy1x2; }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// Gunner Controls /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
joy2y1=scaleForMotor(joystick.joy2_y1); //interger that translates joysticks to motor values,exponential. { motor[liftleft]=joy2y1; //the left gunner joystick controls the lifts up and down, exponential motor[liftright]=joy2y1; } if(joy1Btn(01)) { // if the blue button is pushed, close the hands position=120; }
if(joy1Btn(03)) { // if the red button is pushed, open the hands position=192; }
servo[hand]=position; //set hands every time it loops
}
}
|