|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Why isn't my slowdown working?
Okay. I have this code to add joystick sensitivity(it seems to work):
void joystickSanatizer(float*x, float*y){ //Pointers All the Way!!! #starmaster if(*x<0){ *x*=*x; *x*=0-1; } else *x*=*x; if(*y<0){ *y*=*y; *y*=0-1; } else *y*=*y; } in TeleopPeriodic: float joyx=stick->GetRawAxis(0); float joyy=stick->GetRawAxis(1); joystickSanatizer(&joyx, &joyy); if(stick->GetRawButton(10)){ multiplier=0.4; } else multiplier=1; and then, after some unrelated code: rBot->ArcadeDrive(joyy*multiplier, joyx*multiplier); Where stick is an XBox 360 controller and rBot is a a RobotDrive object The point of this code is to slow down the robot... but it doesn't. Can someone help me fix this code or give me another way to slow down the robot. |
|
#2
|
||||
|
||||
|
Re: Why isn't my slowdown working?
Have you added debug print statements for you code to see if your inputs and outputs make sense?
THat might help you get a quick sanity check of where your code is going wrong. Is there's a reason you don't want to do something a little simpler? Code:
float joyx = stick->GetRawAxis(0);
float joyy = stick->GetRawAxis(1);
if(stick->GetRawButton(10)){
multiplier = 0.4;
} else {
multiplier = 1;
}
rBot->ArcadeDrive(joyy * multiplier, joyx * multiplier);
It doesn't give you X^2 scaling, but not sure you need that. Keeping the x^2 implementation: Code:
float joyx = stick->GetRawAxis(0);
float joyy = stick->GetRawAxis(1);
//#nostarmaster
joyx = joyx * abs(joyx);
joyy = joyy * abs(joyy);
if(stick->GetRawButton(10)){
multiplier = 0.4;
} else {
multiplier = 1;
}
rBot->ArcadeDrive(joyy * multiplier, joyx * multiplier);
Last edited by otherguy : 12-03-2015 at 17:22. Reason: added another option closer to original implementation |
|
#3
|
|||||
|
|||||
|
Re: Why isn't my slowdown working?
Or even simpler, with squaring:
Code:
float joyx=stick->GetRawAxis(0); float joyy=stick->GetRawAxis(1); multiplier = stick->GetRawButton(10) ? 0.4 : 1; rBot->ArcadeDrive(joyy*abs(joyy)*multiplier, joyx*abs(joyx)*multiplier); |
|
#4
|
|||
|
|||
|
Re: Why isn't my slowdown working?
Well, there's another portion of my code affected by the slowdown (the tote pickup motor) that is affected by the slowdown:
outside TeleopPeriodic: float motorpower; inside: if(stick->GetRawButton(10)) motorpower=0.4; else motorpower=1; later in TeleopPeriodic(where vmc is a talon object): vmc->Set(motorpower); and that does not work. any thoughts? |
|
#5
|
||||
|
||||
|
Re: Why isn't my slowdown working?
Can you share an actual excerpt from your code?
Can you elaborate on "doesn't work"? What action are you performing and how is the robot responding that leads you to the conclusion that it's not doing what you want? The 'code' looks reasonable, but you haven't really described what is happening, just that what happened isn't want you expected. |
|
#6
|
|||
|
|||
|
Re: Why isn't my slowdown working?
Quote:
|
|
#7
|
|||
|
|||
|
Re: Why isn't my slowdown working?
Are you sure you're pushing "Button #10"?
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|