• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

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              
              }  
          }
    }    
}
0
jasoncuevas
Asked:
jasoncuevas
  • 4
  • 2
1 Solution
 
PaulCaswellCommented:
I'm guessing that this bit:

            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

Is supposed to be done when bot hits the end of the tape. In this case your problem is with the if. Where is the break_beam sensor?

I'm not sure wexactly what you need to do but this may be a good idea:

Change:

if(analog(break_sensor) > 200 && break_count == 0)  //if break beam sensor is broken, it will do this

to

if(analog(break_sensor) > 200)  //if break beam sensor is broken, it will do this
{
 if (break_count == 0)
 {
  // I guess we are the end of the tape!
  break_count ++;
 }
 else
 {
  // Back at the start! Stop bot!
  break;
  }
}
else
{
 // As before.
 ...
}
0
 
PaulCaswellCommented:
Jason,

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

Paul
0
 
jasoncuevasAuthor Commented:
because it didn't answer my question, but I thought i'd give you points for the effort.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
PaulCaswellCommented:
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
0
 
jasoncuevasAuthor Commented:
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.
0
 
PaulCaswellCommented:
Jason,

Thats good! You certaily ask interesting questions.

Paul
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now