#define RightRM 1 #define LeftRM 3 #define LEFTSERVO 3 #define RIGHTSERVO 0 float distance; float rotation; #define TpC 41.23//re-configure values based on wheel size #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:
void black_line () { float i; while(1) { while(analog10(2&&3)>920){ //while both sensors 2 and 3 see white, move forward bk(1); bk(3); if(analog10(2)<920) //if sensor 2 see's black (left side) it will move left, to get off the black line) mav(1,-1000); mav(3,300); if(analog10(3)<920) // if sensor 3 see's black (right side) it will move right, to get off the black line) mav(1,-300); mav(3,1000); i = 5.0; while(digital(14)) //when the touch sensor is pressed, bot stops moving, and dumps balls, then descends the basket from dumping position { ao(); Dump_balls(); Decend_balls(); } } } } }
void black_line () { float i; while(1) { if(analog10(2)>650) mav(3,300); mav(1,-1000); i = 5.0; { while(analog10(2)<650){ mav(3,-1000); mav(1,300); while(digital(14)) { ao(); Dump_balls(); } } } } }
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.
void Dump_balls() //dump balls into tower { int i = 0; for(i = 0; i < 950; i+= 40) //go up at a certain speed to prevent launching of balls { set_servo_position(LEFTSERVO,i); set_servo_position(RIGHTSERVO,i); sleep(.1); } }
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
void Decend_balls() { int i = 950; //we replaced the 0 with 950, thinking it would start the servos at it's already 950 position, we were wrong. for(i =950; i < 0; i-=40) //in fact we're not sure if we did this right at all. { set_servo_position(LEFTSERVO,i); set_servo_position(RIGHTSERVO,i); sleep(.1); }
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.
| Attachment | Size |
|---|---|
| Blackline4.1.c | 4.93 KB |
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.
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), Norman Advanced Robotics (2010-2011), Norman High (2008-2009), Norman North (2005-2007), Whittier Middle School (2003-2004)
2012 VP of Comm, 2011 President, Botball Youth Advisory Council (2009-2012)
Whoops, I meant braces. I must have been kinda tired that day. Rereading my post, it was quite confusing. Thanks for clarifying Jeremy!