//Riley's code void TankDrive() { if(joystick.joy1_y1>deadZone || joystick.joy1_y1<-deadZone) { motor[FrontLeft]=scaleMotor(joystick.joy1_y1); motor[BackLeft]=scaleMotor(joystick.joy1_y1); /* nxtDisplayTextLine(1, "%d", scaleMotor); wait1Msec(5000); */ } else { motor[FrontLeft]=off; motor[BackLeft]=off; } if(joystick.joy1_y2>deadZone || joystick.joy1_y2<-deadZone) { motor[FrontRight]=scaleMotor(joystick.joy1_y2); motor[BackRight]=scaleMotor(joystick.joy1_y2); } else { motor[FrontRight]=off; motor[BackRight]=off; } }
// calculate left and right wheel commands void combine(uint32_t x, uint32_t y) { int32_t xError, yError, axesIn[2], axesOut[2]; xError = X_CENTER-x; yError = Y_TRACK-y; //cprintf("x: %d y: %d xError: %d yError: %d\n", x, y, xError, yError); axesIn[0] = g_transLoop.update(yError); axesIn[1] = g_rotLoop.update(xError); axisMap(axesIn, axesOut); rcs_setPos(LEFT_AXIS, scaleMotor(axesOut[0])); rcs_setPos(RIGHT_AXIS, scaleMotor(axesOut[1])); }
void motor(uint32_t x, uint32_t y) { static MotorLoop rloop(1600, 4500); static MotorLoop tloop(4000, 4000); int32_t xerror, yerror, axesIn[2], axesOut[2]; xerror = XCENTER-x; yerror = YTRACK-y; axesIn[0] = tloop.update(yerror); axesIn[1] = rloop.update(xerror); axisMap(axesIn, axesOut); rcs_setPos(0, scaleMotor(axesOut[0])); rcs_setPos(1, scaleMotor(axesOut[1])); }
task main() { //false=off/start position/etc. bool sweeperState=false; bool flagState=false; servo[basketServo]=basketServoUp; while(true) { //Riley's code if(abs(joystick.joy1_y1)>deadZone) { motor[FrontLeft]=scaleMotor(joystick.joy1_y1); motor[BackLeft]=scaleMotor(joystick.joy1_y1); //debug code /* nxtDisplayTextLine(1, "%d",scaleMotor(joystick.joy1_y1) ); wait1Msec(5000); */ } else { motor[FrontLeft]=0; motor[BackLeft]=0; } if(abs(joystick.joy1_y2)>deadZone) { motor[FrontRight]=scaleMotor(joystick.joy1_y2); motor[BackRight]=scaleMotor(joystick.joy1_y2); } else { motor[FrontRight]=0; motor[BackRight]=0; } //End of Riley's code //Toggling the sweeper if(joy2Btn(SWEEPERBUTTON)==true && sweeperState==false) { motor[sweeper]=sweeperOn; sweeperState=true; } else if(joy2Btn(SWEEPERBUTTON)==true && sweeperState==true) { motor[sweeper]=sweeperOff; sweeperState=false; } //Moving the arm up or down if((abs(ARMJOYSTICK))>deadZone && ARMJOYSTICK>0) { motor[armMotor]=armMotorUp; } else if((abs(ARMJOYSTICK))>deadZone && ARMJOYSTICK<0) { while(SensorValue[touchSensor]==0) { motor[armMotor]=-armMotorUp; } motor[armMotor]=armMotorUp; wait1Msec(50); motor[armMotor]=0; } else { motor[armMotor]=0; } //Change the basket servo position if(joy2Btn(BASKETUPBUTTON)==true) { servo[basketServo]=basketServoUp; } else if(joy2Btn(BASKETDOWNBUTTON)==true) { servo[basketServo]=basketServoStart; } //Turns the flag motor on/off if(joy2Btn(FLAGBUTTON)==true && flagState==false) { motor[flagMotor]=flagMotorOn; flagState=true; } else if(joy2Btn(FLAGBUTTON)==true && flagState==true) { motor[flagMotor]=0; flagState=false; } wait1Msec(1); } }
task main() { //false=off bool sweeperState=false; servo[basketServo]=basketServoUp; while(true) { getJoystickSettings(joystick); //Riley's code if(joystick.joy1_y1>deadZone || joystick.joy1_y1<-deadZone) { motor[FrontLeft]=scaleMotor(joystick.joy1_y1); motor[BackLeft]=scaleMotor(joystick.joy1_y1); /* nxtDisplayTextLine(1, "%d", scaleMotor); wait1Msec(5000); */ } else { motor[FrontLeft]=off; motor[BackLeft]=off; } if(joystick.joy1_y2>deadZone || joystick.joy1_y2<-deadZone) { motor[FrontRight]=scaleMotor(joystick.joy1_y2); motor[BackRight]=scaleMotor(joystick.joy1_y2); } else { motor[FrontRight]=off; motor[BackRight]=off; } //End of Riley's code //Toggling the sweeper if(joy2Btn(SWEEPERONBUTTON)==true && sweeperState==false) { motor[sweeper]=sweeperOn; sweeperState=true; } else if(joy2Btn(SWEEPEROFFBUTTON)==true && sweeperState==true) { motor[sweeper]=off; sweeperState=false; } //Reverses the sweeper direction while the button is pressed if(joy2Btn(SWEEPERREVBUTTON)==true) { motor[sweeper]=-sweeperOn; } else if(sweeperState==true) { motor[sweeper]=sweeperOn; } else if(sweeperState==false) { motor[sweeper]=off; } //Moving the arm up or down if(ARMJOYSTICK>deadZone) { motor[armMotor]=armMotorUp; } else if(ARMJOYSTICK<-deadZone) { //Checks if touchsensor is pressed before moving the arm if(SensorValue[touchSensor]==touchUnpressed) { motor[armMotor]=-armMotorUp; } else { motor[armMotor]=off; } } else { motor[armMotor]=off; } //Change the basket servo position if(joy2Btn(BASKETUPBUTTON)==true) { servo[basketServo]=basketServoUp; } else if(joy2Btn(BASKETDOWNBUTTON)==true) { servo[basketServo]=basketServoDown; } //Turns the flag motor on/off if(joy2Btn(FLAGBUTTON)==true /*&& flagState==false*/) { motor[flagMotor]=flagMotorOn; //flagState=true; } else if(joy2Btn(FLAGADJUSTBUTTON)==true) { motor[flagMotor]=flagMotorAdjust; } else /*if(joy2Btn(FLAGBUTTON)==true && flagState==true)*/ { motor[flagMotor]=off; //flagState=false; } } }