Created
March 2, 2019 14:17
-
-
Save ringodin/c139340065ddf79bd65778ff3607108d to your computer and use it in GitHub Desktop.
Robot drives forward until it bumps, then backs up and turns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma config(Sensor, port5, bumpSwitch, sensorVexIQ_Touch) | |
#pragma config(Motor, motor1, leftMotor, tmotorVexIQ, openLoop, encoder) | |
#pragma config(Motor, motor6, rightMotor, tmotorVexIQ, openLoop, reversed, encoder) | |
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | |
/*------------------------------------------------------------------------------------------------ | |
Simple program to make your robot move forward until the Bumper Sensor is triggered (pressed). | |
ROBOT CONFIGURATION: VEX IQ Clawbot | |
MOTORS & SENSORS: | |
[I/O Port] [Name] [Type] [Location] | |
Port 1 leftMotor VEX IQ Motor (Reversed) Left side motor | |
Port 6 rightMotor VEX IQ Motor Right side motor | |
Port 2 bumpSwitch VEX IQ Bumper Bumper Sensor | |
------------------------------------------------------------------------------------------------*/ | |
task main() | |
{ | |
while(true) | |
{ | |
setMotorSpeed(leftMotor, 50); | |
setMotorSpeed(rightMotor, 50); | |
if(getBumperValue(bumpSwitch) == 1) | |
{ | |
setMotorSpeed(leftMotor, 0); | |
setMotorSpeed(rightMotor, 0); | |
sleep(500); //stop | |
resetMotorEncoder(leftMotor); | |
resetMotorEncoder(rightMotor); | |
moveMotorTarget(leftMotor, -500, -50); | |
moveMotorTarget(rightMotor, -500, -50); | |
waitUntilMotorStop(leftMotor); | |
waitUntilMotorStop(rightMotor); //backup | |
sleep(500); | |
resetMotorEncoder(leftMotor); | |
resetMotorEncoder(rightMotor); | |
moveMotorTarget(leftMotor, -200, -50); | |
moveMotorTarget(rightMotor, 200, 50); | |
waitUntilMotorStop(leftMotor); | |
waitUntilMotorStop(rightMotor); //turn left | |
sleep(500); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment