Go to Post While one student may not be of much value to the team, do we ever stop to think about how much value the team may be to that student? - Madison [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 03-03-2011, 22:42
de_ de_ is offline
Registered User
AKA: Dave Edwards
FRC #1310 (Runnymede Robotics)
Team Role: Mentor
 
Join Date: Apr 2005
Rookie Year: 2005
Location: Toronto, Ontario
Posts: 256
de_ is a jewel in the roughde_ is a jewel in the roughde_ is a jewel in the roughde_ is a jewel in the rough
WPI Lib Relay class - individual line control

I can't quite figure out the WPI Lib description as to whether we can individually control each of the 2 output lines without effecting the other line. Here's an extreme example

On one line have an (12v) Red LED connected and be able to turn it on and off without effecting the state of what is on the other line of the spike. On the other line, we want to have a white 12v led that we flash in software, again, not effecting the Red LED.

The class description seems to hint that we need to declare 2 relays on the SAME channel,
- one with forward only (line 1) control
Relay m_relay1(1, Relay::KForwardOnly);
- and one with reverse only (line 2).
Relay m_relay2(1, RElay::kReverseOnly);

And then we can control each line relay individually.

Or do you declare a single relay and change the direction to access a specific line on the fly like

Relay m_relay(1);

:
m_relay.SetDirection(Relay::kForwardOnly); // access 1 line of the spike
m_relay.Set(Relay::kOn) ; // set On or Off 1st line
m_relay.SetDirection(Relay::kReverseOnly); // access 2nd line
m_relay.Set(Relay::kOn); // set On or Off 2nd line....
:

Sorry last coding I did was on an RC
Reply With Quote
  #2   Spotlight this post!  
Unread 04-03-2011, 05:42
java4first java4first is offline
(Java) Programming Mentor
AKA: Stu
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Nov 2010
Rookie Year: 2011
Location: Goffstown, NH
Posts: 56
java4first is an unknown quantity at this point
Re: WPI Lib Relay class - individual line control

We are doing something similar, and fortunately have a good Controls person to translate the h/w to s/w requirements. I don't have access to the code until we get back to the Verizon today - but we are doing something like this.

One relay has two LEDs, and one relay has one. On the two one, you create it, set the direction to both, and then by setting the value to either forward or backward, it turns one or the other on and the other off (toggle mode). Or you can set it off to turn both off.

For the relay with only one LED, we set the direction to forward(?) and then turn it on or off. Or something like that (I'm not as sure for this one).

Sorry I can't post the code at this point to make it work - but maybe this will help. If you use the output on the dashboard for the relays, you can see the two little lights (one above each other) go green and red as you set the state for which line is on and off.
Reply With Quote
  #3   Spotlight this post!  
Unread 04-03-2011, 07:32
Mr. Lim Mr. Lim is offline
Registered User
AKA: Mr. Lim
no team
Team Role: Leadership
 
Join Date: Jan 2004
Rookie Year: 1998
Location: Toronto, Ontario
Posts: 1,125
Mr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond repute
Re: WPI Lib Relay class - individual line control

http://www.chiefdelphi.com/forums/sh...52&postcount=5
__________________
In life, what you give, you keep. What you fail to give, you lose forever...
Reply With Quote
  #4   Spotlight this post!  
Unread 04-03-2011, 09:11
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: WPI Lib Relay class - individual line control

Quote:
Originally Posted by de_ View Post
On one line have an (12v) Red LED connected and be able to turn it on and off without effecting the state of what is on the other line of the spike. On the other line, we want to have a white 12v led that we flash in software, again, not effecting the Red LED.

The two processes will have to cooperate to achieve what you want.

Let the 4 possible states of the Spike outputs be:

Code:
   White   Red
1) OFF     OFF
2) OFF     ON
3) ON      OFF
4) ON      ON
Then, to flash the Red LED on/off while the White one is OFF, you would alternate between states 1 & 2.

But to flash the Red LED on/off while the White one is ON, you would alternate between states 3 & 4.

So the process which flashes the Red LED cannot act independently from the process which flashes the White LED, and vice-versa. The processes must share information.

One way to do this would be to have each process just set a boolean flag to indicate whether its LED should be ON or OFF, and let a third process set the proper state of the Spike each time either of these booleans changes. Rather than having the third process chew up resources polling, you could use some sort of messaging supported by the vxworks OS.


Reply With Quote
  #5   Spotlight this post!  
Unread 04-03-2011, 09:49
de_ de_ is offline
Registered User
AKA: Dave Edwards
FRC #1310 (Runnymede Robotics)
Team Role: Mentor
 
Join Date: Apr 2005
Rookie Year: 2005
Location: Toronto, Ontario
Posts: 256
de_ is a jewel in the roughde_ is a jewel in the roughde_ is a jewel in the roughde_ is a jewel in the rough
Re: WPI Lib Relay class - individual line control

Thanks everyone. That makes sense now!
Reply With Quote
  #6   Spotlight this post!  
Unread 04-03-2011, 09:54
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,572
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: WPI Lib Relay class - individual line control

Unfortunately, it looks like the Java wpilib code throws an exception if you set both on. You'd have to modify wpilib.
Reply With Quote
  #7   Spotlight this post!  
Unread 04-03-2011, 18:13
de_ de_ is offline
Registered User
AKA: Dave Edwards
FRC #1310 (Runnymede Robotics)
Team Role: Mentor
 
Join Date: Apr 2005
Rookie Year: 2005
Location: Toronto, Ontario
Posts: 256
de_ is a jewel in the roughde_ is a jewel in the roughde_ is a jewel in the roughde_ is a jewel in the rough
Re: WPI Lib Relay class - individual line control

Thought I would step back and see if there is any hardware reason I can't individual lines without effecting the other line and there isn't. Right now the class appears to require you to know the state of the other line (H/L) so you can change the the line you are interested in (ie which function code you need) as the code seems to say it will effect BOTH lines. But if this is true, this sure appears to be a software constraint.

I do wonder what would happen if I tried what I suggested in the first post.
Time to get my hands wet in Java....
Reply With Quote
  #8   Spotlight this post!  
Unread 04-03-2011, 22:43
Mr. Lim Mr. Lim is offline
Registered User
AKA: Mr. Lim
no team
Team Role: Leadership
 
Join Date: Jan 2004
Rookie Year: 1998
Location: Toronto, Ontario
Posts: 1,125
Mr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond repute
Re: WPI Lib Relay class - individual line control

Code:
int redLight = 0;
int whiteLight = 0;

void updateLights()
{
	int combinedLights;

	combinedLights = (redLight << 1) + whiteLight;

	switch (combinedLights)
	{
		case 0:
			myRelay.set(Relay.Value.kOff); // M+ and M- = 0V (Both Off)
		break;

		case 1:
			myRelay.set(Relay.Value.kForward); // M+ = 12V, M- = 0V (White Only)
		break;

		case 2:
			myRelay.set(Relay.Value.kReverse); // M+ = 0V, M- = 12V (Red Only)
		break;

		case 3:
			myRelay.set(Relay.Value.kOn); // M+ = 12V, M- = 12V (Both On)
		break;
	}

}
Something like the above will give you two independent variables representing the lights that you can change without knowing the state of the other light. Just call updateLights periodically.
__________________
In life, what you give, you keep. What you fail to give, you lose forever...
Reply With Quote
  #9   Spotlight this post!  
Unread 04-03-2011, 23:00
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,572
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: WPI Lib Relay class - individual line control

Quote:
Originally Posted by de_ View Post
The class description seems to hint that we need to declare 2 relays on the SAME channel,
- one with forward only (line 1) control
Relay m_relay1(1, Relay::KForwardOnly);
- and one with reverse only (line 2).
Relay m_relay2(1, RElay::kReverseOnly);

And then we can control each line relay individually.
This will cause an exception because relay 1 will be allocated twice.

Quote:
Originally Posted by de_ View Post
Or do you declare a single relay and change the direction to access a specific line on the fly like

Relay m_relay(1);

:
m_relay.SetDirection(Relay::kForwardOnly); // access 1 line of the spike
m_relay.Set(Relay::kOn) ; // set On or Off 1st line
m_relay.SetDirection(Relay::kReverseOnly); // access 2nd line
m_relay.Set(Relay::kOn); // set On or Off 2nd line....
:

Sorry last coding I did was on an RC
With this code, whenever the relay is set to ForwardOnly, the reverse will be off, and vice versa.
Reply With Quote
  #10   Spotlight this post!  
Unread 04-03-2011, 23:24
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: WPI Lib Relay class - individual line control

Quote:
Originally Posted by Mr. Lim View Post
Something like the above will give you two independent variables representing the lights that you can change without knowing the state of the other light. Just call updateLights periodically.
The above is essentially what I posted previously in this thread:

Quote:
One way to do this would be to have each process just set a boolean flag to indicate whether its LED should be ON or OFF, and let a third process set the proper state of the Spike
..except for the suggestion of calling the relay update task periodically.

The problem with calling the update task periodically is that in order to get good flashing "fidelity" it must be called at a fast rate even if the flashing rate of the individual LEDs is quite slow, and this wastes resources.

The fidelity of flashing LEDs is probably not critical but what if it were something which was critical? How should that be coded? You can put the Relay Update code in a separate thread and have it wait for notification that the LED states have changed, and then it updates the relay immediately and waits for another LED state change.


Reply With Quote
  #11   Spotlight this post!  
Unread 07-03-2011, 16:41
de_ de_ is offline
Registered User
AKA: Dave Edwards
FRC #1310 (Runnymede Robotics)
Team Role: Mentor
 
Join Date: Apr 2005
Rookie Year: 2005
Location: Toronto, Ontario
Posts: 256
de_ is a jewel in the roughde_ is a jewel in the roughde_ is a jewel in the roughde_ is a jewel in the rough
Re: WPI Lib Relay class - individual line control

Thanks for all the insights. We could certainly manage it in software now that it is clear. Too bad the class doesn't allow independent manipulation of each of the lines when the hardware clearly can do it. I might eventually bring that up with Brad as a possible enhancement.
Reply With Quote
  #12   Spotlight this post!  
Unread 07-03-2011, 17:39
de_ de_ is offline
Registered User
AKA: Dave Edwards
FRC #1310 (Runnymede Robotics)
Team Role: Mentor
 
Join Date: Apr 2005
Rookie Year: 2005
Location: Toronto, Ontario
Posts: 256
de_ is a jewel in the roughde_ is a jewel in the roughde_ is a jewel in the roughde_ is a jewel in the rough
Re: WPI Lib Relay class - individual line control

Quote:
Originally Posted by Ether View Post
Just to be clear: independent toggling of each of the lines is not supported by the Spike relay. "
As far as I can tell this constraint is NOT in the spike hardware. If you connect 12v to the input on the spike and put 5v on the red control line, one output line follows it and has no effect on the other line controlled by the white wire (which could be on or not). Same for the White. So the concept of Forward (one line switched high, and the other one automatically low) and Reverse is not native to the spike based on my testing. There is a tiny chance the digital side card is not electrically capable of driving just one line but not likely. More likely a historical software constraint where spikes were used for forward reverse motors and then double solenoids.

The students have implemented flashing and boy the spike relay clicking is annoying
Reply With Quote
  #13   Spotlight this post!  
Unread 07-03-2011, 18:20
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: WPI Lib Relay class - individual line control

Quote:
Originally Posted by de_ View Post
As far as I can tell this constraint is NOT in the spike hardware. If you connect 12v to the input on the spike and put 5v on the red control line, one output line follows it and has no effect on the other line controlled by the white wire (which could be on or not). Same for the White. So the concept of Forward (one line switched high, and the other one automatically low) and Reverse is not native to the spike based on my testing.
Thanks for this additional detail. I was going from memory from last year. I went back and re-checked the datasheet and it appears you are correct.

I will correct or delete my earlier post(s) to the contrary.



Last edited by Ether : 07-03-2011 at 19:14.
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 12:58.

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