View unanswered posts | View active topics It is currently Fri Aug 22, 2014 9:48 am






Reply to topic  [ 3 posts ] 
Using Void Statements? 
Author Message
Site Admin
Site Admin

Joined: Wed Apr 10, 2013 12:05 pm
Posts: 7
Post Using Void Statements?
Original Question posted on Facebook

have a question using void statements.Will this work for getting the robot to move forward?

Code:
void go straight (int speed, int distance)
{
  motor [leftmotor]= speed;
  motor [rightmotor]= speed;
  nMotorEncoder [leftmotor]=distance;
  nMotorEncoder [rightmotor]=distance;
}

task main ()
{
  gostraight (100,2000); /*go forward 100% power for 2000 degrees*/
}

My real question is how do I set up a void statement for a turn since left and right motors will be going at different speeds (either +/- for a point turn, or 0 for one motor and a + number for the other motor for a swing turn)


Tue Jun 25, 2013 10:52 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Using Void Statements?
You would need separate parameters for each motor, i.e LeftMotorSpeed, RightMotorTarget, etc.
If you're using RVW then you need a way to determine whether you should check if the current encoder count is greater than or less than the target. Otherwise nMotorEncoderTarget will work fine.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Wed Jun 26, 2013 12:12 am
Profile WWW
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 564
Post Re: Using Void Statements?
Cara wrote:
Original Question posted on Facebook

have a question using void statements.Will this work for getting the robot to move forward?

Code:
void go straight (int speed, int distance)
{
  motor [leftmotor]= speed;
  motor [rightmotor]= speed;
  nMotorEncoder [leftmotor]=distance;
  nMotorEncoder [rightmotor]=distance;
}

task main ()
{
  gostraight (100,2000); /*go forward 100% power for 2000 degrees*/
}

My real question is how do I set up a void statement for a turn since left and right motors will be going at different speeds (either +/- for a point turn, or 0 for one motor and a + number for the other motor for a swing turn)


A couple of things to note:
-These are called 'functions' and not 'void statements'; the reason for this distinction is that you can have many different types of functions (int, char, string, etc) and void is only one of the acceptable type. If you call them void statements, people may not know what you are talking about and it may cause some confusion.

-Be careful with the naming of your functions. Right now you have the function being called 'go straight' with a space in between, which will cause errors (because of the space in between the two words). The function is called correctly in task main, however.

-You may want to look through the videos that explain encoder usage again, just to be safe; the code you have in your gostraight function will turn the motors on, set the encoders to a value, and that's it. There isn't anything that actually controls how long the robot moves for, target distance, etc.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Wed Jun 26, 2013 9:26 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users 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.