Really stuck - Proportionally control 2 motors from 1 data range

Heres the problem, I am trying to get 2 dc motors to work together to position a moving object in between them. The object moves along a fixed axis with values from say 0 to 159 (Max left and max right respectively). What I am trying to do is the following:

Say the object is in furthest position 0. Left motor runs in reverse, right in forward until the object approaches the center (80) where they slow until stopping. Should the object move along this axis before center is achieved , the motors adjust accordingly. It should be noted that the object does not move very quickly. I have tried looking at various different PID examples but getting something to control 2 objects from 1 input isnt really covered.

Many thanks

So ? What's your question ?

Can anyone help me with how to do this?

"Really stuck " isn't going to get us to do your homework. If you want to solve the problem then stop asking us to do it for your and start researching it. This is not HomeworkRUS.
Use Google with the word "arduino " in front of whatever you are trying to research .

I am trying to get 2 dc motors to work together to position a moving object in between them.

I don't even know what that means. Stop being cryptic and tell us what the object is. You haven't told us anything about the= hardware you are using to drive these motors. If you want help, you have to do your part. Post your code and any documentation or links pertaining to whatever you are using to drive the motors.

The object moves along a fixed axis with values from say 0 to 159 (Max left and max right respectively).

Learn how to flap your wings (move the motors) before trying to fly (position the object)

What I am trying to do is the following:

Say the object is in furthest position 0. Left motor runs in reverse, right in forward until the object approaches the center (80) where they slow until stopping. Should the object move along this axis before center is achieved , the motors adjust accordingly. It should be noted that the object does not move very quickly. I have tried looking at various different PID examples but getting something to control 2 objects from 1 input isnt really covered. [/quote]

This is stupid. If you're not going to tell us what the object is do it yourself.

GreyE30:
Can anyone help me with how to do this?

If you have a circuit diagram it would be a great help. You can just draw it by hand if you need to. Also, pictures of your complete setup would be really handy if you have already assembled your sketch.

I've seen this kind of setup before and the trick is to run both DC motors so that they push against each other, not one pushing and the other pulling like you said. If it worked the way you are describing then you would only need one motor.

By having two motors pushing against each other you can have them hold at a set position so the moving object will be locked in place when not moving to another position.

(M1)---------F1>>>>|<<<<F2------------------(M2)

Steady state: Forces F1=F2 vertical bar not moving.

Looking at this simple diagram you can see that if motor M1 is pushing with equal force against motor M2 then the vertical bar will hold its position because force F1 equals force F2. To move the vertical bar to the right you don't reverse the direction of motor M2 you just reduce its force on the center bar.

Moving Slowly

(M1)-------------F1>>>>|<<<F2---------------(M2)

Moving state: 
Force F1 is slightly greater than F2 : Vertical bar moving slowly to the right.

Moving Fast

(M1)--------------F1>>>>|<F2-----------------(M2)

Moving state: 
Force F1 is much greater than F2 : Vertical bar moving quickly to the right.

This is where I'm not so sure of the solution but if each motor has it own PID controller and you use the position error of the vertical bar as the input to each PID then it should drive the vertical bar to the new position. This requires that the position error be inverted for each motor PID controller.

If, for example, you want to move the vertical bar to the half-way point but it is currently 1/4 of the distance from motor M1 and 3/4 of the distance from motor M2 then the position error for the M1 PID would be -1/4 and the position error for the M2 PID would be +1/4.

mstanley - Thank you this is great and exactly what I was hoping for. Your thoughts on two motors pushing (albeit one less than the other) is easier to get my head around than what I had thought, I was trying to work it out with motors in reverse depending on position but I think that was where I was confusing PID input.

Essentially I am using an Adafruit motor shield to control the motors on my fixed point and the design looks something like below:

0 <------------------------------------------------------|--------------------------------------------> 160 (Fixed axis IR light)

Left Motor( O )Right Motor

So in explanation, as the IR light moves along its fixed axis the stationary object (represented by (O) ) turns to face it so the light is always the center of its "field of vision". I found a helpful explanation of PID control linked below but have been unable to make anything work.

About half way down, pseudo code post by scrat:

http://forum.arduino.cc/index.php?topic=45169.0

Why do you need the complexity of two motors?

What would be wrong with one motor (perhaps a stepper motor) and a piece of string (well, a belt, perhaps)?

...R

I may need the focus point to be able to move forward and back at some point and wanted to build in some redundancy.

Imagine the IR light moves along its wall (X) axis stopping at predetermined points and at that given point the central object will move forward to engage or action with objects on the wall before returning to its central position. Initially just following the IR would be a start but as I mentioned I am finding PID motor control (or this level of motor control) beyond my programming ability. I have tried to use various different algorithms but to no avail.

If you need to position an object accurately in one dimension, then a linear actuator is a good choice. Example using a stepping motor: Pololu - Stepper Motor with 28cm Lead Screw: Bipolar, 200 Steps/Rev, 42×38mm, 2.8V, 1.7 A/Phase

You can also make linear actuators quite easily using a motor (either a brushed DC motor or a stepping motor) driving a piece of threaded rod with a nut.

Thats neat but doesnt really achieve the solution I need. I could implement 2 of these in a cross formation but would still need to angle the focus point to point towards the IR. Does that make sense?

Why don't you use the Map function to Map the distance of the object to the speed of the motor toward the object so the further away it is from the object the more it drives toward it and the closer it gets the slower it goes. Use an IF or a CASE to change direction if the object gets to close and flags to keep track of whether the object is approaching or receding. The decision code for direction can use these flags to set direction.

I would use a signed variable to represent the distance between the desired target position, and the actual target position. So for example a positive value could mean that the device is too far to the right, and negative that it is too far to the left.

From this signed value you will need to decide what action the motors need to take. Again I would represent this by a signed value with 0 meaning do nothing (no power to either motor), a positive value meaning apply power in one direction, a negative value meaning apply power in the other direction.

To actually implement that action you would test the sign of the value to decide which direction to move each motor, and the magnitude to decide how much power to apply.

The missing link is how you get from the (signed) positional error to the (signed) required action. The simplest approach would be to just make the action be proportional to the error. If that results in a system which is too slow to respond or subject to overshoots or is subject to oscillations then you might need something more sophisticated such as a PID control algorithm. Try the simple stuff first though.

GreyE30:
Thats neat but doesnt really achieve the solution I need.

Why?

Either you are over complicating the project or there is something you are not telling us.

...R