Robotics StackExchange | Archived questions

ROS2 python example for a pan and tilt PID controller

I have a node that publishes a camera frame and a cv2 rect for a face detected along with a center point of that face rect within the camera frame which I want to feed into a pan/tilt mount for the camera along the lines of this https://pyimagesearch.com/2019/04/01/pan-tilt-face-tracking-with-a-raspberry-pi-and-opencv/.

This is running Humble on a Raspberry Pi (Ubuntu Server 22.04) with a Coral accelerator and using a tflite detection model.

I've set up a subscriber node, but I'm not seeing how to bring the PID controller into the subscriber's callback loop. The above example uses python's multiprocessing library to run the PID in a separate processes, but the variables in those processes are not accessible to the ROS2 node subscriber process as far as I can tell.

Is there an example of using a PID controller within an ROS2 subscriber node (python) for the two arguments of pan and tilt?

Asked by mjohannessen on 2023-05-23 14:27:20 UTC

Comments

Great, thanks. The hardware I am using is a Pimoroni Pan Tilt Hat (https://shop.pimoroni.com/products/pan-tilt-hat?variant=22408353287), and the associated python control library. The node to control the pan tilt hat needs to be in python to use the Pimoroni python library, so I am looking for a python PID controller solution (unless I can find a way to port the python library to c++). The issue seems to be creating a PID process within the subscriber callback function that allows the PID values to be updated along with the callback data.

Asked by mjohannessen on 2023-05-24 09:20:04 UTC

To call a Python library function inside C++ code, you can use the Python C API. The Python C API allows you to embed the Python interpreter within your C++ program and interact with Python objects and functions.

Asked by ljaniec on 2023-05-25 07:52:08 UTC

Answers