View Single Post
  #8   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