|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Controlling motors with spike relays
I need help mapping a spike relay to the x axis of a joystick to control the rotation of a window motor. I've tried modifying the samples they give you, but to no avail. I haven't been doing this very long. Is there anything I might be overlooking? I'm not getting any errors, just no response from the motors. Is there some way to debug or diagnose my problem?
Thanks in advance! |
|
#2
|
|||||
|
|||||
|
Re: Controlling motors with spike relays
A spike relay just has four states (kOff, kOn, kForward, and kReverse IIRC) while a joystick is usually a continuous value from -1 to 1. An easy way if you're trying to do this would be an if-then-elseif-then-else block similar to this:
Code:
if (joystick_input > 0.25) then relay.set(kFORWARD); else if (joystick_input < -0.25) then relay.set(kReverse); else relay.set(kOff); |
|
#3
|
|||
|
|||
|
Re: Controlling motors with spike relays
I tried that, and it still didn't work. I have a solenoid mapped to the y-axis of the same joystick. Our builders built an excavator-like arm, and they want to be able to pick it up with the y-axis of the joystick, and rotate it with the x. The solenoid works, but the relay still doesn't. Is there any way that one is interfering with the other? Here's my TeleOp Periodic Code for the rotation motor:
Code:
double joystick2X;
joystick2X = stick2.GetX();
if (joystick2X > 0.1)
{arm_rotator.Set(Relay::kForward); }
else if (joystick2X < -0.1)
{arm_rotator.Set(Relay::kReverse); }
|
|
#4
|
|||||
|
|||||
|
Re: Controlling motors with spike relays
Your current code doesn't have any way to stop the motor; it needs a final else clause.
Other than that, I don't see the issue in this snippet of code. The next few things to check:
|
|
#5
|
|||
|
|||
|
Re: Controlling motors with spike relays
How can I verify the values? Nest a print statement somewhere, maybe?
|
|
#6
|
||||
|
||||
|
Re: Controlling motors with spike relays
cout << joystick2X << endl;
You can look at the console using rioLog in Eclipse or the console log viewer on the driver' station. (click the gear above the log window on the right and select "View Console") You could also put the value on the smart dashboard: SmartDashboard: utNumber(joystick2x)Then switch the driver station to smart dashboard. |
|
#7
|
|||
|
|||
|
Re: Controlling motors with spike relays
Is there any way I can test my code without connecting to the robot? We had to tag and bag Tuesday, but we still have some work to do.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|