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!

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:

if (joystick_input > 0.25)
then relay.set(kFORWARD);
else if (joystick_input < -0.25)
then relay.set(kReverse);
else relay.set(kOff);

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:

     double joystick2X;
     joystick2X = stick2.GetX();
     if (joystick2X > 0.1)
        {arm_rotator.Set(Relay::kForward); }
     else if (joystick2X < -0.1)
        {arm_rotator.Set(Relay::kReverse); }   

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:

  • Did you verify that you’re getting the values you expect from the GetX()?

  • Is the spike control wire plugged into a relay port (not a PWM or DIO or analog port)?

  • Is relay of the Relay class and initialized to use the same port as the wiring is connected to?

  • Are the wires in the right orientation (both power and control), and are you getting a good connection?

  • Is the fuse on the spike blown?

How can I verify the values? Nest a print statement somewhere, maybe?

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:
Then switch the driver station to smart dashboard.

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.