Go to Post the few, the proud, the animators. - BuddyB309 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-02-2014, 15:12
TheoBlacksmith's Avatar
TheoBlacksmith TheoBlacksmith is offline
Lead Programmer
FRC #0806 (Brooklyn Blacksmiths)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Brooklyn, NY
Posts: 37
TheoBlacksmith is on a distinguished road
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.
__________________
No matter what, It's always a programming problem

-Everyone Else On The Team

Reply With Quote
  #2   Spotlight this post!  
Unread 13-02-2014, 15:30
Domenic Rodriguez's Avatar
Domenic Rodriguez Domenic Rodriguez is offline
Registered User
FRC #0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Grove City, PA
Posts: 213
Domenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura about
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
Relay ledRelay = new Relay(RELAY_PORT);

// Control the relay
ledRelay.set(Relay.Value.kOn);
ledRelay.set(Relay.Value.kOff);
__________________

LuNaTeCs - Learning Under Nurturing Adults Teaching Engineering Concepts and Skills - Small and Mighty!

FRC 316 LuNaTeCs - Student (2011-2014), Lead Programmer (2011-2014), Team Captain (2013-2014), Operator (2013), Drive Coach (2014), Mentor (2015-????)
'11 Philly Regional Finalists, '13 Chestnut Hill Finalists, '13 Lenape Champions, '13 Archimedes Division, '14 Chestnut Hill Champions, '14 Lenape Champions
FTC 7071 EngiNerds - Founding Advisor (2013-2014) | FRC 5420 Velocity - Founding Advisor (2015)
Grove City College Class of '18, Electrical/Computer Engineering (B.S.E.E)

Reply With Quote
  #3   Spotlight this post!  
Unread 13-02-2014, 15:37
TheoBlacksmith's Avatar
TheoBlacksmith TheoBlacksmith is offline
Lead Programmer
FRC #0806 (Brooklyn Blacksmiths)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Brooklyn, NY
Posts: 37
TheoBlacksmith is on a distinguished road
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.
__________________
No matter what, It's always a programming problem

-Everyone Else On The Team

Reply With Quote
  #4   Spotlight this post!  
Unread 13-02-2014, 15:54
Domenic Rodriguez's Avatar
Domenic Rodriguez Domenic Rodriguez is offline
Registered User
FRC #0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Grove City, PA
Posts: 213
Domenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura about
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.
__________________

LuNaTeCs - Learning Under Nurturing Adults Teaching Engineering Concepts and Skills - Small and Mighty!

FRC 316 LuNaTeCs - Student (2011-2014), Lead Programmer (2011-2014), Team Captain (2013-2014), Operator (2013), Drive Coach (2014), Mentor (2015-????)
'11 Philly Regional Finalists, '13 Chestnut Hill Finalists, '13 Lenape Champions, '13 Archimedes Division, '14 Chestnut Hill Champions, '14 Lenape Champions
FTC 7071 EngiNerds - Founding Advisor (2013-2014) | FRC 5420 Velocity - Founding Advisor (2015)
Grove City College Class of '18, Electrical/Computer Engineering (B.S.E.E)

Reply With Quote
  #5   Spotlight this post!  
Unread 13-02-2014, 16:06
TheoBlacksmith's Avatar
TheoBlacksmith TheoBlacksmith is offline
Lead Programmer
FRC #0806 (Brooklyn Blacksmiths)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Brooklyn, NY
Posts: 37
TheoBlacksmith is on a distinguished road
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.
__________________
No matter what, It's always a programming problem

-Everyone Else On The Team

Reply With Quote
  #6   Spotlight this post!  
Unread 13-02-2014, 16:08
MagiChau's Avatar
MagiChau MagiChau is offline
Registered User
AKA: Michael Chau
FRC #0085 (B.O.B. (Built on Brains))
Team Role: Alumni
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Zeeland, Michigan
Posts: 875
MagiChau is just really niceMagiChau is just really niceMagiChau is just really niceMagiChau is just really nice
Re: Programming Ring Light [Java]

Perhaps you wired the ring light incorrectly. Try reversing the wires.
Reply With Quote
  #7   Spotlight this post!  
Unread 13-02-2014, 17:33
TheoBlacksmith's Avatar
TheoBlacksmith TheoBlacksmith is offline
Lead Programmer
FRC #0806 (Brooklyn Blacksmiths)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Brooklyn, NY
Posts: 37
TheoBlacksmith is on a distinguished road
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.
__________________
No matter what, It's always a programming problem

-Everyone Else On The Team

Reply With Quote
  #8   Spotlight this post!  
Unread 13-02-2014, 17:46
nyaculak nyaculak is offline
Registered User
FRC #0053 (Area 53)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Maryland
Posts: 28
nyaculak will become famous soon enough
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.
__________________
2013 MUC DC 3rd Place, FRC DC Regional, FRC Chesapeake Regional
2012 FRC DC Regional, FRC Chesapeake Regional
ERHS Robotics Club
- FRC Team 53 "Area 53"
www.erhsroboticsclub.org
Reply With Quote
  #9   Spotlight this post!  
Unread 13-02-2014, 17:52
TheoBlacksmith's Avatar
TheoBlacksmith TheoBlacksmith is offline
Lead Programmer
FRC #0806 (Brooklyn Blacksmiths)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Brooklyn, NY
Posts: 37
TheoBlacksmith is on a distinguished road
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;
}
}
__________________
No matter what, It's always a programming problem

-Everyone Else On The Team

Reply With Quote
  #10   Spotlight this post!  
Unread 13-02-2014, 17:57
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Programming Ring Light [Java]

Quote:
Originally Posted by DomenicR View Post
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
Relay ledRelay = new Relay(RELAY_PORT);

// Control the relay
ledRelay.set(Relay.Value.kOn);
ledRelay.set(Relay.Value.kOff);
This will not do what you expect. kOn sets both outputs of the spike to 12v, which will cause a motor or an LED to be off. You should use kForward.

You can use kOn if you set the direction of the relay to Forward only.
Reply With Quote
  #11   Spotlight this post!  
Unread 13-02-2014, 18:09
TheoBlacksmith's Avatar
TheoBlacksmith TheoBlacksmith is offline
Lead Programmer
FRC #0806 (Brooklyn Blacksmiths)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Brooklyn, NY
Posts: 37
TheoBlacksmith is on a distinguished road
Re: Programming Ring Light [Java]

Thank you,
The kForward worked for me.
__________________
No matter what, It's always a programming problem

-Everyone Else On The Team

Reply With Quote
  #12   Spotlight this post!  
Unread 13-02-2014, 18:54
Domenic Rodriguez's Avatar
Domenic Rodriguez Domenic Rodriguez is offline
Registered User
FRC #0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Grove City, PA
Posts: 213
Domenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura about
Re: Programming Ring Light [Java]

Quote:
Originally Posted by Joe Ross View Post
This will not do what you expect. kOn sets both outputs of the spike to 12v, which will cause a motor or an LED to be off. You should use kForward.

You can use kOn if you set the direction of the relay to Forward only.
I guess I was assuming that kOn would be equivalent to kForward by default; thanks for the heads up. So adding a call to Relay#setDirection() would give the desired behavior, right?
Code:
// Create the relay
Relay ledRelay = new Relay(RELAY_PORT);

// Specify the direction for the relay
ledRelay.setDirection(Relay.Direction.kForward);

// Control the relay
ledRelay.set(Relay.Value.kOn);
ledRelay.set(Relay.Value.kOff);
Normally I would just use kForward. The reasoning here was to avoid accidentally setting the relay to kReverse and potentially damaging the LEDs. Granted, it's easy enough to just remember not to use kReverse...
__________________

LuNaTeCs - Learning Under Nurturing Adults Teaching Engineering Concepts and Skills - Small and Mighty!

FRC 316 LuNaTeCs - Student (2011-2014), Lead Programmer (2011-2014), Team Captain (2013-2014), Operator (2013), Drive Coach (2014), Mentor (2015-????)
'11 Philly Regional Finalists, '13 Chestnut Hill Finalists, '13 Lenape Champions, '13 Archimedes Division, '14 Chestnut Hill Champions, '14 Lenape Champions
FTC 7071 EngiNerds - Founding Advisor (2013-2014) | FRC 5420 Velocity - Founding Advisor (2015)
Grove City College Class of '18, Electrical/Computer Engineering (B.S.E.E)

Reply With Quote
  #13   Spotlight this post!  
Unread 13-02-2014, 19:02
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Programming Ring Light [Java]

Quote:
Originally Posted by DomenicR View Post
I guess I was assuming that kOn would be equivalent to kForward by default; thanks for the heads up. So adding a call to Relay#setDirection() would give the desired behavior, right?
Yes.
Quote:
Originally Posted by DomenicR View Post
Normally I would just use kForward. The reasoning here was to avoid accidentally setting the relay to kReverse and potentially damaging the LEDs. Granted, it's easy enough to just remember not to use kReverse...
The nice thing about LEDs is they can't be damaged by reverse polarity (unless the thing you're driving has integrated control electronics also, but then you probably wouldn't be driving it from a spike).
Reply With Quote
  #14   Spotlight this post!  
Unread 13-02-2014, 21:11
nyaculak nyaculak is offline
Registered User
FRC #0053 (Area 53)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Maryland
Posts: 28
nyaculak will become famous soon enough
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()) {
    // code goes here
}
__________________
2013 MUC DC 3rd Place, FRC DC Regional, FRC Chesapeake Regional
2012 FRC DC Regional, FRC Chesapeake Regional
ERHS Robotics Club
- FRC Team 53 "Area 53"
www.erhsroboticsclub.org
Reply With Quote
  #15   Spotlight this post!  
Unread 14-02-2014, 12:22
TheoBlacksmith's Avatar
TheoBlacksmith TheoBlacksmith is offline
Lead Programmer
FRC #0806 (Brooklyn Blacksmiths)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Brooklyn, NY
Posts: 37
TheoBlacksmith is on a distinguished road
Re: Programming Ring Light [Java]

I'm not sure what you are talking about Nyaculak. The code here works just fine for me.
__________________
No matter what, It's always a programming problem

-Everyone Else On The Team

Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:17.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi