Moving robot in straight line

straight_line.zip (1992Bytes)
New_Text_Document_0.txt (7688Bytes)
New_Code.txt (6808Bytes)
OB1.zip (3089Bytes)

hi,

I have been working on building a differential wheeled robot with two motors and two encoders (one for each wheel). As expected, one wheel runs significantly faster then the other even though the PWM values are the same so I used PID class to correct error. I don't know if  I wrote it correctly so I'd appreciate it if someone could look over it and check for mistakes or ways I can improve it. I have been adjusting the P, I and D but the robot still drift to the right.  My code is below in the attachments and might be confusing so if you need clarification I'll try and quickly reply. 

 

thanks a lot 

-----------------------------------------------------------------------------------

-----------------------------------------------------------------------------------

-----------------------------------------------------------------------------------

-----------------------------------------------------------------------------------

-----------------------------------------------------------------------------------

--------------------------------------Update-----------------------------------

dears all

I re-configure my robot pins into OddBot code using "Port L" but when runing Arduino the motors don't spin and enoders don't count. Any could help please .

codes "OB1.zip"in the attachement 

thanks

 

I’m sorry, but could you put
I’m sorry, but could you put your code into formatted text files with the .txt extension. I can’t read them as you have them.

As I understand it, you would set yourself a target speed in pulses per second (or some other convenient length of time) with both motors trying to get there.

I would first adjust the P (proportional) parameter until both motors get to the target speed as soon as possible.

Then I’d adjust the I (Integral) parameter to keep the overshoot as low as possible.

Then I’d adjust the D (differential) parameter to keep the vibrations in the final speed as short as possible as short as possible.

If any of these parameters are close to zero, try setting it to zero to see if you can remove that part of the equation.

One thing is that PID controllers make heavy use of floating point math, which the Arduino isn’t great at. You may have a more powerful controller, in which case, “never mind.” Personally I like the Teensy 3.1 for working on control equations until I can simplify them and put them on something smaller or stranger. I have a python controller I want to take for a spin someday.

I’d suggest seaching this site for “PID tutorial”. If not, try googling this.

thanks a lot Dangerous

thanks a lot Dangerous Thing

Actually I thinks that PID parameters need to tuned correctly, I don’t have that enough experiment in tuned that three parameters and how to adjust them together, so could you give more explanation about three point below you mentioned :

[ I would first adjust the P (proportional) parameter until both motors get to the target speed as soon as possible.

Then I’d adjust the I (Integral) parameter to keep the overshoot as low as possible.

 

Then I’d adjust the D (differential) parameter to keep the vibrations in the final speed as short as possible as short as possible ]

 

 

Hint : I added TXT file.

**Hi,

When adjusting, start**
Hi,

When adjusting, start with all parameters set to 0. Then adjust as you said.

The end result should be a mapping between motor speed and PWM. There should be an algorithm that handles both motors simultaneously. There is one for a balancing robot, but I haven’t experimented with that enough. I’m about to build my prototype balancing robot, Bilbo, assuming my 3d printer will actually work when I get back and can build the right parts. :slight_smile:

I noticed the text file and will give it a look shortly.