Quantcast
Viewing all articles
Browse latest Browse all 4938

Automation, sensing and robotics • Need help to drive motor with polar coordinates

Hey, I am currently trying to program a self built RoV and I have put together some code to get polar coordinates from my xbox controller that will essentially drive 2 of the thrusters. The problem I am having is that I need to make it work with Gpiozero and MQTT, since Pigpio remote gpio will not work on a raspberry pi 5 (which will be the topside computer).

Code:

import mathfrom evdev import InputDevice, ecodesdevice = InputDevice('/dev/input/event0')def get_axis_value(i):    return 2.0 * (device.absinfo(i).value -32767) / (-32768 -32767) - 1.0def steerRight():    joy_x = get_axis_value(0)    joy_y = get_axis_value(1)    theta = math.atan2(joy_y, joy_x)    r = math.sqrt(joy_x * joy_x + joy_y * joy_y)    if abs(joy_x) > abs(joy_y):        max_r = abs(r / joy_x)    else:        max_r = abs(r / joy_y)    magnitude = r / max_r    turn_damping = 3.1    right = round(magnitude * (math.sin(theta) - math.cos(theta) / turn_damping), 2)    right = -1 if right < -1 else 1 if right > 1 else right    return right    def steerLeft():    joy_x = get_axis_value(0)    joy_y = get_axis_value(1)    theta = math.atan2(joy_y, joy_x)    r = math.sqrt(joy_x * joy_x + joy_y * joy_y)    if abs(joy_x) > abs(joy_y):        max_r = abs(r / joy_x)    else:        max_r = abs(r / joy_y)    magnitude = r / max_r    turn_damping = 3.1    left = round(magnitude * (math.sin(theta) + math.cos(theta) / turn_damping), 2)    left = -1 if left < -1 else 1 if left > 1 else left    return left        for event in device.read_loop():    if event.type == ecodes.EV_ABS:        print(steerLeft(), steerRight())
I am getting some really good values for X (Left=motor) and Y (Right=motor) but I don't know how to implement these values in Gpiozero to drive the motors, I have tried different things from their motor library and even outputdevice, but nothing seems to work for me and I would love some help if anyone knows a way to do it.

Any help with this would be really appreciated.

Statistics: Posted by Gustav99 — Thu Nov 07, 2024 5:06 pm



Viewing all articles
Browse latest Browse all 4938

Trending Articles