|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
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()); Code:
Relay->Set(Thirdstick.GetY()); |
|
#2
|
|||||
|
|||||
|
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.
|
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
|||||
|
|||||
|
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? |
|
#5
|
||||
|
||||
|
Re: RELAY!!
Quote:
|
|
#6
|
||||
|
||||
|
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)
{
}
Code:
typedef enum {kOff, kOn, kForward, kReverse} Value;
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:
Last edited by Dave Scheck : 03-11-2010 at 16:13. |
|
#7
|
|||||
|
|||||
|
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. |
|
#8
|
||||
|
||||
|
Re: RELAY!!
Ok, now I understand, Thanks alot!!
|
|
#9
|
||||
|
||||
|
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 |
|
#10
|
||||
|
||||
|
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;
}
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); |
|
#11
|
||||
|
||||
|
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);
|
|
#12
|
||||
|
||||
|
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:
Last edited by Dave Scheck : 05-11-2010 at 13:02. |
|
#13
|
|||
|
|||
|
Re: RELAY!!
This is the source of your error. You presumably (since you didn't actually show it) have a RobotDrive member called myRobot which uses PWM channels 1 and 2. You then create 2 Victors which use PWM channels 1 and 2. These 2 channels are already in use by your robot drive object.
|
|
#14
|
||||
|
||||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |