|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
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? |
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
|||||
|
|||||
|
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(); rot = stick2.getX(); scale = Math.max(1.0, Math.abs(fwd) + Math.abs(rot); frontRight.set((fwd - rot) / scale); backRight.set((fwd - rot) / scale); frontLeft.set((fwd + rot) / scale); backLeft.set((fwd + rot) / scale); |
|
#4
|
||||
|
||||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|