Go to Post It can't be too bad... it's Canada! :) - Brandon Martus [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 16-05-2015, 23:00
tahmid0517's Avatar
tahmid0517 tahmid0517 is offline
Registered User
AKA: Tahmid Sheikh
FRC #5036 (The Robo Devils)
Team Role: Engineer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Toronto, Ontario
Posts: 11
tahmid0517 is an unknown quantity at this point
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?
Reply With Quote
  #2   Spotlight this post!  
Unread 17-05-2015, 01:21
BigJ BigJ is offline
Registered User
AKA: Josh P.
FRC #1675 (Ultimate Protection Squad)
Team Role: Engineer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Milwaukee, WI
Posts: 945
BigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond repute
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 17-05-2015, 10:25
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,574
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
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);
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #4   Spotlight this post!  
Unread 17-05-2015, 14:19
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,043
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
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


Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:50.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi