|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Help! Robot Not Moving Even With Connection and Code!
Hi everyone. I'm a newbie programmer for Team 2496 and so far I have this driving code for our mecanum drive robot. However, even though I connected to the robot and enabled it, moving the joystick does nothing....Is there anything wrong with the code I have made for the 2015 roboRIO? I know for a fact it should be working because it worked on our team's older practice bot with the older cRIO.
package org.usfirst.frc.team2496.robot; import edu.wpi.first.wpilibj.RobotDrive; import edu.wpi.first.wpilibj.Joystick; import edu.wpi.first.wpilibj.IterativeRobot; public class Robot extends IterativeRobot { RobotDrive wholeDrive = new RobotDrive(0, 1, 2, 3); Joystick stick = new Joystick(1); public void robotInit() { wholeDrive.setInvertedMotor(RobotDrive.MotorType.k FrontRight, true); wholeDrive.setInvertedMotor(RobotDrive.MotorType.k RearRight, true); } public void autonomousPeriodic() { } public void teleopPeriodic() { wholeDrive.mecanumDrive_Polar(stick.getMagnitude() * .50, -stick.getDirectionDegrees(), stick.getTwist() * .75); if(stick.getRawButton(3)) { System.out.println("Button pressed!"); } if(stick.getRawButton(4)) { System.out.println("Regular Direction: " + stick.getDirectionDegrees()); } if(stick.getRawButton(1)) { this.driveStraight(1); System.out.println("Drive Straight Activated!"); } } public void driveStraight(int joystickButton) { double stickDegrees = 0; while (stick.getRawButton(joystickButton)) { if(stick.getDirectionDegrees() < 0) stickDegrees = -90.0; else stickDegrees = 90.0; wholeDrive.mecanumDrive_Polar(stick.getMagnitude() * .60, -stickDegrees, stick.getTwist()); } System.out.println("Stick Direction: " + stick.getDirectionDegrees()); } public void testPeriodic() { } } |
|
#2
|
||||
|
||||
|
Re: Help! Robot Not Moving Even With Connection and Code!
Joysticks are now zero-indexed. They probably should have made that clearer in the documentation.
|
|
#3
|
||||
|
||||
|
Re: Help! Robot Not Moving Even With Connection and Code!
What kind of speed controllers are you using? RobotDrive defaults to Talon speed controllers.
I would also recommend removing the while loop from driveStraight. Put that code inside the if statement instead of driveStraight as teleopPeriodic is already being called periodically. Also using [code] tags lets you share your code in a more reader-friendly style. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|