ROBOTC.net forumshttp://www.robotc.net/forums/ function problemhttp://www.robotc.net/forums/viewtopic.php?f=68&t=6163 Page 1 of 1

Author:  RobotMaster98 [ Thu Jul 04, 2013 12:56 am ]
Post subject:  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?

 Author: Ernest3.14 [ Thu Jul 04, 2013 2:52 pm ] Post subject: 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.

 Author: RobotMaster98 [ Thu Jul 04, 2013 3:00 pm ] Post subject: 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

Author:  rcahoon [ Fri Jul 05, 2013 10:09 am ]
Post subject:  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

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