Talons fighting with Solenoid for Joystick

Ok, I got my tank mode working, but then my solenoid won’t work.

I think they are fighting for a joystick control or something. Here are the 2 parts of the code in my Begin that seem to be at odds:

(I think I am putting way too much in Begin for my solenoid, I need to break it up don’t I? Can anyone show me how to do this?)

Here is what I thought I needed in Teleop, but it seems to work fine without it, as long as I have all that code in Begin.


And finally, here is what my talons look like in Begin. They work but the joystick won’t control them when I get my solenoid working.

Alright, a few things here.

  1. You really shouldn’t be looping anything in begin. Joystick values should be read in teleop, or specifically for this season, autonomous. Actuators, like motors and solenoids, can be set in those locations as well. Instead of trying to move actuators in begin, use a RefNum Set to set a reference to that actuator so you can call it anywhere.

  2. You shouldn’t close references anywhere outside of Finish, as they will require a code restart to be used again. (And even then, you don’t really need to close things in general.)

Taking both of those into account, the only solenoid code you need in begin is this:Solenoid%20begin
(This is a VI Snipppet, by the way. You can drag this image directly into your Begin.)

  1. After that your solenoid code in teleop is fine as written and should run. Your drive code should also run, assuming it’s in the teleop vi; I imagine the reason it’s not right now is because your solenoid loop in begin is preventing your code from reaching teleop (begin needs to finish executing before any other vi can start; this is why you shouldn’t put a loop in there).

So, just to recap the general flow of the robot code:

-You should be initializing everything in Begin (joysticks, sensors, motors, whatever) and creating the appropriate reference (solenoids need a solenoid set ref, motors need a motor set ref, etc.)

-You then use ref gets in Autonomous (for the sandstorm) or Teleop (for regular control) to reference those objects and actually use them. This is where you’ll read inputs, set outputs, etc.

-Periodic tasks (which I haven’t mentioned yet) can be used for anything that you want to have consistent behavior across Autonomous, Teleop, and Disabled. My team generally reads sensor values here and writes them to variables, as well as publish any diagnostic data/feedback we want to the dashboard.

And that’s about it, I think. Any questions, feel free to ask.

1 Like

I dropped the snippet into begin and kept my teleop the same. The solenoid is still not working, though I can tell you are getting me on the right track!

So my begin looks like this:


and my teleop looks like this:


Is there something else I need? You said something about RefNum Set, is that part of what I have done, or do I still need to doit. If I still need to, can you send me a diagram of how it looks and whether I should put it in Teleop or Begin? Thanks!


That looks like good code. Bring up context help by either clicking the yellow question mark in the upper right or pressing ctrl + H. Then hover over anything in LabVIEW and it will tell you what it is. In particular the VI on the right in Begin is the RefNum Registry Set so that is good.

Questions: are your solenoids 12 or 24 volts and do you have the the jumper on the PCM set right? Is it a double or single solenoid? Set that in Begin. Do the LEDS on the PCM next to the wire pairs that you want light up?

24 volts and yes the jumper is on right. Double solenoid which matches the code. The LEDs light up when I had the bad code that kicked the motors off, but they don’t even light up now.

Does this part of the code need to be in the Teleop version?

This looks like the part which end the while loop. I don’t see a while loop in your new teleop so there is no need for it.

As a general rule, if you’re adding a while loop to teleop, something isn’t being done correctly. This will stop your robot from responding to any commands until the loop is finished. Is that the behavior you want?

I think BogBots is in the middle of breaking the code up into sections for Begin, TeleOp, and Finish. Is that right @BogBots? No you don’t need that section in the TeleOp version. You should also remove the Wait 100 ms function (because TeleOp is called every 20 ms which is the speed the loop should run at) and remove the Driver Station Start Comm VI (because it is already in Robot Main).

Yes, we are doing that, but we didn’t do Finish because we thought that was unnecessary. What should the finish look like?

Ok, now we added Finish:

It is still not working. Drive motors work, but no Solenoid! Should I put the drive motors in Finish also? Thanks for your help, we feel like we are close!

Your drive motors are already in finish by default. Finish also shouldn’t have any effect on teleop/why your solenoids aren’t working.

All the little bits you’ve shown look fine. Are you sure you want joystick 0, button 2? Note that buttons in Labview start at 0, so this will be the button marked 3/the third one shown in the driver station. Is the driver station console showing any errors?

If none of that solves it, a good debugging step here would also be to click run on Main.vi instead of building/running as startup. This let’s you probe data in real time, so you can, for example, click on the boolean wire going to your selector and make sure it’s actually registering when you click the button.

Oh yes, I see the driver motors there in finish now, duh. Maybe do I have to open a compressor in begin? I’m trying to run the solenoids with a cylinder and compressor.

I knew about the numbering system for the joystick, and I do want the number two in that spot.

No you don’t need to open a compressor. Opening a solenoid starts the compressor on PCM 0.

Finish is just good practice.

There are red LEDs on the PCM for each channel. Are those lighting up when you expect them to? Since you are using a double solenoid, you should always set it to either Forward or Reverse which means 1 of the PCM channels should always be on.

What does your code in Begin and TeleOp look like now?

Does the driver station show that there are any errors when you run the code?


1 Like

The compressor would only be an issue if you’re not getting pressure, which should be easy to diagnose. If you thought there might have been some weird code thing preventing a solenoid from firing without a compressor, that is not the case.

The code you’ve posted, if dropped into a default begin and teleop, should function if everything is wired and connected correctly. This means one of two things is happening:

  1. There is a physical issue on the robot (wiring, pressure, etc.)
  2. Another piece of code is at conflict with what you’ve posted

Given that you’ve successfully controlled the solenoid from begin, it does not seem likely to be 1, but it’s worth a sanity check. If I were in your place, I’d verify the following two things:

  1. Go into the USB tab of the driverstation and verify that when you pressed the desired button, the 3rd button of the device in slot 0 lights up, as shown here:

    (note that it goes down columns, not across rows)

  2. If that works, as Jonathan suggested above, enable the robot in teleop and verify that the LEDs on the PCM are responding properly. The LED for channel 0 should be on when the button is held, and the LED for channel 1 should be on when the button is up.

If both of those are happening, then your code is working correctly and your issue is physical; either the wiring to the solenoids is faulty or you don’t have sufficient pressure getting to them.

If the first step is working as expected but not the second, there’s either some sort of conflict in your code, or a wiring issue with your PCM (specifically the CAN bus or power). A post of your entire begin, teleop, and maybe periodic tasks should be enough for us to help you find the issue.

If the first step is not working as expected, you have a simple mapping issue; you’re pressing a button other than the one the code is looking for.