Go to Post Inspiration and recognition does not equal "advanced shop class". What's better for your team is not better for all teams. Remember that. - DonRotolo [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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-11-2010, 10:58
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
RELAY!!

is it possible to set a relay to get the Y-axis on a joystick? I have tried

Code:
Relay->Set(Thirdstick.kYAxis());

Relay->Set(Thirdstick.kDefaultYAxis());
and also

Code:
Relay->Set(Thirdstick.GetY());
none of them worked
Reply With Quote
  #2   Spotlight this post!  
Unread 03-11-2010, 11:06
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: RELAY!!

A joystick axis gives a value from -1 to +1. A relay is either on or off. Can you describe in detail what you're trying to do? Right now, I'm as confused as the compiler is about the intended behavior.
Reply With Quote
  #3   Spotlight this post!  
Unread 03-11-2010, 11:19
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
Re: RELAY!!

the relay is used to control a motor on our arm. For the motor to go forward or backward I had set a button for it and used an "else" statement which would keep it off. Now I would like to use the joystick to make the motor go forward or backward.
Reply With Quote
  #4   Spotlight this post!  
Unread 03-11-2010, 12:16
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: RELAY!!

So you want the relay to be set "forward" if the joystick is pushed forward, you want the relay to be set "reverse" if the joystick is pulled backward, and you want the relay to be set "off" if the joystick is left at center?

The joystick Y-axis value will be negative if you push it forward. The value will be positive if you pull it backward. The value will be zero if you leave it at center. Does that help send you in the right direction?
Reply With Quote
  #5   Spotlight this post!  
Unread 03-11-2010, 15:17
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
Re: RELAY!!

Quote:
Originally Posted by Alan Anderson View Post
So you want the relay to be set "forward" if the joystick is pushed forward, you want the relay to be set "reverse" if the joystick is pulled backward, and you want the relay to be set "off" if the joystick is left at center?

The joystick Y-axis value will be negative if you push it forward. The value will be positive if you pull it backward. The value will be zero if you leave it at center. Does that help send you in the right direction?
yes, Inderstand that concept, but the thing is, for victors and jaguars we would use Joystick.GetY. I dont understand what to put for a relay, I have tried all of those listed in the first post
Reply With Quote
  #6   Spotlight this post!  
Unread 03-11-2010, 15:51
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!!

The code you have definitely won't work. It doesn't look like you're creating instances of the classes. Assuming that I'm misunderstanding your code, your problem comes in with what Relay::Set expects as input vs what Victor::Set or Jaguar::Set expect. Compare the prototypes that are found in WPILib
Code:
void Jaguar::Set(float speed)
{
}

void Victor::Set(float speed)
{
}

void Relay::Set(Relay::Value value)
{
}
See how Victor and Jaguar take in a float? That happens to be what Joystick::GetY is returning. In the case of Relay::Set, it expects a Value type. That can be found in Relay.h as
Code:
typedef enum {kOff, kOn, kForward, kReverse} Value;
So, in order to call Relay::Set, you need to pass in a Relay::kOff, Relay::kOn, Relay::kForward, or Relay::kReverse (look at Relay.h for a description of what they each mean)

In order to do what you want to do, you'll need some logic. Here's an example for using a forward and reverse threshold (I'm using .5 as my threshold in either direction) to set the state of the relay. Don't forget to turn it off if the stick is between the thresholds.

Spoiler for For Jared:
Code:
#define FORWARD_THRESH  .5
#define REV_THRESH  -.5
...
Relay r1(1);
Joystick j1(1);
...
int inSpeed = j1.GetY();
Relay::Value outSpeed;

if(inSpeed > FORWARD_THRESH)
{
    outSpeed = Relay::kForward;
}
else if(inSpeed < REV_THRESH)
{
    outSpeed = Relay::kReverse;
}
else
{
    outSpeed = Relay::kOff;
}

r1.Set(outSpeed);

Last edited by Dave Scheck : 03-11-2010 at 16:13.
Reply With Quote
  #7   Spotlight this post!  
Unread 03-11-2010, 15:54
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,080
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: RELAY!!

The joystick axes output a double between -1 and 1. Victors and Jaguars conveniently accept a double value between -1 and 1 as an input.

Relays can be set to kForward, kReverse, or kOff (or kOn, but that doesn't seem to matter here).

So you need to write some code that translates from [-1, 1] to [kForward, kReverse, kOff].

All you need to do is write an if...else statement that checks if the joystick axis is pushed forward, backwards, or is in the center. In other words, is the axis <0, >0, or ==0 (note that you might not want to check if it is exactly zero, since the tiniest bit of movement would make your motor move - you probably want a threshold so that if the stick is within, say, .1 of 0, just call it zero).

EDIT: Aww, Dave - he was getting so close!

Last edited by Jared Russell : 03-11-2010 at 15:56.
Reply With Quote
  #8   Spotlight this post!  
Unread 03-11-2010, 16:12
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
Re: RELAY!!

Ok, now I understand, Thanks alot!!
Reply With Quote
  #9   Spotlight this post!  
Unread 03-11-2010, 16:14
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!!

Sorry Jared

I went back and put the code in a spoiler tag if krudeboy wants to go through the thinking exercise.

EDIT: He just posted which means he probably saw it before the spoiler tag was in. Oh well. It can still be a thinking exercise for those new to programming
Reply With Quote
  #10   Spotlight this post!  
Unread 03-11-2010, 16:19
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
Re: RELAY!!

One Problem, Does anyone know what this error is:

[Qoute]
Fatal error "Attempting to resuse an allocated resource" in Allocate() in C:/WindRiver/workspace/WPILib/Resource.cpp at line 76
[/quote]

I looked at line 76 of the code, all I have there is a "wait" in autonomous
Reply With Quote
  #11   Spotlight this post!  
Unread 03-11-2010, 16:41
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!!

The line 76 is in C:/WindRiver/workspace/WPILib/Resource.cpp not in your code.

That line is checking to see if the index has already been allocated.
Code:
if ( m_isAllocated[index] )
{
    wpi_fatal(ResourceAlreadyAllocated);
    return 0;
}
Looking further up to see where it is used, Relay uses is it in InitRelay. So this tells me that you have two relay objects that are set up on the same slot.

Check where you declare your variables. You'll get that error if you're trying to create two relays on the same slot. Make sure you don't have something like:

Relay r1(1);
Relay r2(1);
Reply With Quote
  #12   Spotlight this post!  
Unread 05-11-2010, 10:32
krudeboy51's Avatar
krudeboy51 krudeboy51 is offline
Only Programmer
AKA: kory
FRC #0369 (369)
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2010
Location: brooklyn
Posts: 151
krudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of lightkrudeboy51 is a glorious beacon of light
Send a message via AIM to krudeboy51
Re: RELAY!!

I only have one relay:

Code:
myRobot(1, 2),
		Leftstick(1),
		Rightstick(2),
		Thirdstick(3)
			
	{
		LGC = new Servo(9);
		RGC = new Servo(10);
		pair1 = new Victor(1);
		pair2 = new Victor(2);
		CamKicker = new Victor(6);
		Winch = new Victor(7);
		Dribbler = new Victor(5);
		ArmRelease = new Relay(1);
		Zone1 = new DigitalInput(1);
		Zone2 = new DigitalInput(2);
		Zone3 = new DigitalInput(3);
		CamSwitch = new DigitalInput(7);
Reply With Quote
  #13   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
  #14   Spotlight this post!  
Unread 05-11-2010, 12:44
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: RELAY!!

Quote:
Originally Posted by Dave Scheck View Post
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.
That's not correct Dave. The digital modules have 4 distinct resource types... PWM channels, Relay Channels, an I2C bus, and Digital I/O channels. Because they are separate resources, you will not get conflicts from using the same channel "number" in a different set of channels. This is best illustrated by looking at the digital sidecar itself and witnessing different pins for each of those channel types.

Quote:
Originally Posted by Dave Scheck View Post
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);
This has no effect. The default digital module is 4, so explicitly specifying 4 is not any different than not specifying it. In either case, you are allocating the same channel. The reason this works is because the relay channels are separate from the digital I/O channels.
Reply With Quote
  #15   Spotlight this post!  
Unread 05-11-2010, 13:00
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: RELAY!!

What do the numbers in this line represent?
Code:
myRobot(1, 2),
How does that interact with these two lines?
Code:
		pair1 = new Victor(1);
		pair2 = new Victor(2);
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Relay Code dnrobotics11 C/C++ 3 08-03-2010 23:03
Relay Issues Stealth NI LabVIEW 4 16-02-2010 00:24
Relay AllocationException EHaskins Java 3 14-02-2010 15:30
Relay Robopanda6 Java 5 07-02-2010 01:08
C++ Relay Code? Happyisgood C/C++ 10 16-07-2009 14:54


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

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