ROBOTC.net forumshttp://robotc.net/forums/ Using Void Statements?http://robotc.net/forums/viewtopic.php?f=66&t=6036 Page 1 of 1

Author:  Cara [ Tue Jun 25, 2013 10:52 pm ]
Post subject:  Using Void Statements?

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)

 Author: NeXT-Generation [ Wed Jun 26, 2013 12:12 am ] Post subject: 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.

Author:  JohnWatson [ Wed Jun 26, 2013 9:26 am ]
Post subject:  Re: Using Void Statements?

Cara wrote:

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.

 Page 1 of 1 All times are UTC - 5 hours [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/