Following the black line with a rover 2.and descending a erect set_servo position.

3 replies [Last post]
Title: MiniBot
Joined: 06/21/2011
BotPoints: 29
User offline. Last seen 11 years 11 weeks ago.

  1. #define RightRM 1
  2. #define LeftRM 3
  3. #define LEFTSERVO 3
  4. #define RIGHTSERVO 0
  5. float distance;
  6. float rotation;
  7. #define TpC 41.23//re-configure values based on wheel size
  8. #define TpD 14.9694//re-configure values based on wheel size

ok so with the information I've gathered from the answer's I've gotten, i have a program for using one sensor, and a program for using two sensors. The program using one sensor works well, while the one using two has issues i cannot solve for the life of me. I've made a new thread for this, because the last was is a cluster-mash of useless information.

TWO SENSORS, they are to be hung on the left and right side of the black line, They track white, and move forward, if a certain tophat sensor see's black, it will adjust the robot to center itself on the line again. But, as nice as that sounds, it doesn't do any of that, and looking at the code, i can't help but say to myself "WHY ISN'T THIS WORKING?! IT MAKES PERFECT SENSE ON THE SCREEN! -pulls hair out-". If you have any changes or notice anything you could change, that'd be amazing:

  1. void black_line ()
  2. {
  3. float i;
  4. while(1)
  6. {
  7. while(analog10(2&&3)>920){ //while both sensors 2 and 3 see white, move forward
  8. bk(1);
  9. bk(3);
  11. if(analog10(2)<920) //if sensor 2 see's black (left side) it will move left, to get off the black line)
  12. mav(1,-1000);
  13. mav(3,300);
  14. if(analog10(3)<920) // if sensor 3 see's black (right side) it will move right, to get off the black line)
  15. mav(1,-300);
  16. mav(3,1000);
  17. i = 5.0;
  21. while(digital(14)) //when the touch sensor is pressed, bot stops moving, and dumps balls, then descends the basket from dumping position
  22. {
  23. ao();
  24. Dump_balls();
  25. Decend_balls();
  27. }
  28. }
  29. }
  30. }
  31. }

ONE SENSOR, this is what we're going to use for the time being until we get the double sensor working the way we'd like it to. it leads the bot down the line, but in a slow and inefficient way, done by constant jerks to the left and right, we'd rather have a smooth glide across the black line, with the use of one sensor if possible:
  1. void black_line ()
  2. {
  3. float i;
  4. while(1)
  6. {
  7. if(analog10(2)>650)
  8. mav(3,300);
  9. mav(1,-1000);
  10. i = 5.0;
  12. {
  14. while(analog10(2)<650){
  15. mav(3,-1000);
  16. mav(1,300);
  18. while(digital(14))
  19. {
  20. ao();
  21. Dump_balls();
  23. }
  24. }
  25. }
  26. }
  27. }

using the servos to dump a basket, such as the code i have below works well, because it slowly creeps the basket up where we need it to be, but as soon as it's done with the program, or the possible sleep we could put after it, The motors go Full speed back into the 0 degree position, This force slams down so hard, it causes damage to the robot it'self.

  1. void Dump_balls() //dump balls into tower
  2. {
  3. int i = 0;
  5. for(i = 0; i < 950; i+= 40) //go up at a certain speed to prevent launching of balls
  6. {
  7. set_servo_position(LEFTSERVO,i);
  8. set_servo_position(RIGHTSERVO,i);
  9. sleep(.1);
  12. }
  13. }

this is a major problem, so we assumed we could make another program and name it decend_balls, and then put it right under the Dump_balls program in hopes it would slowly let the basket back down

  1. void Decend_balls()
  2. {
  3. int i = 950; //we replaced the 0 with 950, thinking it would start the servos at it's already 950 position, we were wrong.
  4. for(i =950; i < 0; i-=40) //in fact we're not sure if we did this right at all.
  5. {
  6. set_servo_position(LEFTSERVO,i);
  7. set_servo_position(RIGHTSERVO,i);
  8. sleep(.1);
  9. }

so yeah, if anyone could help with that, that'd be great as well.

I will attach our whole program so far as-well, if you wish to go into the whole thing.

Blackline4.1.c4.93 KB
Nathan Bernard
Title: Botball Youth Advisory Council
Joined: 07/01/2011
BotPoints: 17
User offline. Last seen 9 years 23 weeks ago.

There is one bug that I noticed immediately. It is that you are not using brackets with your "if"s. You need to use brackets with these the same way as if they were "while"s. The reason your one sensor code works is because your "while(analog10(2)..." works correctly and once it resolves false (no longer over the line), the code goes back to line 7 where the "if" does nothing and the next two lines reset the motor speeds.

The servos probably slam back down because the program has ended. When the program ends, power is cut to all devices. This means the servos turn off and gravity takes over.

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
BotPoints: 1168
User offline. Last seen 7 years 19 weeks ago.

To elaborate, the reason why the if statement not having curly braces isn't giving a compile error is that when if statements (or while/for statements) don't have braces, the compiler inserts braces around only the first statement following the if. This is a nice shortcut for experienced programmers, but as you found, it can be confusing for newbies as well. Short answer, always use braces around the contents of if blocks.

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

Nathan Bernard
Title: Botball Youth Advisory Council
Joined: 07/01/2011
BotPoints: 17
User offline. Last seen 9 years 23 weeks ago.

Whoops, I meant braces. I must have been kinda tired that day. Rereading my post, it was quite confusing. Thanks for clarifying Jeremy!