| Author |
Message |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 Re: Help with simple programming
Good Luck  And of course you can always ask more questions if you get stuck.
_________________ sudo rm -rf /
|
| Wed Nov 30, 2011 9:46 pm |
|
 |
|
van2007
Rookie
Joined: Wed Nov 30, 2011 6:00 pm Posts: 13
|
 Re: Help with simple programming
I actually did run into another program, looking over your sample program. I had my sonar sensor looped to spin back and forth in a circle. But when the robot would go to move, it would only spin in one direction.
I believe it looked something like this:
int = 0;
motor[motorA] = 25; wait1msec(2000); motor[motorA] = -25;
Then the move forward program;
I++;
|
| Wed Nov 30, 2011 9:53 pm |
|
 |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 Re: Help with simple programming
I'm sorry, but you're going to have provide a little more context that that. I see the part where the sonar turns, but what about int i = 0 and i++? Are you trying to code a for loop?
_________________ sudo rm -rf /
Last edited by magicode on Wed Nov 30, 2011 9:59 pm, edited 1 time in total.
|
| Wed Nov 30, 2011 9:57 pm |
|
 |
|
van2007
Rookie
Joined: Wed Nov 30, 2011 6:00 pm Posts: 13
|
 Re: Help with simple programming
Yes. I was trying to get the sonar spinning to continue looping until it saw something. What other information might you need?
|
| Wed Nov 30, 2011 9:59 pm |
|
 |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 Re: Help with simple programming
I meant about the program. Where is this piece of code located inside your program? Why are you setting int i = 0 and incrementing it?
_________________ sudo rm -rf /
|
| Wed Nov 30, 2011 10:00 pm |
|
 |
|
van2007
Rookie
Joined: Wed Nov 30, 2011 6:00 pm Posts: 13
|
 Re: Help with simple programming
The Int is located at the top, and the i++ is located at the end of the program.
And I set it like that because of this sample program: task main() { int i = 0; //the variable "i" is declared as an integer, and initialized to equal zero
while(i < 20) //a while loop is delcared with the variable "i" being less than 20 as its true condition { motor[motorA] = 75; //motor A is run at a 75 power level motor[motorB] = 75; //motor B is run at a 75 power level wait1Msec(4000); //the program waits 4000 milliseconds before running further code
motor[motorA] = 75; //motor A is run at a 75 power level motor[motorB] = -75; //motor B is run at a -75 power level wait1Msec(750); //the program waits 750 milliseconds before running further code
i++; //the variable "i" is incremented (increased) by 1 } }
|
| Wed Nov 30, 2011 10:05 pm |
|
 |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 Re: Help with simple programming
Are you trying to turn back and forth in this code? If so, why are motors A and B both running at 75 in one direction, and in opposite directions in the other direction?
_________________ sudo rm -rf /
|
| Wed Nov 30, 2011 10:11 pm |
|
 |
|
van2007
Rookie
Joined: Wed Nov 30, 2011 6:00 pm Posts: 13
|
 Re: Help with simple programming
Thats just the sample code that I got the loop code from.
|
| Wed Nov 30, 2011 10:13 pm |
|
 |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 Re: Help with simple programming
If you are trying to turn, then you should spin the motors in opposite directions. Now you said that the code worked when you were not moving forward. If this was the code that you used, then the robot should have only turned one way and then gone straight again and again in a loop.
_________________ sudo rm -rf /
|
| Wed Nov 30, 2011 10:19 pm |
|
 |
|
van2007
Rookie
Joined: Wed Nov 30, 2011 6:00 pm Posts: 13
|
 Re: Help with simple programming
I think you misunderstood. The movement of the robot wasn't the problem. But the spinning of the sonar sensor. It would rotate left to right, until it got to the part of the program that made the robot move. The sonar sensor would then just spin one direction.
|
| Wed Nov 30, 2011 10:26 pm |
|
 |
|
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 Re: Help with simple programming
Then could you please post the part that makes the sonar move? In fact, it would be a lot more helpful if you just posted your entire code. If you do not have access to it right now, perhaps you could post it when you do.
_________________ sudo rm -rf /
|
| Wed Nov 30, 2011 10:30 pm |
|
 |
|
van2007
Rookie
Joined: Wed Nov 30, 2011 6:00 pm Posts: 13
|
 Re: Help with simple programming
Okay, I'll try to do that. Thanks!
|
| Wed Nov 30, 2011 10:40 pm |
|
|