Eclipse not reading Joystick values

Hi, first-time mentor, first post here. I’m trying to get Eclipse working with Gazebo, but having some issues with the joystick inputs.

I’ve set up FRCSim on Ubuntu 14.04, as described in the WPI lib docs. Gazebo 6 runs fine, The sim_ds command seems to work fine, it recognizes my Logitech F710 as a RumblePad 2, fwiw.

When I run the jstest-gtk program, that shows the controller and registers Axis 0 and Axis 1 with full range of input – values change correctly when I use the controller.

However, when I run one of the example Robot programs in Eclipse (Java simulation build target), the values it reports from the joystick are all zeros.

My Robot program right now it basically all Joystick debug:

package org.usfirst.frc.team1.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.command.PrintCommand;

public class Robot extends IterativeRobot {
	RobotDrive myRobot;
	Joystick joystick;

	public void robotInit() {
		myRobot = new RobotDrive(0, 1);
		joystick = new Joystick(0); 
		//		myRobot.setSafetyEnabled(true);
		//		while (isOperatorControl() && isEnabled()) {
		Thread t = new Thread(() -> {
			while (!Thread.interrupted()) {            	
				double l = -1 * joystick.getX(), r = -1 * joystick.getRawAxis(0);
				System.out.println(l + " " + r);

				// Create some buttons
				JoystickButton d_up = new JoystickButton(joystick, 5);
				JoystickButton d_right = new JoystickButton(joystick, 6);
				JoystickButton d_down = new JoystickButton(joystick, 7);
				JoystickButton d_left = new JoystickButton(joystick, 8);
				JoystickButton l2 = new JoystickButton(joystick, 9);
				JoystickButton r2 = new JoystickButton(joystick, 10);
				JoystickButton l1 = new JoystickButton(joystick, 11);
				JoystickButton r1 = new JoystickButton(joystick, 12);

				// Connect the buttons to commands
				d_up.whenPressed(new PrintCommand("up"));
				d_down.whenPressed(new PrintCommand("down"));
				d_right.whenPressed(new PrintCommand("right"));
				d_left.whenPressed(new PrintCommand("left"));

				r1.whenPressed(new PrintCommand("r1"));
				r2.whenPressed(new PrintCommand("r2"));
				l1.whenPressed(new PrintCommand("l1"));
				l2.whenPressed(new PrintCommand("l2"));

I’m running sim_ds in terminal. Once it launches (and says “claims to have found 1 controllers”), I click the Logitech controller (first item in the list, rest are “Empty joystick”) and then click “Enable” on Teleop). One possibly useful thing is that when I stop the Eclipse program, sim_ds spits out the following:

WARNING|Gazebo Transport: Can't handle publisher_del
WARNING|Gazebo Transport: Can't handle publisher_del
WARNING|Gazebo Transport: Ignoring unsubscribe: topic: "/gazebo/frc/ds/state"
host: ""
port: 45388
msg_type: "gazebo.msgs.DriverStation"
latching: false

WARNING|Gazebo Transport: Ignoring unsubscribe: topic: "/gazebo/frc/ds/joysticks/0"
host: ""
port: 45388
msg_type: "gazebo.msgs.Joystick"
latching: false

Also, the controller is showing in the OS as js0:

$ ls /dev/input/js0 

It seems like I’m not connecting to the correct controller in my robot code, but not sure what it would be besides


Why did you create a thread for the drive?

Also, I notice that you set up your robot as IterativeRobot, but the loop in your thread is while(!Thread.interrupted()) {}. I"m not sure whether this is right for multithreaded, but it would be incorrect without the threading, as your other code would never get a chance to run.

Well, mostly because I don’t know what classes I should be using :slight_smile:

But when I tried other examples I’ve found in a few place (for instance this nice post), I get either no output at all (no results from


) or else get only one print statement, and then nothing (as though the loop isn’t working. Though I’ve noticed that if I remove the


entirely, it does at least loop (but still zero values).

public class Robot extends SampleRobot {
	// Simple robot handling instance variable
	RobotDrive myRobot;

	// A joystick instance variable
	Joystick joystick;

	// Robot class constructor. Inits channels for drive motors and joystick
	// USB id numbers
	public Robot() {
		myRobot = new RobotDrive(4, 3, 2, 1);
		joystick = new Joystick(0);

	// This function is called when entering teleoperated mode
	public void operatorControl() {
		// Be sure the drive motor safety system is disabled. (This system will
		// prevent the motors from driving if not commanded at a regular interval.)

		// While we haven't left teleoperated mode and the robot is enabled
		while (isOperatorControl() && isEnabled()) {
			// Command the robot to drive based on the joystick in arcade
			// configuration.
			double l = -1 * joystick.getX(), r = -1 * joystick.getRawAxis(0);
			System.out.println(l + "" + r);
			myRobot.arcadeDrive(l, r);

			// Wait 5ms to allow other processes time to run on the roboRio and not
			// bog down the system.

The threading code is borrowed from WPIlib docs here.

Well, I’ve made a tiny bit of progress. It seems the “sim_ds” application shortcut which the instructions have you create doesn’t exit cleanly – when I run it from the Ubuntu program manager, and then hit the red X to close it, it disappears, but is still running:

$ ps aux | grep java
ubuntu    19269 11.8  0.4 7280528 73496 ?       Sl   15:08   0:00 java -Djava.library.path=/home/ubuntu/wpilib/simulation/lib -jar /home/ubuntu/wpilib/simulation/jar/SimDS-all.jar

As a result, I had several copies running. Killing them all and then only running that command directly in the terminal helped.

Now I can get the robot moving, though my axis 0 and axis 1 seem to both move the robot forward/back, when using arcadeDrive:

			double l = joystick.getRawAxis(1), r = joystick.getRawAxis(0);
			myRobot.arcadeDrive(l, r, true);

Anyway, onward.

I seem to recall there being an issue with axis numbers not starting at 0, have you tried Axis 1 & 2 instead of 0 & 1?