Programming help needed! Using motors+ pots for large "Mega Servo"

We have a robot built using an arm with a gear drive, with a potentiometer on the top shaft. What I need to do is write/get some code which will allow me to basically use it like a giant servo. The way the logic works in my head is this: (translate this into C somehow? I’m new to programming)

Read stick position.
Determine arm position.
read difference between the two
move motor to make stick and arm position equal
if arm moves and stick doesn’t, fight back and correct
repeat

And have a limited range of movement, so top of stick= max range of travel for the arm. I could do this with a limit switch but it likes to bounce on and off of the switch.

Hopefully someone can figure out what I’m trying to do and help us. THe comp is on saturday and we need to figure this out. I just have zero programming experience aside from setting it up as essentially an RC vehicle and doing time based autonomous.

What you need to do is get an Intergraded Motor Encoder for one of your motors and use the PID Function. This would make what you need to do very easy we even have a sample “PID Control with Joystick Digital Buttons”, just make sure the axel is grounded to the frame and you drag something metal.

Otherwise your going to need to learn how to program in C at least at an basic level if/else, variables and some creativity. If you check in the samples there is a project called “PID Interrupt Service Routine” you need to merge that with the other sample I mentioned “PID Control with Joystick Digital Buttons”. The First sample has doing the P in PID with a POT and the Second sample has the joystick button press thing your looking for.

sounds good, I’ll give it a shot.
I have experience flying multicopters, so the PID loop concept is familiar to me.
I’ll let you know how it works :slight_smile:

Best of luck.