How to make the robot to move in straight line using encoders

i m amateur to programming …
doing project on “path follower robot” in which i have to give path virtually that part is done
robot is also going on path but it is not going straight so it is distracting from path….

my robot is pololu 3pi+.

Hello.

It is normal for brushed DC motors to have some unit-to-unit variation in speed, so a differential drive robot like the 3pi+ will not keep a straight path unless you account for it properly. You might be able to calibrate for it by empirically determining an offset between the two speeds for your particular combination of motors. Alternatively, you could use the encoders for closed-loop feedback (as your title suggestions) so you control the actual speed of the motors instead of just the voltage to them.

We do not currently have any examples for doing closed-loop speed control like that for the 3pi+, but using PID control for each motor would be my recommendation. This PID speed control tutorial on YouTube might be a good starting point for learning how to do that.

Brandon

How to make the robot (3pi +) to move in straight line and return back to it’s home position.

And also how to record the values of position and speed into a graph format. It would be great if someone could help me out asap.

Hello.

I merged your new thread into your old one since the questions are very similar and seem to be about the same topic.

Returning back to the starting position would probably involve keeping track of how many encoder counts you get while moving forward, then either turning around or reversing until the same number of encoder ticks are counted. It sounds like you might be describing behavior of a “dead reckoning” robot, so you might find this blog post about Paul’s dead reckoning robot helpful.

As far as logging the position and speed values, there are many ways you could do something like that, but the 3pi+ does not have any special data logging features built-in. Depending on the amount of data you are trying to gather, you might be able to just store the coordinates of the data you want to graph in arrays, then have the 3pi+ print the data after you connect it to your computer via USB. From there, you could import the data to a spreadsheet and graph it. Another option might be to use some kind of wireless device (e.g. Bluetooth, WiFi, or RF) that you can use to send the data wirelessly to another device like your computer or a separate microcontroller. Alternatively, you could look into adding some kind of data logging device to the 3pi+ that you can use to store the data separately, such as a micro SD card carrier. However, each I/O pin on the 3pi+ is already being used for some other purpose, so you would need to disable features to get something like that to work.

Brandon

Hello

I was more interested in the data logging aspect of this discussion.

@BrandonM you mentioned

Depending on the amount of data you are trying to gather, you might be able to just store the coordinates of the data you want to graph in arrays, then have the 3pi+ print the data after you connect it to your computer via USB.

I am able to monitor data when connected using the serial monitor but it would be useful I could do this while being remote. Could you share some resources that one could refer to achieve this?

Thanks

Hello.

In case it was not clear, the 3pi+ Robot does not have any built-in way to transmit data wirelessly. What I was referring to in the sentence you quoted was essentially having the robot gather the data by saving it into arrays, then having it wait until the USB is connected and the serial port is opened to dump the data to a computer. We do not have any examples for doing this, but it should be fairly straight forward. You can use Serial.available() to check if the serial port is open.

Alternatively, you could try adding a Bluetooth or WiFi serial module to the robot like I mentioned in my previous post. Unfortunately, we do not currently carry any modules like that, and I do not have any specific recommendations for one, but you might check somewhere like Adafruit or SparkFun.

Another option might be a RF devices, such as a pair of Wixels (one on the robot and one connected to a computer) each running the Wireless Serial App, but please note that those are currently on End-of-life rationing.

Brandon