# PID motor control through a motor shield

Hello everyone,

This is my first question on this platform.

I am making a prototype for a cheetah like robot, but I am running into a problem which I can’t seem to find an answer for on the internet.

I’ll try to explain myself as best as possible to avoid confusion and to avoid being an annoying newbie.

concise question:

A PID control returns an (analog) output based on an error measured by the encoder on the motor. This output should drive the motor through a Adafruit motor shield V2. But this shield doesn’t work on analogwrite commands but rather on ‘‘run(FORWARD)’’ and ‘‘setSpeed(speed)’’ commands.
How can I run this configuration with the PID control?

further information
PID control: PID_V1 (standard library)

This is how I have to adres the motor:

If I for got information to answer this question please let me know
If my question was to vague let me know and I will rephrase it

The PID library takes an input and calculates an output for you. It has no idea what that output means, nor what you are controlling.

You can constrain the library (at least in the one I've used) to keep that output in whatever range you desire.

So tell the library to constrain the output to the range of speeds you can give the motor and use it directly to set speed.

If you need to go forward and back, set it to twice that and for the lower half of the range set the motor to backwards, the upper half to forwards. You'll need to do a little math to calculate the speed setting in this case.

Going off wildbill, you will probably need to find/solve for an equation of the form “speed = m*pid_output + b” where m and b are constants…

Also, what is your control objective? This PID Tuning Guide argues that knowing the control objective is the single most important piece of information in designing and implementing an effective control strategy.

Are you using the PID to control the position of an arm? Like, what are you trying to do? If it is position control, then using servo motors might better suit the project.