Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

a small problem on my robot

Status
Not open for further replies.

abbiati012

New Member
I am doing my robot programming, it supposes to turn left, stop, and turn right, but now it just make turns, I can't figure out, anyone can take look at my programming, thank u for reading , I really appreciate.....

int RIGHT_MOTOR= 0;
int LEFT_MOTOR = 2;
int LEFT_BUMPER=7;
int RIGHT_BUMPER=9;

#define TURE 1
#define FALSE 0

#define FORWARD 1
#define REVERSE 2
#define TURN_LEFT 3
#define TURN_RIGHT 4
#define STOP 5

persistent int ix;

void main()
{

while(1)
{
printf("Press start\n");
if (start_button())
{
while (!stop_button())
{
motor_routine(FORWARD);
if (digital(7))
{
motor_routine(STOP);
sleep(0.25);
motor_routine(REVERSE);
sleep(0.25);
motor_routine(TURN_RIGHT);
}
if (digital(9))
{
motor_routine(STOP);
sleep(.2);
motor_routine (REVERSE);
sleep(0.2);
motor_routine(TURN_LEFT);
sleep(.2);
}
}

}
}
}

void motor_routine( int motor_cmd)
{
if( motor_cmd==FORWARD)
{
fd(RIGHT_MOTOR);
fd(LEFT_MOTOR);
}
if( motor_cmd==REVERSE)
{
bk(RIGHT_MOTOR);
bk(LEFT_MOTOR);
}
if( motor_cmd==TURN_RIGHT)
{
ao();
motor(RIGHT_MOTOR,45);
}

if( motor_cmd==TURN_LEFT)
{
ao();
motor(LEFT_MOTOR,45);
}
if (motor_cmd==STOP)
{
ao();
}
}
 
this is my project:
Building the basic robot
In this exercise we will build a robot with the most basic behavior, escaping whenever it hits
something with its bumpers. Perform the following programming steps:
1. Upon pushing the START button, the robot moves forward and stops after the STOP
button is pushed.
If a bumper switch is activated:
2. Backup a quarter of the length of your robot using the IC time commands, storing any
constants set as persistent global variables for use in later programming (see page 12 of
the Handy Board manual or page 408 of your text).
3. Turn 45 in the opposite direction of the bumper switch activated (i.e., turn right if the left
bumper switch was engaged) and then continue forward.


Use the attached outline for your code.
// ECE 450: Bumper Car Lab
// Team #
// Names?
/*Port Definitions */
#define RIGHT_MOTOR 0 /* Motor Slot 0 */
#define LEFT_MOTOR 2 /* Motor Slot 2 */
/* Logic */
#define TRUE 1
#define FALSE 0
/* Motor Commands */
#define FORWARD 1
#define REVERSE 2
#define TURN_LEFT 3
#define TURN_RIGHT 4
#define STOP 5
/* Persistent variables */
persistent int ix;
void main()
{
while(TRUE)//infinite loop
{
Print ¡°Press Start¡± to the LCD Screen
Wait for the start button to be pressed
If Start Button is pressed
{
While The Stop Button isn¡¯t pressed
{
Move Forward
If Left Bumper is pressed
{ Stop
Backup 1/4 length of robot
Turn Right 45 degrees
}
If Right Bumper is pressed
{ Stop
Backup 1/4 length of robot
Turn Left 45 degrees
}
}
Stop Button was pressed so STOP
}
}
} //end of main routine
void motor_routine(int motor_cmd) // Defines motor actions
{
If (motor_cmd == FORWARD)
Set Right and Left motors to go forwards
If (motor_cmd == REVERSE)
Set Right and Left motors to go backwards
If (motor_cmd == TURN_RIGHT)
Set Right and Left motors so robot turns right
If (motor_cmd == TURN_LEFT)
Set Right and Left motors so robot turns left
If (motor_cmd == STOP)
Stop!
}//end of motor_routine definition
 
Status
Not open for further replies.

Latest threads

Back
Top