Quick question about preset heights

Hello guys,

I was working on some code today to support some preset heights and I was wondering how I would be able to do it. I’m just learning PID and how I can use it. We have a potentiometer installed. I was wondering how I could select which case to run, because it wouldn’t necessarily be a true/false type of statement (or would it). It would be if button1 = pressed = go here. Maybe i’m just fried from the series of tests I had today, but I really can’t figure it out.

We are doing a similar thing with our arm, including the use of PID loop controls for it.

The way we did it in simplest terms is that we found the range of readings back from the potentiometer and used positions based on that range. For example, if 0 from the potentiometer meant that the arm was at the floor and 180 meant it had rotated to a level for the top row, then our range would be 180. The arm would always be maintaining the current position and the joystick input axis would only increment or decrement the position that the arm would be maintaining. For example, if the arm was currently at a position of 10, just above the floor, and I pulled the joystick to the right to raise the arm, then the goal position would increase and this would change the setpoint of the PID loop causing the arm to change it’s position. It would also be necessary for the setpoint to not change when the joystick was neutral in order for buttons to be added in.

With the input from the buttons for going to preset positions, it would be a simple addition into the program where the activation of a certain button changes the setpoint to a different value, say 90 for the trigger being pressed. This would then cause the PID loop to correct the arm to go to the new setpoint.

The reason why it is important for the motor output to be directly controlled by the joystick input is because this would possibly conflict with the PID loop control. If the trigger had been pressed and the setpoint was 90 and the arm was currently at 10 but the joystick was neutral giving an output of 0, then with the joystick feeding directly into the motor and bypassing the PID loop, you would get jerky behavior from the motor unless you had the PID loop shut out. The joystick input can still be fed directly to the motor output if you have a way of toggling between PID loop control of the arm and joystick control of the arm. However, this seemed complicated and not quite user-friendly enough for our team. We ended up making the joystick affect the setpoint of the PID loop control and let the PID loop take over movement of the arm motor. This allowed us to hit a button to change the setpoint and have the arm start moving to that setpoint while the driver still had joystick control to modify the setpoint value on the run.

I hope this helps. Also, if you think that it is just your code that is having problems, post it on here so we can look it over.