Go to Post We design for being on a dysfunctional alliance: all the time. - boomergeek [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-02-2016, 14:54
Lesafian Lesafian is offline
Registered User
AKA: Jeremy Styma
FRC #6077 (Wiking Kujon)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2016
Location: Posen, Michigan
Posts: 20
Lesafian is an unknown quantity at this point
Re: Is my Java code ok?

Won't this only work if I move the stick up? Shouldn't I need both > and < .1 if I'd like to both increase and decrease

Example of what I mean:
Code:
			if (Math.abs(xboxController.getRawAxis(5)) > .1) {
                               
                                //set your motor output to the axis value
				slideMotor.set(xboxController.getRawAxis(5));

			
			}else if (Math.abs(xboxController.getRawAxis(5)) < .1 {
                                slideMotor.set(xboxController.getRawAxis(5));
                        }
  #2   Spotlight this post!  
Unread 03-02-2016, 15:20
soundfx's Avatar
soundfx soundfx is offline
Registered User
AKA: Aaron J
FRC #3238 (Cyborg Ferrets)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Anacortes, WA
Posts: 14
soundfx is an unknown quantity at this point
Re: Is my Java code ok?

Quote:
Won't this only work if I move the stick up? Shouldn't I need both > and < .1 if I'd like to both increase and decrease
MaGiC_PiKaChU is correct. His code will test the absolute value for the threshold, then set the motor power to the joystick. Yours would probably work just as well, but the else if is redundant since it will never evaluate to true.
  #3   Spotlight this post!  
Unread 03-02-2016, 18:05
MaGiC_PiKaChU's Avatar
MaGiC_PiKaChU MaGiC_PiKaChU is offline
Drive Coach
AKA: Antoine L.
FRC #3360 (Hyperion)
Team Role: Mentor
 
Join Date: Mar 2014
Rookie Year: 2012
Location: Sherbrooke
Posts: 608
MaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond repute
Re: Is my Java code ok?

Quote:
Originally Posted by Lesafian View Post
Won't this only work if I move the stick up? Shouldn't I need both > and < .1 if I'd like to both increase and decrease

Example of what I mean:
Code:
			if (Math.abs(xboxController.getRawAxis(5)) > .1) {
                               
                                //set your motor output to the axis value
				slideMotor.set(xboxController.getRawAxis(5));

			
			}else if (Math.abs(xboxController.getRawAxis(5)) < .1 {
                                slideMotor.set(xboxController.getRawAxis(5));
                        }
No. The math.abs function transforms your value to positive.

if (Math.abs(xboxController.getRawAxis(5) < .1) is equivalent to if(xboxController.getRawAxis(5) < .1 && xboxController.getRawAxis(5) > -.1)

Let's say you put Math.abs(-0.05). that will output 0.05. I recommend you try it out and print in the Riolog. That saves you a few lines in your code, instead of testing for both positive and negative values.
__________________
2012 - 3360 - Junior member
2013 - 3360 - Lead Programmer, Human player
2014 - 3360 - Lead Programmer, Human player
2015 - 3360 - Lead Programmer, Driver
2016 - 3360 - Mentor, Drive coach




Last edited by MaGiC_PiKaChU : 03-02-2016 at 19:42. Reason: fixed operator
  #4   Spotlight this post!  
Unread 03-02-2016, 19:33
mmaunu's Avatar
mmaunu mmaunu is offline
Registered User
FRC #2485 (W.A.R. Lords)
Team Role: Mentor
 
Join Date: Mar 2013
Rookie Year: 2010
Location: San Diego, CA
Posts: 88
mmaunu is a jewel in the roughmmaunu is a jewel in the roughmmaunu is a jewel in the roughmmaunu is a jewel in the rough
Re: Is my Java code ok?

Quote:
Originally Posted by MaGiC_PiKaChU View Post
No. The math.abs function transforms your value to positive.

if (Math.abs(xboxController.getRawAxis(5) < .1) is equivalent to if(xboxController.getRawAxis(5) < .1 || xboxController.getRawAxis(5) > -.1)
That should be an && (and) in your compound statement instead of an or.
__________________
2014 Las Vegas (Winners with 987, 2478; Excellence in Engineering)
2014 San Diego (Finalists with 987, 3250; Quality Award)
2013 Inland Empire (Winners with 1538, 968; Excellence in Engineering Award)
2013 San Diego (Finalists with 2984, 4322; Creativity Award)
2012 Las Vegas (Finalists with 2034, 3187; Quality Award)
  #5   Spotlight this post!  
Unread 03-02-2016, 19:42
MaGiC_PiKaChU's Avatar
MaGiC_PiKaChU MaGiC_PiKaChU is offline
Drive Coach
AKA: Antoine L.
FRC #3360 (Hyperion)
Team Role: Mentor
 
Join Date: Mar 2014
Rookie Year: 2012
Location: Sherbrooke
Posts: 608
MaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond repute
Re: Is my Java code ok?

Quote:
Originally Posted by mmaunu View Post
That should be an && (and) in your compound statement instead of an or.
you're right. Fixed it
__________________
2012 - 3360 - Junior member
2013 - 3360 - Lead Programmer, Human player
2014 - 3360 - Lead Programmer, Human player
2015 - 3360 - Lead Programmer, Driver
2016 - 3360 - Mentor, Drive coach



Closed Thread


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 05:33.

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