Link to home
Start Free TrialLog in
Avatar of jasoncuevas
jasoncuevas

asked on

Running a motor using Interactive C

The project is to design a robot out of legos which, by using infrared and breakbeam sensors, will follow a path of black tape on a white floor, pick up a block at the end of the tape, turn around, follow the tape back, and stop at the end. My issue is trying to figure out how to get it to recognize that it's at the end of the tape. At the moment, it backs up if it gets off the tape (which it does 15-20 times while actually travelling the track), so when it gets to the end, it just spazzes by going alternating forward/backward on and off the tape.
Any help would be appreciated, here's the code.

void main()
{
    int left_motor = 1, right_motor = 3, left_sensor = 5,
      right_sensor = 6, break_sensor = 2, back_count = 0,
      break_count = 0, motor_sensor = 0;
   
    while(1)
      {
        if(analog(break_sensor) > 200 && break_count == 0)  //if break beam sensor is broken, it will do this
          {
            motor(left_motor,100);
            motor(right_motor,100);   //moves bot forward
            msleep(300L);
            off(left_motor);
            off(right_motor);
            motor(motor_sensor,100);  //activates muscle wire, traps box
            sleep(5.0);  
            off(motor_sensor); //turns motor_0 motors off
            motor(left_motor, 100);
            msleep(500L);
            motor(right_motor,-100);    //this makes robot pull a 180
            msleep(500L);
            break_count++;   //exits the loop permanently
        }
        else
          {  
            if(analog(left_sensor)<120 && analog(right_sensor)>120) //left sensor off tape
              {                                                     //right sensor on tap
                motor(left_motor,100);
                motor(right_motor,25);  //turns left motor on high, right motor 25%, turns left
              }
            if(analog(left_sensor)>120 && analog(right_sensor)>120) //both on tape
              {
                motor(left_motor,100);
                motor(right_motor,100);  //both motors full speed
              }
            if(analog(left_sensor)>120 && analog(right_sensor)<120) //left on, right off
              {    
                motor(left_motor,25);
                motor(right_motor,100);   //makes a right turn to get back on tape
              }
            if(analog(left_sensor)<120 && analog(right_sensor)<120) //both sensors off tape
              {
                motor(left_motor,-50);
                motor(right_motor,-50);   //back up both motors              
              }  
          }
    }    
}
ASKER CERTIFIED SOLUTION
Avatar of PaulCaswell
PaulCaswell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Jason,

Thanks for the points, why the 'C' grade?

Paul
Avatar of jasoncuevas
jasoncuevas

ASKER

because it didn't answer my question, but I thought i'd give you points for the effort.
Jason,

It has been correctly pointed out to me that my wording about grading might be misinterpreted.

>>A grade C generally means you dont think I put any effort in. Usually, grade C is used when, for example, someone just post you a link.
I did not intend to make this sound as personal as it came out. It is difficult to be an expert AND a page editor :). You have every right to give whatever grade you want. Grading is a personal thing. The more you visit here the more you will understand how everything works for everyone and the easier it will be to grade.

I would suggest, to begin with, you read the grading suggestions in the help system and have a thought about grading in general. We are only talking about points here, not money so its not terribly important. However, the experts who answer your questions and take part in the discussion get no money for what they do, they give their time patiently and with only your assistance in mind, and perhaps a point or two.

Paul
I'm sorry, I didn't realize that was how it worked. Thanks for helping me. I certianly didn't mean to imply that you hadn't given any effort. I'm reading all the stuff on the site right now.
Jason,

Thats good! You certaily ask interesting questions.

Paul