So my rookie team has the basic drivetrain made and they want to test it out with the Logitech Extreme 3-D Pro Joystick.
We are running behind on our schedule and we need to test out the drivetrain immediately.
We have the Driver Station and Eclipse installed on the Acer Aspire E-11 that came with our kit this year, and we have all the necessary software loaded onto the RoboRIO.
Which example Robot Java Project (From WPILIB) will us to immediately load it on the RoboRIO and get the drivetrain functioning?
I wouldn’t suggest using an example. If you want something really simple and fast just make a new Robot Project. Then go to The Robot Class. create a joystick object “Joystick joy1 =new Joystick (0);” then create a motor object for each motor controller/Cim (My team personally uses talon motor controllers)“Talon Motor1 = new Talon(PWM PORT);” then go to your teleopperiodic and pull the X and Y value of the joystick, set it to a double . Then use double to set the speed of the motors.
In case you need more information, after creating a new Talon (or Jaguar), in the teleOp section, do
double speed = getRawAxis(ID_NUMBER); //ID_NUMBER is # of axis on joystick
motor1.set(speed);
The only problem I have is that Eclipse states that "The method getRawAxis(int) is undefined for Robot.java
Any hints here?
It should be like this:
double speed = joystick.getX();
This sets your double to the values being returned by your joystick. Then use that double to power your motor.
I forgot to mention some important information.
We are now trying to use the Xbox 360 Controller to use both analog sticks.
But we don’t know how to set one analog stick to the left side, and the other analog stick to the right side. Any hints?
Code is listed below
package org.usfirst.frc.team5938.robot;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.VictorSP;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class Robot extends IterativeRobot {
final String defaultAuto = "Default";
final String customAuto = "My Auto";
String autoSelected;
SendableChooser chooser;
Joystick stick = new Joystick(0);
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
chooser = new SendableChooser();
chooser.addDefault("Default Auto", defaultAuto);
chooser.addObject("My Auto", customAuto);
SmartDashboard.putData("Auto choices", chooser);
}
/**
* This autonomous (along with the chooser code above) shows how to select between different autonomous modes
* using the dashboard. The sendable chooser code works with the Java SmartDashboard. If you prefer the LabVIEW
* Dashboard, remove all of the chooser code and uncomment the getString line to get the auto name from the text box
* below the Gyro
*
* You can add additional auto modes by adding additional comparisons to the switch structure below with additional strings.
* If using the SendableChooser make sure to add them to the chooser code above as well.
*/
public void autonomousInit() {
autoSelected = (String) chooser.getSelected();
// autoSelected = SmartDashboard.getString("Auto Selector", defaultAuto);
System.out.println("Auto selected: " + autoSelected);
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
switch(autoSelected) {
case customAuto:
//Put custom auto code here
break;
case defaultAuto:
default:
//Put default auto code here
break;
}
}
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
VictorSP motor1 = new VictorSP(0);
VictorSP motor2 = new VictorSP(1);
double speed = stick.getRawAxis(1);
double speed1 = stick.getRawAxis(2);
motor1.set(speed);
motor2.set(speed1);
}
/**
* This function is called periodically during test mode
*/
public void testPeriodic() {
}
}
First you’ll need to make sure you know which axis goes to which joystick. Don’t connect up your robot motors (you might not even need to enable it, I can’t remember) and in the driverstation there will be one tab on the left side you can click that will show you a bunch of buttons and sliders that correlate to user input from the joystick. This will tell you what # you need for the getRawAxis(#) function.
You can use either the Getting Started project or the Tank Drive one. Getting started uses Arcade drive, Tank drive uses…Tank.
Either way you’ll need to make sure to have a couple of things mapped correctly in the code:
Which joystick axis do you need to use (using the above method)
Which motors need to get powered - this is determined by where your PWM cables are plugged into the rio.
If you have 2 CIMs per side - I highly recommend disconnecting one from power and ensuring they both treat forward as the same direction independently. It’s a good way to burnout motors or mess up gears if they’re fighting each other and you keep trying to make it move.
Probably common sense - but since it’s a rookie year I want to say this just in case: I also highly recommend putting the robot up on blocks and everything is free and clear of belts/chain/wheels until you feel comfortable it’s not going to go anywhere unexpectedly.