My group is having trouble having a robot move in a random maze, the robot has 4 wheels and has a limit switch in the front and back to detect a wall. We are using vex 393 motors. Can someone please help us code this?
Weâre not going to do it for you - you wouldnât learn anything, but we can give you a few things to think about.
First, what have you tried so far? Without writing it in code (just English for now), what âalgorithmâ could you think about that might acomplish your goal?
We are having trouble with the wheels moving and dont know how to code it, we tried putting a motor command but it does not work
Can you share your code? What do you have already? Please put it within [code]
and [/code]
tags. What is the behavior that occurs when you try running it?
We tried using
[code]
[motor[port1] = 40;]
but the wheels arent moving
Not quite formatted correctly (you can use the button that looks like code in the text box toolbar), but whatever.
Thatâs not the whole program. Can you please share the whole program?
[
#pragma config(CircuitBoardType, typeCktBoardUNO)
#pragma config(UART_Usage, UART0, uartSystemCommPort, baudRate200000, IOPins, dgtl1, dgtl0)
#pragma config(Sensor, dgtl7, ultrasonic, sensorSONAR_TwoPins_inch)
#pragma config(Motor, servo_10, rightServo, tmotorServoContinuousRotation, openLoop, reversed, IOPins, dgtl10, None)
#pragma config(Motor, motor_11, leftServo, tmotorServoContinuousRotation, openLoop, IOPins, dgtl11, None)
//!!Code automatically generated by âROBOTCâ configuration wizard !!//
void DriveBackward()
{
motor[leftServo] = -40;
motor[rightServo] = -40;
wait1Msec(400);
}
void DriveForwardUntilWall()
{
motor[leftServo] = 40;
motor[rightServo] = 40;
while(SensorValue[ultrasonic] <= 4) {}
DriveBackward();
}
void TurnRight()
{
motor[leftServo] = 40;
motor[rightServo] = -40;
wait1Msec(470); //will probably need to adjust time for your robot
}
void TurnLeft()
{
motor[leftServo] = -40;
motor[rightServo] = 40;
wait1Msec(475); //will probably need to adjust time for your robot
}
void Stop()
{
motor[leftServo] = 0;
motor[rightServo] = 0;
}
task main()
{
//wait 1 seconds before starting.
wait1Msec(1000);
DriveForwardUntilWall();
TurnLeft();
DriveForwardUntilWall();
TurnRight();
DriveForwardUntilWall();
TurnRight();
DriveForwardUntilWall();
Stop();]
re-formatted
#pragma config(CircuitBoardType, typeCktBoardUNO)
#pragma config(UART_Usage, UART0, uartSystemCommPort, baudRate200000, IOPins, dgtl1, dgtl0)
#pragma config(Sensor, dgtl7, ultrasonic, sensorSONAR_TwoPins_inch)
#pragma config(Motor, servo_10, rightServo, tmotorServoContinuousRotation, openLoop, reversed, IOPins, dgtl10, None)
#pragma config(Motor, motor_11, leftServo, tmotorServoContinuousRotation, openLoop, IOPins, dgtl11, None)
// *!!Code automatically generated by âROBOTCâ configuration wizard !!* //
void DriveBackward()
{
motor[leftServo] = -40;
motor[rightServo] = -40;
wait1Msec(400);
}
void DriveForwardUntilWall()
{
motor[leftServo] = 40;
motor[rightServo] = 40;
while(SensorValue[ultrasonic] <= 4) {}
DriveBackward();
}
void TurnRight()
{
motor[leftServo] = 40;
motor[rightServo] = -40;
wait1Msec(470); //will probably need to adjust time for your robot
}
void TurnLeft()
{
motor[leftServo] = -40;
motor[rightServo] = 40;
wait1Msec(475); //will probably need to adjust time for your robot
}
void Stop()
{
motor[leftServo] = 0;
motor[rightServo] = 0;
}
task main()
{
//wait 1 seconds before starting.
wait1Msec(1000);
DriveForwardUntilWall();
TurnLeft();
DriveForwardUntilWall();
TurnRight();
DriveForwardUntilWall();
TurnRight();
DriveForwardUntilWall();
Stop();
}
This might be the problem of why itâs not working. Your closing bracket is different to your opening bracket.
Use a curly bracket instead of a square bracket:
Stop();
}
Another problem seems to be in DriveForwardUntilWall()
:
The DriveBackward();
should be within the while statement.
while(SensorValue[ultrasonic] <= 4) {
DriveBackward();
}
Hope this fixes some of your problems.