I’m trying to figure out how to attenuate the drive motor speed at the push of a button. For example, if normal operation allows for a value of 0 to 1, we’d like to be able to push a button and have the new value be 0 to 0.5.
I’ve been searching around for how to do this and I can’t seem to find anything definitive. I used Team 358’s examples but I’m not sure that I got it right. I’ve been using the LabVIEW simulator to test out the code. The robot moves but does not slow when I activate the joystick push button on the xbox controller (button 9). I’ve attached what I have so far.
Does “Button 9” mean the ninth button counting from 1, or counting from zero? Don’t forget that the first button is at array index 0, so the ninth button is actually at index 8. You can set a probe on the Buttons array to verify which one you need to be reading.
During the Beta Test, there was a strong preference among the Java and C++ teams for the button numbers in the code to match the labels on the joysticks/gamepads. The LabVIEW functions stayed with the zero-based arrays. It’s a little confusing if you’re moving between programming environments.
You do want the ninth button. But its value is in array index 8, because the first button is in index 0.
That post is from 2013 and applied to the cRIO and pre-2015 code. The xbox mapping has changed with the 2015 control system.
Aside from that your code looks fine once you change the index from a 9 to an 8.
Just make sure, depending on your drive train, that the rotate is still getting enough power to act against any wheel scrub at low power.
Instead of limiting the voltage that can be supplied, a different option would be to contour the joystick’s output to reduce the gain at low joystick commands but still allow full joystick output at high joystick commands.
This can be done with a smooth mapping function, or a piecewise-linear function, or a lookup table.
What I would do is make a true/false case structure so that when the “button pressed?” reads false it does nothing but when it reads true it divides the value by 2.
Voilà!
(Although if it IS a controller problem the above posts should help fix that :))