Command ataching issue

Hello,
While programming our robot I struggled with three problems I coud’nt solve that are all related to ataching commands to buttens/triggers and I wondered if it is all one problem.

In all three problems it did maneged to buid right but in the driver station I saw no robot code.

The first problem occurred when I tryed to define a command group and atach it to a button action.
The second problem was when I tryed to atach two commands to the same button (one to whileHeld and one to whenRelease).
The third problem was when I tryed to define a new Trigger to the throttel of the joystick and atach to it a command whenActive.

if someone knows what am I doing wrong it would be very helpfull.

If you could post a link to your code so we could read it, that would be helpful.

the first problem was when I added a command group to a button action.

the command group was :

public class DropAndCollect extends CommandGroup{

	public DropAndCollect() {
		// TODO Auto-generated constructor stub
		addSequential(new DropAndCollect());
		addSequential(new Collect());
	}
	
}

the OI was :

public class OI {
	public Joystick stick = new Joystick(0);
	public Button] btns = new Button[11];{
		for (int i = 0; i < 11; i ++){
			btns* = new JoystickButton(stick, i + 1);
		}
	}
	
    public OI(){
    	btns[0].whileHeld(new DropAndCollect());
    }
}

the second problem was when trying to have 2 commands at different actions of a button (in this case I also had no communication)

OI code :

public class OI {
	public Joystick stick = new Joystick(0);
	public Button] btns = new Button[11];{
		for (int i = 0; i < 11; i ++){
			btns* = new JoystickButton(stick, i + 1);
		}
	}
	
    public OI(){
    	btns[0].whenPressed(new DropCollector());
    	btns[0].whileHeld(new Collect());
    }
}

the third problem was when I tried to define a trigger and run a command with it.

trigger code:

public class ThrottleTrigger extends Trigger{

	@Override
	public boolean get() {
		// TODO Auto-generated method stub
		return Robot.oi.stick.getThrottle() > 0;
	}

}

OI code:

public class OI {
	public Joystick stick = new Joystick(0);
	public Button] btns = new Button[11];{
		for (int i = 0; i < 11; i ++){
			btns* = new JoystickButton(stick, i + 1);
		}
	}
	public ThrottleTrigger throttleTrigger = new ThrottleTrigger();
	
    public OI(){
    	throttleTrigger.whenActive(new RaiseCollectorArm());
    }
}

if someone knows why is that happening it will be very helpful.***

At a glance I can’t see anything wrong with your code, but here are some suggestions

  • If you lost communications, check your connection to the robot. Communications aren’t typically dependant on the presence of robot code (although robot code that crashes very quickly combined with auto-restart causes some problems in roboRIO responsiveness from experience)

  • If your robot code is crashing very quickly for some reason, the driverstation usually doesn’t have a chance to grab the log. Instead, open up an SSH session (with PuTTY on Windows and ssh on Linux, or whatever client you prefer) to “roborio-3211-frc.local” (default username is admin; password is blank [so hit enter directly on the prompt]) and use


tail -f /home/lvuser/FRC_UserProgram.log

This might allow you to catch some stack trace you’re not seeing

  • Try using the debugger. It will probably trigger a breakpoint on any error, so this might also allow you to see if anything’s causing a crash

The first addSequential is using the wrong class. As you have it, it will result in an infinite loop creating many nested DropAndCollect instances.

Hope this helps,
Steve