fusionjuggler13
Posts: 3
Joined: Mon May 03, 2021 1:03 am

Question about selecting the right servo control module

Fri May 07, 2021 9:02 pm

Hello All, I'm new to this forum I believe this is the right location to ask this question, but if it's not be sure to tell me.

Let me tell you first what I'm working on just to get an idea of my problem. The project I'm working on is to orchestrate the movements of an array of RC cars that I connect to using a python socket server. There's an overhead camera that I use to track the position of each of the cars on the track and from this information, the motion of all the cars can be coordinated. My part in this project is to get the cars to operate reliably. Each car has a servo to control the steering and a DC motor to drive the car. I control the DC motor using an "Adafruit TB6612 1.2A DC/Stepper Motor Driver Breakout Board" this module requires a digital signal for standby two digital signals for directional control and a PWM signal at 1000hz frequency for DC motor speed control. The servo is connected directly to the pi.

I currently have a servo motor wired directly to a raspberry pi zero w (version 1.3) to control the steering and I'm using the RPi.GPIO library in python, but the jitter of the servo is really extreme. I believe this is because Linux isn't really designed for this kind of time-sensitive operation. To remedy this I want to find preferably some external servo controller module that can generate a dedicated PWM signal to prevent this kind of severe jitter. I'm having some trouble with this problem because I can't seem to find the module I need. I Ideally want it to be relatively simple to implement and not super invasive on what I already have. I also need to have the servo powered in order to keep the steering column at a specific angle; so I can't just set the steering column to an angle and turn it off it must stay on. Finding a reliable way to control a servo motor with nearly negligible jitter is the problem I'm dealing with.

I've looked into some hats for the pi that specialize in servo control but the ones that I've seen seem to take up the entire GPIO pin array and because I have other peripherals I need enough of the GPIO pin array to actually control them. I also found some external modules for controlling servos using Arduino but those ones looked like they needed to connect to the Arduino's analog input and I don't think the raspberry pi has an analog input. I don't know if there might be a programmatic solution to this problem either because like earlier mentioned Linux doesn't play well with precise timing.

Thanks for any input you guys may give. If you need any more information feel free to ask me.

This is the python code I run on the RC car

Code: Select all

import socket
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

#This is the steering section
GPIO.setup(7, GPIO.OUT)
pwmserv = GPIO.PWM(7, 50)
pwmserv.start(7)

#This is the driving section
GPIO.setup(11, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)

GPIO.output(11, GPIO.HIGH)

GPIO.output(13, GPIO.HIGH)
GPIO.output(16, GPIO.LOW)

pwmsig = GPIO.PWM(12, 1000)
pwmsig.start(0)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("[Computer IP]", 1234))

msg = s.recv(1024).decode("utf-8")


while(msg != "end"):
	print(msg)
	if(msg[0:5] == "drive"):
		if(msg[8:9] == "F"):
			GPIO.output(13, GPIO.LOW)
			GPIO.output(16, GPIO.HIGH)
		elif(msg[8:9] == "R"):
			GPIO.output(13, GPIO.HIGH)
			GPIO.output(16, GPIO.LOW)
		
		pwmsig.ChangeDutyCycle(int(msg[5:8]))

	if(msg[0:5] == "steer"):
		pwmserv.ChangeDutyCycle((int(msg[5:7])/90)*4 + 5)

	msg = s.recv(1024).decode("utf-8")
	
Attachments
Capture.PNG
Capture.PNG (231.96 KiB) Viewed 166 times

User avatar
Gavinmc42
Posts: 5636
Joined: Wed Aug 28, 2013 3:31 am

Re: Question about selecting the right servo control module

Sat May 08, 2021 2:07 am

The Pi has 2 PWM outputs, use those?

The servo needs a pulse between 1 to 2ms every 20ms.
10bit accuracy is good enough, so 1000 to 2000 steps in a 20,000 loop clocked at 1MHz?

Or just use the Servo option in PiGPIO.
http://abyz.me.uk/rpi/pigpio/python.html

Try to avoid Python for this sort of timing stuff, use it to interface to the PIGPIO lib
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

fusionjuggler13
Posts: 3
Joined: Mon May 03, 2021 1:03 am

Re: Question about selecting the right servo control module

Sun May 09, 2021 8:25 pm

Thank you for the advice, when I get to work I'll try it out.

fusionjuggler13
Posts: 3
Joined: Mon May 03, 2021 1:03 am

Re: Question about selecting the right servo control module

Sun May 09, 2021 11:18 pm

I implemented the solution and It worked perfectly, thank you so much

Return to “Compute Module”