Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Would this code work for kaj drive? (http://www.chiefdelphi.com/forums/showthread.php?t=137262)

tahmid0517 16-05-2015 23:00

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?

BigJ 17-05-2015 01:21

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.

GeeTwo 17-05-2015 10:25

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


Ether 17-05-2015 14:19

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