I have an elevator with a motor and i cant get it to go in reverse the line for the motor control is
m_motor.set(m_driverController.getRawAxis(kMotorPort));
Triggers are a little bit weird because they’re two halves of a single axis on most gamepads. So where most axes are -1 to +1, the triggers are usually just 0 to +1. You usually have to do some of your own logic to mix the two in a useful way.
I would do it this way:
double leftTrigVal = m_driverController.getRawAxis(/*axis number for left trigger*/);
double rightTrigVal = m_driverController.getRawAxis(/*axis number for right trigger*/) ;
double motorPwr = (leftTrigVal > 0)? -leftTrigVal : (rightTrigVal > 0)? rightTrigVal : 0;
m_motor.set(motorPwr);
In case you’re not familiar with the syntax, the motorPwr = etc. etc. bit is equivalent to:
if (leftTrigVal > 0)
{
motorPwr = -leftTrigVal; //negate for down direction
}
else if (rightTrigVal > 0)
{
motorPwr = rightTrigVal;
}
else
{
motorPwr = 0;
}
PSA: please use code blocks when sharing code. You just have to wrap the code in triple backticks, and you can even specify a language and it’ll lex it for you.