Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Moving after coordinates


I am doing a project using micro maestro 6 channel, a raspberry pi 4 b, two servos and a pi camera. I am trying to make the servo move the camera using the coordinates of a bounding box. It works… but not very well.

These are the functions I am using to calculate the coordinates and to set the target of the motor.

def rescale(wobj, hobj, start_x, start_y, w_imag, h_imag):
w_rescale = 5604 #max_pos - min_pos
h_rescale = 576
4 #max_pos - min_pos

w_imag = 640
h_imag = 480

rescale_coeff_w = w_rescale/w_imag
rescale_coeff_h = h_rescale/h_imag

motor_coord_x = 1904*4 + (start_x + wobj/2)*rescale_coeff_w #1904 = min_pos
motor_coord_y = 1920*4 + (start_y + hobj/2)*rescale_coeff_h #1920= min_pos

return motor_coord_x, motor_coord_y

def move_motor(x, y):
mu.setTarget(channel0, int(x))
mu.setTarget(channel1, int(y))

Also, cam someone explain why we use “*4”??
Thank you!