View unanswered posts | View active topics It is currently Fri Jul 29, 2016 11:55 am

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
function problem
Author Message
Rookie

Joined: Wed Jun 19, 2013 5:57 pm
Posts: 25
function problem
Hi I am try to make a function for the gyro turn program, but when the program runs the bot just goes in circles not a 90 degree turn.

Here is the original program

 Code:task main(){  //Specify the number of degrees for the robot to turn (1 degree = 10, or 900 = 90 degrees)  int degrees10 = 900;  //turnValue10 is used to take the current gyro sensor reading into account when turning  int turnValue10 = 0;   //Reset encoder and gyro values to 0  SensorValue[gyroSensor] = 0;  nMotorEncoder[motorA] = 0;  nMotorEncoder[motorB] = 0;  nMotorEncoder[motorF] = 0;  nMotorEncoder[motorG] = 0;  nMotorEncoder[motorH] = 0;  nMotorEncoder[motorI] = 0;  //Set turnValue10 equal to the current gyro reading plus the desired amount to turn  turnValue10 = abs(SensorValue[gyroSensor]) + abs(degrees10);   //Turn until the desired gyro value is reached +/- .5 degrees  //Reverse the polarity of the motors to turn the other direction   while(abs(SensorValue[gyroSensor]) < turnValue10 - 5 || abs(SensorValue[gyroSensor]) > turnValue10 + 5)   {      motor[motorD] = -20;      motor[motorE] = 20;      motor[motorF] = -20;      motor[motorG] = 20;   }   //Stop   motor[motorD] = 0;   motor[motorE] = 0;   motor[motorF] = 0;   motor[motorG] = 0;}

That works fine when I run it

Here is it made into a function

 Code:void gyroturn(float degrees, int Lmotors, int Rmotors){   int degrees10 = degrees;   int turnValue10 = 0;   SensorValue[gyroSensor] = 0;  nMotorEncoder[motorA] = 0;  nMotorEncoder[motorB] = 0;  nMotorEncoder[motorF] = 0;  nMotorEncoder[motorG] = 0;  nMotorEncoder[motorH] = 0;  nMotorEncoder[motorI] = 0;     turnValue10 = abs(SensorValue[gyroSensor]) + abs(degrees10);   while(abs(SensorValue[gyroSensor]) < turnValue10 - 5 || abs(SensorValue[gyroSensor]) > turnValue10 + 5)   {      motor[motorD] = Lmotors;      motor[motorE] = Rmotors;      motor[motorF] = Lmotors;      motor[motorG] = Rmotors;   }   motor[motorD] = 0;   motor[motorE] = 0;   motor[motorF] = 0;   motor[motorG] = 0;}

And here is program I am calling it from

can anyone help me?

_________________
-TheRobotMaster (or soon to be one)

FRC Team #2550 Skynet -Programmer 2013 - present

FTC Team #4508 E=MC^Squirreled -Second Programmer 2013-2014

FLL Team #3414 Team Brickstein -Mentor

Thu Jul 04, 2013 12:56 am
Professor

Joined: Sat May 18, 2013 1:24 pm
Posts: 271
Location: Olympia, WA
Re: function problem
Haven't used RVW too much myself, but it seems like you can't use nMotorEncoder[] in Virtual Worlds yet. It's not supported.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

Thu Jul 04, 2013 2:52 pm
Rookie

Joined: Wed Jun 19, 2013 5:57 pm
Posts: 25
Re: function problem
thanks for your help but I already fixed the problem . I had the speed on the turn set a little too high causing the gyro readings to go a little too fast for the program.

again thanks

_________________
-TheRobotMaster (or soon to be one)

FRC Team #2550 Skynet -Programmer 2013 - present

FTC Team #4508 E=MC^Squirreled -Second Programmer 2013-2014

FLL Team #3414 Team Brickstein -Mentor

Thu Jul 04, 2013 3:00 pm

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Re: function problem
 Ernest3.14 wrote:Haven't used RVW too much myself, but it seems like you can't use nMotorEncoder[] in Virtual Worlds yet. It's not supported.

nMotorEncoder should work in Virtual Worlds - please let us know if it's not. It's the NXT's regulated motors feature which is not yet implemented - nMotorEncoderTarget, nSyncedTurnRatio, nSyncedMotors, nMotorPIDSpeedCtrl, nMotorRunState.

Cheers,
--Ryan

_________________
Ryan Cahoon
RVW Software Developer

Fri Jul 05, 2013 10:09 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 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