View unanswered posts | View active topics It is currently Wed May 23, 2018 6:41 pm

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Using Void Statements?
Author Message

Joined: Wed Apr 10, 2013 12:05 pm
Posts: 7
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)

Tue Jun 25, 2013 10:52 pm
Senior Roboticist

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
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

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
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.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.

Wed Jun 26, 2013 9:26 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 3 posts ]

Who is online

Users browsing this forum: No registered users and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning