need help understanding c code in robotdrive

hey…
i have this code that i got from WPILib. its a part from robotdrive.cpp

 RobotDrive::RobotDrive(SpeedController *frontLeftMotor, SpeedController *rearLeftMotor,
						SpeedController *frontRightMotor, SpeedController *rearRightMotor,
						float sensitivity)

i just copied it and pasted here from notepad.

i want to understand what is float sensitivity?? what could i put on it?
and other question: can i replace speedcontroller *… with a number of the pwm in the digital sidecar? i mean if i am using a victor and have a connection for pwm number 1 so could i write for example :

myrobot.robotdrive(1,2,3,4,float sensitivity)

and here are constructor maybe it could help:

* Constructor for RobotDrive with 4 motors specified as SpeedController objects.
 * Speed controller input version of RobotDrive (see previous comments).
 * @param rearLeftMotor The back left SpeedController object used to drive the robot.
 * @param frontLeftMotor The front left SpeedController object used to drive the robot
 * @param rearRightMotor The back right SpeedController object used to drive the robot.
 * @param frontRightMotor The front right SpeedController object used to drive the robot.
 * @param sensitivity Effectively sets the turning sensitivity (or turn radius for a given value) 

help me rapidly please:P

Sensitivity is a multiplier in case you have a different brand of joystick (from what I can understand). I’d set it to 1.

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);
    }

In answer to sensitivity:

Don’t worry about it, it
a) Has a default value
and
b) Will be gone soon if it isn’t already

In answer to your other question, you cannot pass a pwm number into the function - speedcontroller is an “placeholder” class, designed to allow operations on victors and jaguars by the same functions - so it does need to a class derived from speedcontroller

ok which code i could use to pass a pwm number ??
maybe this??

RobotDrive::RobotDrive(UINT32 frontLeftMotor, UINT32 rearLeftMotor,
		UINT32 frontRightMotor, UINT32 rearRightMotor, float sensitivity)

or can u write the code we can use to drive 4 motors (2 left . 2 right) with one joystick … so i could copy it to the simple template i got from frc and delete the tank code or the arcade…

still waiting !!! :frowning:

the sensitivity parameter you can leave out.

As far as replacing speedcontroller if you look at the class the constructor is overloaded and one of the possible variations is:

	RobotDrive(UINT32 frontLeftMotorChannel, UINT32 rearLeftMotorChannel,
				UINT32 frontRightMotorChannel, UINT32 rearRightMotorChannel, float sensitivity = 0.5);

so you could do

myrobot.robotdrive(1,2,3,4);

then for arcade

myrobot.ArcadeDrive(stick);

for 1 joystick control

yeah thanks it is working for arcade drive … but if i wanna all 4 wheels get just (y)axis speed what i have to change …
second Q. : We wanna use this year 2 motors to control the directions(see attachment files)
we have to make the motors number 1,2,3,4 just get speed from (y)axis
and motor number 5,6 … get the directions by (x) axis - {we wanna use one joystick for driving not more like tank!
so who can help me to do this ?

chassi.JPG


chassi.JPG

The class and the methods were designed for simple 2 and 4 motor drive robots with skid steering. If you have more complex designs then you might consider subclassing the RobotDrive class and adding your own method to control the motors. Also you grab the source code and modify it to work in your robot, although subclassing where possible is usually a better solution.

There are three ways of getting the robot to turn under program control in the library:

  1. RobotDrive:: Drive(speed, curve) - this takes a forward speed and rate of curve value. It tries to use the curve value to create a constant angle curve regardless of speed. We’d be interested in feedback on how well it’s working for you. The **sensitivity **
    parameter is used to modify that turn rate based on the curve parameter.
  2. RobotDrive::ArcadeDrive(moveValue, rotateValue) - uses the moveValue for forward speed and the rotateValue to bias the left and right sides of the robot like you would expect. One interesting thing here is that there is an optional parameter where it will square the inputs. Because the parameters are between -1.0 and 1.0 squaring the input has the effect of making the robot more sensitive at low speeds (expanding the low end of the joystick range). This can also be used with a Joystick parameter making it very easy to create a driving robot.
  3. RobotDrive::TankDrive(leftValue, rightValue) - the traditional tank drive sending the leftValue to the left side of the robot and the rightValue to the right side of the robot. This can also be used with Joystick parameters making it very easy to create a driving robot.

thank u
can u help me how to use this parameters to our robot??
i just want to give a speed by joystick (y) axis (forward,backward) to all the wheels
and the curves i wanna make by the same joystick (x) axis but not for the same motors … see the picture again that i attached

Joystick stick1(1);//ds port1
RobotDrive rd(1,2);//pwm port 1 and 2

at the top
and

rd.ArcadeDrive(stick1);

in the telop while loop

can you tell me what this code for exactly?

Joystick stick1(1);
//Declare Variable "stick1" of type "Joystick" on 
//Driverstation Port 1 "(1)"
RobotDrive rd(1,2);
//create variable "rd" of type "RobotDrive" (which controls 2
//or 4 pwm's for a base) with 2 pwm's on pwm ports 1 and 2 "(1,2)"

at the top
and

rd.ArcadeDrive(stick1);
//Arcade drives (one joystick) the RobotBase rd with
//the paramaters for speed and turn in Joystick stick1

in the telop while loop
Got it?