Thread: RELAY!!
View Single Post
  #1   Spotlight this post!  
Unread 05-11-2010, 11:16
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: RELAY!!

I went back and added the spoiler tag to retain my original post but to hide it from the casual reader. As Joe said below, my analysis is incorrect. I'll leave the post here for reference.

Spoiler for Hiding bad info:
You're getting burned by the way you're building up Relay and DigitalInput. The code you have is syntactically valid and each line will run on its own, however, there is some code inside WPILib that is hurting you when they interact.

WPILIb provides the following constructors for Relay and DigitalInput
Code:
Relay(UINT32 channel, Direction direction = kBothDirections);
Relay(UINT32 slot, UINT32 channel, Direction direction = kBothDirections);

explicit DigitalInput(UINT32 channel);
DigitalInput(UINT32 slot, UINT32 channel);
With the way that you're calling those, you are only passing in a channel to the construtor, so you're calling the first construtor in for each class. Herein lies the problem.

The Relay constructor is going to call InitRelay with GetDefaultDigitalModule() as the slot number.

The DigitalInput constructor is going to call InitDigitalInput with GetDefaultDigitalModule() as the slot number.

In each of those functions, a Resource is allocated using the slot number passed in (in both cases the output of GetDefaultDigitalModule()) and a channel number (the channel number from your constructor). Inside Resource::Allocate is the code that I referenced in my previous post. You're telling it to create two Resources using the same slot and channel combination. It's at this point that the assertion fails and things break.

Specifically, it's these two lines
Code:
ArmRelease = new Relay(1);
Zone1 = new DigitalInput(1);
These both allocate Resources using the default slot with channel 1.

To fix this, you need to use the other constructor for these objects and specifically call out the slot number. I forget what the slot numbers are, but I found this in our 2009 code.

Code:
ap_rlyElevatorR  = new Relay(1);
ap_elevatorLimitRightTop = new DigitalInput(4, 1);
So that code creates the right elevator Relay on the default slot, channel 1 and creates the right top elevator limit switch Digital input on slot 4, channel 1.

Change up your constructors and you should be ok

Last edited by Dave Scheck : 05-11-2010 at 13:02.
Reply With Quote