Check My Autonomous Code

Hey all,

If you don’t mind, can you take a look at my autonomous code? First time really trying to do it. One part is the kinect which I am certain to work, and the other is moving to the bridge and lowering our arm to tilt the balls towards us.

As a way of switching between modes, I went with the route of using the virtual digital inputs on the driver station. In the code, you will see how I have a wire going from that array to the kinect in a case structure, and another wire from the array to the other autonomous mode in a case structure. Not sure if it is correct that way.

Any help would be appreciated!!!


Autonomous (43.2 KB)

Autonomous (43.2 KB)

First of all, make sure you reset your encoders before using them. So make a sequence before you move back to reset them to 0 and then you can see accurate results. Also your bridge arm code doesnt look correct, but I dont know how yours runs so I cant be for sure. The array part that you are using is something that I havent used before so I have no help for that.

I’ll have to add that for the encoders.
The arm code looks pretty confusing because it involves a limit switch to stop it when it hits its lowest point. That is why there is an array part and logic code in there. It has worked in teleop before.


In your attached code, you have two while loops.

The one on the top has some useless logic in there with the < 0 thing since you’re giving it values of 0.3 and 0, the value will never be less than 0. I think you’re trying to code in protection so the motor never goes in reverse, right? Or is your logic backwards and you want to use the AND to enable the motor output? I’m not sure what’s going on here. You might want to think it out on paper. Also, you should GET your references outside of the while loop to reduce CPU load.

The one on the bottom definitely won’t work the way you think it will.
I think you want your robot to move forward 5 feet, stop, and lower the bridge arm, right? Look where your while loop is located. It will execute the sequence diagram with every loop. So you’ll be telling your drive motors to move, then stop, move then stop… Another issue is where your bridge switch GET method is located, outside of the while loop. The switch will only be read once, then that’s it. Your motor output will never be controlled. And again, some useless logic. Is 1 < 0? No, you know that, so why have that in your program. Since you’re using an AND, and you have a constant FALSE being pushed in it, it will always be false, which will cause your bridge arm motor to be on the full time.

Also, good job using the Select on the second sequence. Why not use it for the motor values in the first sequence?

Don’t forget to add a small Wait timer to each while loop. Not having this will cause the CPU to spike out to 100% and hog all resources.

One last additional thing. You should re-enable the safety config for your drive motors once you’re done with autonomous. Really, it’s not needed. As long as you update your motors every 100ms, you’ll be fine.

And as Jay1986 said, make sure to reset your encoders before using them.

I changed some stuff and tried to fix what you suggested though somethings i was unsure of. Let me know how this one looks. Could you possibly comment in the physical code what I need to change?
In regards to the code on the top, that is for the kinect. Don’t worry about that because it works PERFECTLY! I’m just worried with that part in regards to the digital inputs on the driver station and how I attached that array to a case structure outside.

Autonomous (43.9 KB)

Autonomous (43.9 KB)

I didn’t really edit any of your code. You had a floating number and boolean that I deleted, and I move a few elements around to better document it.

Autonomous (45.7 KB)

Autonomous (45.7 KB)

You think the bottom code will work now? How about the virtual digital inputs?

No, the bottom code won’t work. Check out the comments I left in the code.

Just fixed some of the things you commented. I appreciate the comments you had with my logic on somethings, but I kept them the way they were because I am confident that logic works. I added timers and a while loop at the end, though I’m not too sure on that while loop. I didn’t change much in the part with the arm because I couldn’t quite understand your comment.

To give you more insight of how the arm works, I’ll describe it to the best of my ability. It starts straight up, then rotates down to I guess to be something like a 115 degree angle or whatever needed to tilt the bridge on our robot. At that lowest point, there is a limit switch to make the output 0. I am trying to make this autonomous work where when it moves to that sequence, the arm will rotate down at 1, then hit 0 when limit switch is hit. I’m definite the logic is correct as it is also used in my teleop.

Can you post your new code so I can take a look? My comment about the logic is that you have some stuff in there that doesn’t do anything, and then some of it that doesn’t do anything will cause your motor to keep running indefinitely.

Let me step you through your own logic.

We’re looking at this code right here:
Before Cleanup.PNG

Let’s clean it up to view everything a little better:
After Cleanup.PNG

Now let’s minimize the code, removing code that does nothing.
Step 1:
Minimization 1.PNG

Step 2:
Minimization 2.PNG

Step 3:
Minimization 3.PNG

Please let me know if you do or do not understand this. The reason it all cancels out to a False is because you’re using an AND gate, meaning both input X AND input Y must be True in order for the Output to be True.

Before Cleanup.PNG
After Cleanup.PNG
Minimization 1.PNG
Minimization 2.PNG
Minimization 3.PNG

Before Cleanup.PNG
After Cleanup.PNG
Minimization 1.PNG
Minimization 2.PNG
Minimization 3.PNG

Alright. I’ll change that stuff later in the day. Sort of in a rush right now, but I attached my new code from last night. (34.7 KB) (34.7 KB)

Keep me informed. I’m wanting to get it working for you.

I just looked over the code again. I left the logic you were talking about the same as I feel safer keeping it the way I’ve always done limit switches since I know it works. I’m not doubting your suggestions, I would just like to keep it the way it is.

The new code is in my previous response in the zip attachment.

Well, I’m going to tell you right now, it’s will not work. I cannot explain it any further. Maybe someone else can look at your code and help you. I’ve done all I can do.

Ryan is correct.

I highly recommend looking through Ryan’s images above, step by step to see why your logic doesn’t work the way you want it to (in addition to the fact that the code for the bottom mode isn’t in a loop).

I’m gonna say it again. The logic I have in there for my limit switch for my bridge is 100% correct. It will work exactly as I need it to work. I’ve used that code before in teleop and it has worked. I have received this bit of code straight from

Look for limit switch example. It works.

All I’m trying to do is get the robot to move the distance to the bridge using the encoders. Stop when the distance has been met, then lower the bridge arm down until the limit switch is hit.
I’m a second year programmer who has never had experience with autonomous. Last year I never even got to it as I started programming in week 4(Conversation for a different thread). I will easily admit I’m not too confident in writing the bottom code, and that is why I came here.

All I’m asking for is some help. My competition begins tomorrow, and I would love if I could get this to work.
Come on and help me out

The limit switch example on that page works great; however, it does not match your code.

I highly recommend you be ready to disable the robot when testing that code to avoid breaking the arm and that you seek out an experienced LabVIEW team and/or the CSA at your event to help you out.

The example and my code are the same…Just checked. The only difference is that the example takes the value from the joystick while my code has a constant of 1.

Is there anything I can do to get the robot to at least move the distance by encoders?

If you want, I can set it up for you to remote into my computer and work on my code in real-time rather than having to keep going back and forth on here. PM if you want to.


Check out the comment below that code. “limit switch on the forward motor direction”

What this example does is allows you to move the motor in either direction, but it tests for a special case for when the joystick is pushed forward (forward values are inverted, and give you a negative value instead of a positive). If the driver is holding the joystick forward, it will allow the motor to go up until the point where the limit switch is hit. The driver has the ability to drive the other direction (reverse) all day long, as the limit switch is disabled, and will not disable the motor value.

Q: So why is the False end of the Select connected to the joystick?
A: The False of the the select is connected to the joystick to control the motor speed.

Q: What is the default state for the Select?
A: The default state is False, where the motor value is directly connected to the joystick.

Q: What causes the Select to switch to the True case to turn the motor off?
A: Having the joystick pushed forward (where the value is less than 0) AND when the limit switch is depressed will cause the Select to switch to the True case, passing a 0 motor value, ultimately turning the motor off.

As RufflesRidge mentioned, this is only a small part of your problem, but this is the problem that will cause you to rip an appendage off of your robot via programming. Trust me, the mechanical guys will not be happy.

You need some while loops, and timers would be useful to maintain a good connection to the field.

Please get out of the mindset that your code works perfectly in teleop. In fact, I bet it does work perfectly, but you are using a joystick to control the motor instead of a constant value. Another problem is that you are probably going to turn the motor in the wrong direction if you think the code will work. You might want a -1 in there instead of a 1, which would make your code work, but why go through the extra effort of checking if a constant (constant meaning that it won’t change, ever) goes negative?

Being able to copy someone else’s code is one thing but being able to actually understand what the code is doing is another.

You have multiple issues, and I haven’t seen one addressed since last night. I’d be happy to help you out if you want, but you’ll have to just trust me on everything that I say. Send me a PM.