Ok, not a rookie, but for sure no expert. Is there any way to access limit switches that are set for arms in Teleop during Autonomous? We have limit switches that work during Teleop perfectly and would like to move the same arms to a position and have them stop. I thought…limit switch in auto…hmmm. I tried and the switches didn’t stop the motor. Can this be done? Maybe I just made a mistake in creating the Auto program. Any help would be great.


1 Like

Are you opening the switches in begin?

If so, they should be accessible in auto. Put the sensor “get” with the correct refnum name in the same loop that you’re using to run your auto mode.

1 Like

Something that might be tripping you up, in the Autonomous VI you have to add while loops yourself where they make since.

If you post a screenshot of your code (ideally showing all cases of case structures) we can help you better.

When you create a while loop in Autonomous, you should put a 10 or 20 millisecond wait function in it so the loop doesn’t use up all the roboRIO’s CPU.

Just to be clear, DON’T use a wait function in the TeleOp VI.

This definitely can be done. In fact, your robot can and should work functionally the same in auto and teleop, and it’s merely what is causing the inputs (controllers verses prepared instructions) that is different.

I highly suggest uploading your code to github so we can view it and help you based on your current code structure. The way you are describing your problem leaves many different avenues based on what your code currently looks like. I describe the process to creating a github repo in this thread.

In periodic tasks query your limit switches and set Robot Global Data Variables to their values.

Then in Auto or Teleop just look at the RGD variables and not directly at the limit switches.

AfterTen, I personally wouldn’t recommend that architecture. Not that it wouldn’t work, but I don’t see the added benefit; and I see more complexity. I’m curious if there’s a reason you would do it that way though. (Maybe @mention me in another thread or PM, not that I’ll be able to respond quickly). :slightly_smiling_face:

Edit: And of course your welcome to opinions too.

1 Like

I’m not sure why you see more complexity. We do the same. We have a single loop that polls our sensors and saves the results to globals. This allows you to use them in both teleop or auto, and doesn’t require you to put gets in both to use the sensors. It’s quite clean and simple. It also has the benefit that your sensors are polling in disabled so you can feed them to your dashboard and probe them for troubleshooting, all without enabling the robot.

Pretty much this.
We also do this for many of our mechanisms that operate by state machine.
(I haven’t bothered to seriously look into Command And Control - I should)
For instance our intake, not surprisingly, goes up and down.
There is a global variable that we set to the desired state of the intake.
Then the VI that actually controls the intake runs in periodic tasks and just monitors the global variable.
Set the variable to “UP” and the intake goes up. “Down” goes down.
Now in auto we just set it when we need to and same for TeleOp. Hitting buttons on control panel just sets a global variable.
As usual with programming there multiple ways to go about it and the best way, barring an objective argument against it like introducing too much lag, is just the way it makes more sense to you.

We do it very similar to you. VERY little code goes in teleop - just getting the operator joysticks etc and puttings those into globals.

We actually use those same globals in auto to drive the robot. Our auto sends outputs to the joystick globals.

This prevents potential race conditions. I limit the team members to only ever using a single motor set for each motor, and a single global to control it.

OK, tried to add to github.

Thanks for the help!!!

So your periodic task would look something like the attached image. “Bottom Limit Switch” comes from a Boolean you put into “Robot Global”

Then you can just get the value in Teleop or Autonomous
Here’s a snippet of what it would look like in Teleop

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.