Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Controlling motors with spike relays (http://www.chiefdelphi.com/forums/showthread.php?t=144721)

FRC3220 02-25-2016 02:38 AM

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!

GeeTwo 02-25-2016 06:19 AM

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);


FRC3220 02-25-2016 12:52 PM

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); }


GeeTwo 02-25-2016 01:08 PM

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:
  • 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?

FRC3220 02-25-2016 01:50 PM

Re: Controlling motors with spike relays
 
How can I verify the values? Nest a print statement somewhere, maybe?

SuperBK 02-25-2016 02:46 PM

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

FRC3220 02-25-2016 10:33 PM

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.


All times are GMT -5. The time now is 10:26 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi