Questions about self drive tuning


I am using the monsterborg self-drive code in order to drive my robot around this track (attached to this comment). I have been tweaking the values for a long time, yet I cannot seem to find any values (for the PID loops) that allow my robot to drive around this curve. My track is roughly 20mm and I think my camera is mounted accurately. Could you please possibly give me some advice or guidance on how to get the robot to follow this track? What currently is happening is that it follows the line when it is straight, yet when the white line curves, the robot loses track of it and comes to a halt.


piborg's picture

It looks like your corners are rather small compared to the size of the robot. This means that the MonsterBorg will quickly loose sight of the line if it does not react quickly enough.

The first thing I would suggest is turning motorSmoothing down to 1. This will effectively turn the smoothing off. While the smoothing helps keep the steering changes from being to jumpy, it also causes changes to be delayed. With the standard value of 5 it means at least 5 frames have to be processed before the steering can go from none to full.

You may also want to reduce currentSpeed (1 is full speed) and see how things work out. The faster the MonsterBorg is moving the less updates it gets from the camera for the same distance travelled.

Finally you could try increasing frameRate. Be aware that the code has to keep up with the images, or it will start controlling based on old data. I think a Pi 4 would probably cope with 60, but I have not tested it.

To give you an idea, the standard values work fairly well on the Formula Pi track. When we tested this code it was driving on the inside red track, which is rather wide / long corners.


After taking your advice, my robot managed to get further around the track, yet when it approached the curve it just stopped. Are there any other values I could tweak in order to get it to work? If this doesn't work, I found this code:, which could possibly work. I would have to tweak a few things (convert all the Zeroborg to Thunderborg) yet it seems possible. The question I have about this code is that does LeftPin refers to GND or OUT?

Sorry for the many questions but your help is greatly appreciated!
Once again, many thanks!

piborg's picture

To help further I will need a little more information:

  1. Does the robot try and turn at all?
  2. Have you tried adjusting targetY1 and targetY2?
  3. Can you attach some images with testMode = True and showImages = True at various points around the track (especially the corner)

For the other code: leftPin, middlePin, and rightPin are all OUT for different sensors. Basically you have a sensor for left of the line, on the line, and right of the line. This page has a decent explanation:

Thank you so much for your help. I was testing various ways of mounting the camera and I found a position that works well.

Many Thanks!

piborg's picture

Glad to hear you managed to get it working :)

I would love to see some images / videos if you would like to share.

Subscribe to Comments for "Questions about self drive tuning"