View unanswered posts | View active topics It is currently Thu Aug 28, 2014 1:23 am






Reply to topic  [ 4 posts ] 
function problem 
Author Message
Rookie
User avatar

Joined: Wed Jun 19, 2013 5:57 pm
Posts: 25
Post 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


Code:

#include "FTCfunctions.h"


task main()
{

gyroturn(450, 75, -75);




}







can anyone help me?

_________________
-TheRobotMaster (or soon to be one)

FRC Team #2550 Skynet -Programmer 2013 - present
Website [url]sites.google.com/site/2550robotics[/url]

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

FLL Team #3414 Team Brickstein -Mentor


Thu Jul 04, 2013 12:56 am
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post 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).

and also quadrotors. Quadrotors!


Thu Jul 04, 2013 2:52 pm
Profile
Rookie
User avatar

Joined: Wed Jun 19, 2013 5:57 pm
Posts: 25
Post Re: function problem
thanks for your help but I already fixed the problem :D . 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
Website [url]sites.google.com/site/2550robotics[/url]

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

FLL Team #3414 Team Brickstein -Mentor


Thu Jul 04, 2013 3:00 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post 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
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Fri Jul 05, 2013 10:09 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

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