Why isn't my slowdown working?

Okay. I have this code to add joystick sensitivity(it seems to work):
void joystickSanatizer(floatx, floaty){
//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.

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?


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

Just change your multiplier variable to affect commanded rate of travel.

It doesn’t give you X^2 scaling, but not sure you need that.

Keeping the x^2 implementation:


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

I think this one does exactly what you were trying to do in your code.

Or even simpler, with squaring:


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

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?

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.

What I mean by it doesn’t work is that the motor doesn’t slow down. It keeps at the same speed.

Are you sure you’re pushing “Button #10”?