First, let me preface this with this : I am teaching myself java (uh-oh) I’m a mechanical mentor/ flight engineer who has only programmed HTML back when it was new (yikes!) closest to java I’ve ever been to was DHTM (remember that?).
I’m helping to start a new team to the north and I’m going to be relied upon to help teach the control system / programming among other things (everything else). It’s my weakest area so I’ve decided to dive in. I’ve set up a complete control board in my dining room (- brownie points) as well as maybe a smallish robot I’m building as a demo bot (already has a weight problem).
The problem I’m having is I mapped button 1 (A button) of a gamepad to turn on the spike (kOn) when pressed, and off at all other times. It worked. the problem now is I can’t map it to any other button - I can try to map it to 2, or 3, or 4, push the code, re boot the c-Rio, power cycle, it’s like button 1(A) has been hard wired to the spike on. even if I comment it out and push the code it still works?? :ahh:
attached is my very simple spaghetti code - I’m sure its probably something I’m missing (hopefully obvious to all of you. right now it has a left side and a right side drive to 4 can jags (which works just fine). My woes are with this relay. I have named the relay “light” as if it were actuating a light, which in this case all I’ve been doing is watching the state light on the spike itself.
here is the code.
/----------------------------------------------------------------------------/
/* Copyright © FIRST 2008. All Rights Reserved. /
/ Open Source Software - may be modified and shared by FRC teams. The code /
/ must be accompanied by the FIRST BSD license file in the root directory of /
/ the project. /
/----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.CANJaguar;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Relay;
/**
- 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 RobotTemplate extends IterativeRobot {
/** * This function is run when the robot is first started up and should be * used for any initialization code. */ //Dim Jags Joystick gp;// = new Joystick(1); //gamepad Relay light; //sets up a relay named 'light' CANJaguar leftFront; CANJaguar leftRear; CANJaguar rightFront; CANJaguar rightRear;
public void robotInit() { //switched wiring for left drive to reverse drive try { gp = new Joystick(1); light = new Relay(1); //defines new relay port 1 leftFront = new CANJaguar(10); leftRear = new CANJaguar(11); rightFront = new CANJaguar(12); rightRear = new CANJaguar(13); } catch (Exception e) { System.out.println("Exception Thrown"); e.printStackTrace(); } }
/**
- This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
light.set(Relay.Value.kOn);}
/** * This function is called periodically during operator control */ public void teleopPeriodic() {
if (gp.getRawButton(1)) { light.set(Relay.Value.kOn); } else { light.set(Relay.Value.kOff); } try{ //tank drive, gamepad try{ leftFront.setX(gp.getRawAxis(2));//pulls gamepad left stick leftRear.setX(gp.getRawAxis(2));//pulls gp left stick rightFront.setX(gp.getRawAxis(5));//pulls gp right stick rightRear.setX(gp.getRawAxis(5));//pulls gp right stick } catch(Exception e){ e.printStackTrace(); } } catch(edu.wpi.first.wpilibj.can.CANNotInitializedException cnie) { cnie.printStackTrace(); } }
}
Thanks for taking a look, hopefully I can figure this out. seams odd that I was able to program it in (didn’t do it before I added the programming) but now its all it wants to do - and its a bit .
The gamepad we are using is the logitech rumble F510 if that matters.