View Single Post
  #3   Spotlight this post!  
Unread 13-01-2009, 08:25
charrisTTI charrisTTI is offline
Ramblin' Wreck
AKA: Charles Harris
FRC #0623
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2003
Location: Vienna, VA
Posts: 106
charrisTTI has a spectacular aura aboutcharrisTTI has a spectacular aura about
Send a message via AIM to charrisTTI
Re: need help understanding c code in robotdrive

Here are the constructor declarations from robotdrive.h:

RobotDrive(UINT32 leftMotorChannel, UINT32 rightMotorChannel, float sensitivity = 0.5);
RobotDrive(UINT32 frontLeftMotorChannel, UINT32 rearLeftMotorChannel,
UINT32 frontRightMotorChannel, UINT32 rearRightMotorChannel, float sensitivity = 0.5);
RobotDrive(SpeedController *leftMotor, SpeedController *rightMotor, float sensitivity = 0.5);
RobotDrive(SpeedController &leftMotor, SpeedController &rightMotor, float sensitivity = 0.5);
RobotDrive(SpeedController *frontLeftMotor, SpeedController *rearLeftMotor,
SpeedController *frontRightMotor, SpeedController *rearRightMotor,
float sensitivity = 0.5);
RobotDrive(SpeedController &frontLeftMotor, SpeedController &rearLeftMotor,
SpeedController &frontRightMotor, SpeedController &rearRightMotor,
float sensitivity = 0.5);

This is the comment for the sensitivity parameter.

* @param sensitivity Effectively sets the turning sensitivity (or turn radius for a given value)

In each contstructor, there is a default value for the sensitivity parameter of 0.5.

If you want to use the default value, do not specify any value in that position.

ie:

myrobot.robotdrive(1,2,3,4); // using the default sensitivity of 0.5


If we go the .cpp file we can see how sensitivity is used.

In each of the constructors, the sensitivity parameter is copied to the class member variable m_sensitivity.

m_sensitivity = sensitivity;


The only method which uses m_sensitivity is Drive:

/**
* Drive the motors at "speed" and "curve".
*
* The speed and curve are -1.0 to +1.0 values where 0.0 represents stopped and
* not turning. The algorithm for adding in the direction attempts to provide a constant
* turn radius for differing speeds.
*
* This function sill most likely be used in an autonomous routine.
*
* @param speed The forward component of the speed to send to the motors.
* @param curve The rate of turn, constant for different forward speeds.
*/
void RobotDrive :: Drive(float speed, float curve)
{
float leftSpeed, rightSpeed;

if (curve < 0)
{
float value = log(-curve);
float ratio = (value - m_sensitivity)/(value + m_sensitivity);
if (ratio == 0) ratio =.0000000001;
leftSpeed = speed / ratio;
rightSpeed = speed;
}
else if (curve > 0)
{
float value = log(curve);
float ratio = (value - m_sensitivity)/(value + m_sensitivity);
if (ratio == 0) ratio =.0000000001;
leftSpeed = speed;
rightSpeed = speed / ratio;
}
else
{
leftSpeed = speed;
rightSpeed = speed;
}
SetLeftRightMotorSpeeds(leftSpeed, rightSpeed);
}
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010
Reply With Quote