|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Is my Java code ok?
Thank you, I'll fix that! As far as everything else does it look ok?
|
|
#2
|
||||
|
||||
|
Re: Is my Java code ok?
I see that you initialized the RobotDrive with the port numbers of your speed controllers. I believe that this will work correctly because you are using victors, but it would be better practice to initialize it with the two speed controllers you already initialized.
Code:
drive = new RobotDrive(drivermotor1, drivemotor2); |
|
#3
|
|||
|
|||
|
Re: Is my Java code ok?
For us, although the code said "build successful" for code similar as shown below, it will throw an error (on the robot) and the driver station noted no code on the robot.
Code:
drivemotor1 = new Victor(0); drivemotor2 = new Victor(2); ... drive = new RobotDrive(0, 2); Once we did this change, everything worked fine. |
|
#4
|
|||||
|
|||||
|
Re: Is my Java code ok?
Quote:
also, your condition testing with Math.abs removes the negative sign, so your second if test will never work This is how it could be made Code:
// Move sliding mechanism forwards and backwards
//if your axis is not between -0.1 and 0.1
if (Math.abs(xboxController.getRawAxis(5)) > .1) {
//set your motor output to the axis value
slideMotor.set(xboxController.getRawAxis(5));
}else {
slideMotor.set(0);
}
|
|
#5
|
|||
|
|||
|
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));
}
|
|
#6
|
||||
|
||||
|
Re: Is my Java code ok?
Quote:
|
|
#7
|
|||||
|
|||||
|
Re: Is my Java code ok?
Quote:
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. Last edited by MaGiC_PiKaChU : 03-02-2016 at 19:42. Reason: fixed operator |
|
#8
|
||||
|
||||
|
Re: Is my Java code ok?
That should be an && (and) in your compound statement instead of an or.
|
|
#9
|
|||||
|
|||||
|
Re: Is my Java code ok?
you're right. Fixed it
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|