Potentiometer; holding lift position and proportional control, EasyC

I’m coaching a team that has a lifting arm (4 bar arm both sides). They would like add a potentiometer to help hold the lifted position during user control mode. They are using EasyC to program. We are all new to this, I don’t know where to start with the program.

The searching I’ve done says it’s a good idea to use the joystick button to set a target value variable and then use proportional control loop to come to that height in a controlled way.

Where should a novice level programmer using EasyC begin?

To begin I would suggest something simple like setting the lift power to 15 when you aren’t controlling it. This will resist gravity and hold the arm where it is. Also I would suggest having enough rubber bands to keep the lift relatively neutral.

A P controller is nice for set heights( having different buttons you can press to go to different precoded heights) but if the goal is to hold the lift you don’t need P.

Pardon the no doubt simple question… We control the arm with a Digital Motor block set to button 6. How do we set that to give 15 power when no buttons are pressed?

The if blocks and the else blocks
set them up to be
if up button set full power up
else if down button set full power down
else 15 power up

This is what the Digital motor block is doing on the inside just without the last else statement and as we get into more advanced features we have to start moving away from the predefined blocks.

Thanks, they will give it a try.

They have a design flaw, the motor with a 12T metal gear drives a 84T HD gear, a standard shaft transfers the torque about 1.5" to a 36T HD gear bolted to the lift arm. They started making drill bits out of sq. axles.

How about using a pot. for max/min lift… maybe a limit switch to set bottom position… or just two limit switches?

I’ll see if they are up to fixing the design flaw after the next league match.

How would you go about doing this (precoded heights)? I will have an IME on my lift but i don’t have the first clue about PID stuff. I want to be able to do this in both driver control and autonomous and it must lift the lift to the required height from any other height the lift could be at.

So a P controller is really what you need most of the time. P stands for proportional.

My favorite explanation is
motor =kp*(where I want to be -where I am) If your very far away from the goal you apply full power while if your very close you apply only a little bit of power.
kP is just a unit conversion like feet to inches. It converts sensor values to motor values. The official method for finding the unit conversion is really just starting at 0 and making it bigger until it works.

So for writing EasyC code for this you have to set a variable called error which will be the IME value of the goal - current IME value. You will also probably need an variable called goal height so that different buttons can change the variable. This variable will allow you to react differently to each height with the same line of code
motor =kp*(where I want to be -where I am)

I’m not entirely sure that i understand. What type of variable do i need? i.e unsigned int or long or something

At their build session last night there was not enough programming time for the team to figure out the IF ELSE statements and put them in their program. I was able to figure it out at home last night. Now I’ll be able to guide them to the solution when they have more time. Thanks for the help.

In novice programming speak, here is what I needed to do in Easy C…

Create an “unsigned char” variable (btnUP) for the up button

Create an “unsigned char” variable (btnDWN) for the down button

I used GETJOYSTICKDIGITAL, and IF, and ELSE, and MOTOR OUTPUT blocks in the User Control WHILE loop

WHILE loop

TANK MODE or ARCADE MODE drive block here

GETJOYSTICKDIGITAL block for joystick 1, button 6(upper button), save to variable (btnUP)

GETJOYSTICKDIGITAL block for joystick 1, button 6(lower button), save to variable (btnDWN)

IF btnUP == 1

—> IF btnDWN == 1