View unanswered posts | View active topics It is currently Sat Oct 25, 2014 1:52 pm






Reply to topic  [ 27 posts ]  Go to page Previous  1, 2
Help with simple programming 
Author Message
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Help with simple programming
van2007 wrote:
Wish me luck

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
Profile
Rookie

Joined: Wed Nov 30, 2011 6:00 pm
Posts: 13
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post 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
Profile
Rookie

Joined: Wed Nov 30, 2011 6:00 pm
Posts: 13
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post 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
Profile
Rookie

Joined: Wed Nov 30, 2011 6:00 pm
Posts: 13
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Help with simple programming
van2007 wrote:
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


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
Profile
Rookie

Joined: Wed Nov 30, 2011 6:00 pm
Posts: 13
Post Re: Help with simple programming
magicode wrote:
van2007 wrote:
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


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?


Thats just the sample code that I got the loop code from.


Wed Nov 30, 2011 10:13 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post 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
Profile
Rookie

Joined: Wed Nov 30, 2011 6:00 pm
Posts: 13
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post 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
Profile
Rookie

Joined: Wed Nov 30, 2011 6:00 pm
Posts: 13
Post Re: Help with simple programming
Okay, I'll try to do that.
Thanks!


Wed Nov 30, 2011 10:40 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 27 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: hexafraction and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.