![]() |
Would this code work for kaj drive?
Hi, I'm new to programming and I wrote a piece of code that I don't have access to a robot right now to test on:
frontRight.set(stick1.getY() - stick2.getX()); backRight.set(stick1.getY() - stick2.getX()); frontLeft.set(stick1.getY()+ stick2.getX()); backLeft.set(stick1.getY()+ stick2.getX()); Assuming all the motor and joystick ports are declared correctly and this code is in the teleop periodic section, would this code work as a form of kaj drive where a robot's forward and backward motion is controlled with the left joystick and turning is controlled by the right joystick? |
Re: Would this code work for kaj drive?
It "would" work - however if the expression inside set() goes above 1.0 it will be cut off. It is worth thinking about how that will affect your controls.
|
Re: Would this code work for kaj drive?
The easiest way to scale to prevent set values outside of the -1 to 1 range would be to divide everything by 2. Unfortunately, this would reduce your maximum forward speed (and the others as well) by 50%.
It would also be cleaner to get the joystick numbers once rather than call the get() methods repeatedly. A fairly general way to combine the numbers which allows full speed but prevents bounds errors on the set() methods could be: Code:
fwd = stick1.getY(); |
Re: Would this code work for kaj drive?
...or you could just use the arcade drive in the Java WPILib and provide the fwd/rev from the left Y; and the turning from the right X |
| All times are GMT -5. The time now is 10:50. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi