![]() |
Programming Ring Light [Java]
Hi, Even though we are not a rookie team, this is the first year we have used a LED ring light. I have a few years experience with Java and though i have put several days into trying to program this light in java, I cannot figure it out. Right now we have 1 LED ring light hooked up to a Spike that is in turn connected to Digital I/O port 2 on the Digital Sidecar. Right now I just want to toggle the light with a trigger on the joystick. This is not the final thing I want though, it's just for testing. Any help will be appreciated.
|
Re: Programming Ring Light [Java]
If you're using a Spike Relay, then the signal cable should be connected to a Relay port on the sidecar, not a DIO port.
In your code, you'll want to use the Relay class. You use the Relay#set() method to control the output of the relay: Code:
// Create the relay |
Re: Programming Ring Light [Java]
Thanks for that, but that is the first thing that i tried, I moved over to the I/O ports because others seemed to be doing that. Ive been all over the Digital Sidecar.
|
Re: Programming Ring Light [Java]
When you call the Relay#set() method, the LEDs next to the relay ports on the sidecar change to indicate the state of each relay (red for reverse, green for forwards/on). Did you see these lights change while testing?
Could you post the relevant portions of your code? That will help to track down the problem. Another option you might have would be to wire your LED light to the solenoid module and use the Solenoid class to control it. |
Re: Programming Ring Light [Java]
While testing, I see the lights light up on the right relay channels. we also know that the spike and LED are wired up correctly because we placed the PWM for the compressor spike in the LED spike and the LED lit up. The only issue we could be having is a faulty PWM, but we switched it out twice.
|
Re: Programming Ring Light [Java]
Perhaps you wired the ring light incorrectly. Try reversing the wires.
|
Re: Programming Ring Light [Java]
Okay, it seems that the PWMs weren't in place properly. The light is toggled now, but i have another issue. when the button is pressed, the light simply flashed and the light on the spike shuts off. This can be repeated by pressing the button again and again, but the light never stays on.
|
Re: Programming Ring Light [Java]
We will be able to better help you debug your code if you post it here.
On another note...Do you really need to be able to turn the led ring on and off? It would be a lot easier to just connect it to the PDB. |
Re: Programming Ring Light [Java]
Here is the Code:
import edu.wpi.first.wpilibj.Talon; import edu.wpi.first.wpilibj.Relay; import edu.wpi.first.wpilibj.Victor; import edu.wpi.first.wpilibj.Joystick; import edu.wpi.first.wpilibj.Solenoid; import edu.wpi.first.wpilibj.Compressor; import edu.wpi.first.wpilibj.RobotDrive; import edu.wpi.first.wpilibj.SimpleRobot; import edu.wpi.first.wpilibj.SpeedController; import edu.wpi.first.wpilibj.GenericHID.Hand; import edu.wpi.first.wpilibj.AnalogPotentiometer; public class ASimpleJavaBot extends SimpleRobot { // Constants private static final Hand LEFTHAND = Hand.kLeft; private static final Hand RIGHTHAND = Hand.kRight; Solenoid launcherClosed = new Solenoid(1); Solenoid launcherOpen = new Solenoid(2); Solenoid armsClosed = new Solenoid(3); Solenoid armsOpen = new Solenoid(4); SpeedController frontRight = new Victor(3); SpeedController frontLeft = new Victor(2); SpeedController rearRight = new Victor(1); SpeedController rearLeft = new Victor(4); SpeedController rightArmMotor = new Talon(6); SpeedController leftArmMotor = new Talon(7); Compressor compressor = new Compressor(1, 1); Relay Light = new Relay(2); Joystick joy1 = new Joystick(1); XboxController cont1 = new XboxController(1); XboxController cont2 = new XboxController(2); RobotDrive drive = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight); /** * This function is called once each time the robot enters autonomous mode. */ public void autonomous() { } /** * This function is called once each time the robot enters operator control. */ public void operatorControl() { int count = 0; compressor.start(); boolean armsDown = false; boolean ltPressed = false; drive.setInvertedMotor(RobotDrive.MotorType.kFront Left, false); drive.setInvertedMotor(RobotDrive.MotorType.kRearL eft, false); drive.setInvertedMotor(RobotDrive.MotorType.kFront Right, true); drive.setInvertedMotor(RobotDrive.MotorType.kRearR ight, true); if (ltPressed == false) { if (cont2.getTrigger(LEFTHAND) == true) { if (armsDown == true) { armsOpen.set(false); armsClosed.set(true); armsDown = false; ltPressed = true; } else { armsOpen.set(true); armsClosed.set(false); ltPressed = true; armsDown = true; } } } else { if (cont2.getTrigger(LEFTHAND) == false) { ltPressed = false; } } if (cont2.getBumper(LEFTHAND) == true) { // up rightArmMotor.set(1); leftArmMotor.set(-1); } if (cont2.getBumper(RIGHTHAND) == true) { // down rightArmMotor.set(-.7); leftArmMotor.set(.7); } if ((cont2.getBumper(RIGHTHAND) == false) && (cont2.getBumper(LEFTHAND) == false)) { rightArmMotor.set(0); leftArmMotor.set(0); } if (cont1.getBumper(RIGHTHAND) == true) { Light.set(Relay.Value.kOn); } if (cont1.getBumper(RIGHTHAND) == false) { Light.set(Relay.Value.kOff); } } } private static double RoundToDecimalPlace(double value, int decimalPlaces) { double exponent = 10 ^ decimalPlaces; int rounded = (int) (value * exponent); return (double) rounded / exponent; } } |
Re: Programming Ring Light [Java]
Quote:
You can use kOn if you set the direction of the relay to Forward only. |
Re: Programming Ring Light [Java]
Thank you,
The kForward worked for me. |
Re: Programming Ring Light [Java]
Quote:
Code:
// Create the relay |
Re: Programming Ring Light [Java]
Quote:
Quote:
|
Re: Programming Ring Light [Java]
The code supplied is not going to work at all. The operatorControl() function is only called once, so it's necessary to surround all of the control logic in a while loop
Code:
while(isEnabled() && isOperatorControl()) { |
Re: Programming Ring Light [Java]
I'm not sure what you are talking about Nyaculak. The code here works just fine for me.
|
| All times are GMT -5. The time now is 13:17. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi