|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
need help understanding c code in robotdrive
hey...
i have this code that i got from WPILib. its a part from robotdrive.cpp Code:
RobotDrive::RobotDrive(SpeedController *frontLeftMotor, SpeedController *rearLeftMotor, SpeedController *frontRightMotor, SpeedController *rearRightMotor, float sensitivity) 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 : Code:
myrobot.robotdrive(1,2,3,4,float sensitivity) Code:
* 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) ![]() |
|
#2
|
|||
|
|||
|
Re: need help understanding c code in robotdrive
Sensitivity is a multiplier in case you have a different brand of joystick (from what I can understand). I'd set it to 1.
|
|
#3
|
|||
|
|||
|
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); } |
|
#4
|
||||
|
||||
|
Re: need help understanding c code in robotdrive
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 |
|
#5
|
||||
|
||||
|
Re: need help understanding c code in robotdrive
ok which code i could use to pass a pwm number ??
maybe this?? Code:
RobotDrive::RobotDrive(UINT32 frontLeftMotor, UINT32 rearLeftMotor, UINT32 frontRightMotor, UINT32 rearRightMotor, float sensitivity) |
|
#6
|
||||
|
||||
|
Re: need help understanding c code in robotdrive
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...
|
|
#7
|
||||
|
||||
|
Re: need help understanding c code in robotdrive
still waiting !!!
![]() |
|
#8
|
||||
|
||||
|
Re: need help understanding c code in robotdrive
Quote:
As far as replacing speedcontroller if you look at the class the constructor is overloaded and one of the possible variations is: Code:
RobotDrive(UINT32 frontLeftMotorChannel, UINT32 rearLeftMotorChannel, UINT32 frontRightMotorChannel, UINT32 rearRightMotorChannel, float sensitivity = 0.5); Code:
myrobot.robotdrive(1,2,3,4); Code:
myrobot.ArcadeDrive(stick); |
|
#9
|
||||
|
||||
|
Re: need help understanding c code in robotdrive
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 ? |
|
#10
|
|||
|
|||
|
Re: need help understanding c code in robotdrive
Quote:
|
|
#11
|
|||
|
|||
|
Re: need help understanding c code in robotdrive
There are three ways of getting the robot to turn under program control in the library:
|
|
#12
|
||||
|
||||
|
Re: need help understanding c code in robotdrive
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 |
|
#13
|
||||
|
||||
|
Re: need help understanding c code in robotdrive
Code:
Joystick stick1(1);//ds port1 RobotDrive rd(1,2);//pwm port 1 and 2 and Code:
rd.ArcadeDrive(stick1); |
|
#14
|
||||
|
||||
|
Re: need help understanding c code in robotdrive
can you tell me what this code for exactly?
|
|
#15
|
||||
|
||||
|
Re: need help understanding c code in robotdrive
Code:
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)" and Code:
rd.ArcadeDrive(stick1); //Arcade drives (one joystick) the RobotBase rd with //the paramaters for speed and turn in Joystick stick1 Got it? |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help for Better Understanding of Shaft Encoders | Xufer | Programming | 2 | 08-01-2007 23:14 |
| need help w/ joystick code | willie837 | Programming | 6 | 02-02-2005 23:17 |
| code violation...need help | Vince lau | Programming | 4 | 20-02-2004 16:31 |
| Help with understanding Fuse panel | Blue_Midnight | Electrical | 3 | 10-02-2004 23:12 |
| hey need some help with writing a code please help me here | magical hands | Programming | 9 | 01-01-2004 21:46 |