Skip to content

Instantly share code, notes, and snippets.

@jakl
Last active August 29, 2015 14:22
Show Gist options
  • Save jakl/8f98235a23d3d3d4679e to your computer and use it in GitHub Desktop.
Save jakl/8f98235a23d3d3d4679e to your computer and use it in GitHub Desktop.
Robot
#pragma config(Motor, port2, frontRightMotor, tmotorNormal, openLoop)
#pragma config(Motor, port3, backRightMotor, tmotorNormal, openLoop)
#pragma config(Motor, port4, frontLeftMotor, tmotorNormal, openLoop, reversed)
#pragma config(Motor, port5, backLeftMotor, tmotorNormal, openLoop, reversed)
#pragma config(Sensor, dgtl11, frontRightbumper, sensorTouch)
#pragma config(Sensor, dgtl12, frontLeftbumper, sensorTouch)
#pragma config(Sensor, dgtl5, backrightbumper, sensorTouch)
#pragma config(Sensor, dgtl4, backLeftbumper, sensorTouch)
task moveBackwards()
{
motor[frontRightMotor] = -127;
motor[backRightMotor] = -127;
motor[frontLeftMotor] = -127;
motor[backLeftMotor] = -127;
}
task moveForwards()
{
motor[frontRightMotor] = 127;
motor[backRightMotor] = 127;
motor[frontLeftMotor] = 127;
motor[backLeftMotor] = 127;
}
task main()
{
wait1Msec(1500);
moveForwards();
while(true)
{
if (SensorValue(dgtl11) == 0)
{
moveForwards();
}
else
{
moveBackwards();
# Instead of waiting 3 seconds here
# you could record which sensor was pressed last and when it was pressed
# and inside your while(true) loop, do things based on which sensor was pressed when
# and never wait for more than a half second, so you have quicker responses.
# It doesn't look like this code can be asyncronous, so you need to have a tight fast loop.
wait1Msec(3000);
motor[frontRightMotor] = -100;
motor[backRightMotor] = -100;
motor[frontLeftMotor] = 100;
motor[backLeftMotor] = 100;
wait1Msec(5000);
}
if (SensorValue(dgtl12) == 0)
{
motor[frontRightMotor] = 127;
motor[frontRightMotor] = 127;
motor[backRightMotor] = 127;
motor[backLeftMotor] = 127;
}
else
{
motor[frontRightMotor] = -127;
motor[backRightMotor] = -127;
motor[frontLeftMotor] = -127;
motor[backLeftMotor] = -127;
wait1Msec(3000);
motor[frontRightMotor] = 100;
motor[backRightMotor] = 100;
motor[frontLeftMotor] = -100;
motor[backLeftMotor] = -100;
wait1Msec(5000);
}
if (SensorValue(dgtl5) == 0)
{
motor[frontRightMotor] = 127;
motor[frontRightMotor] = 127;
motor[backRightMotor] = 127;
motor[backLeftMotor] = 127;
}
else
{
Sleep(2000);
motor[frontRightMotor] = 127;
motor[backRightMotor] = 127;
motor[frontLeftMotor] = 127;
motor[backLeftMotor] = 127;
wait1Msec(2000);
motor[frontRightMotor] = -127;
motor[backRightMotor] = -127;
motor[frontLeftMotor] = 127;
motor[backLeftMotor] = 127;
wait1Msec(15000);
}
if (SensorValue(dgtl4) == 0)
{
motor[frontRightMotor] = 127;
motor[frontRightMotor] = 127;
motor[backRightMotor] = 127;
motor[backLeftMotor] = 127;
}
else
{
Sleep(2000);
motor[frontRightMotor] = 127;
motor[backRightMotor] = 127;
motor[frontLeftMotor] = 127;
motor[backLeftMotor] = 127;
wait1Msec(2000);
motor[frontRightMotor] = 127;
motor[backRightMotor] = 127;
motor[frontLeftMotor] = -127;
motor[backLeftMotor] = -127;
wait1Msec(15000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment