Independent and Simultaneous Tasks (ESP-IDF FreeRTOS)

Nespressif
Posts: 76
Joined: Tue Sep 12, 2017 11:25 am

Re: Independent and Simultaneous Tasks (ESP-IDF FreeRTOS)

Postby Nespressif » Wed Sep 27, 2023 7:34 am

MicroController wrote:
Tue Sep 26, 2023 8:40 pm
it is not the idea that I have to move each servo in an independent task that runs on each core
Indeed, it's not. It's an alternative suggestion on how to control any number of servos simultaneously from a single dedicated task. One or more other tasks or ISRs can asynchronously give "commands" to the servos by calling startServoMove() and all servos will move at the same time, each at its own prescribed speed until it stops at its target position or receives another command.
An approach like this is more efficient than creating one task per servo and scales to more servos than you have PWM channels with virtually no increment in RAM or CPU use.
But I may also have misunderstood the actual issue.
Hello MicroController, your idea seems very interesting to me and I am going to try your code, but I don't think it is the best option to achieve my goal.
I will try to explain myself better, I have a servo tower made https://es.aliexpress.com/item/33002852 ... Redirect=yup of two servomotors, one makes the horizontal movement and the other vertical. The tower moves a laser that is projected onto a surface to describe a trajectory.
I have a task that controls a microphone, to send a notification to the task or tasks through an interruption (if there are two tasks, it sends it first to one and then to the other) so I can activate the laser and start the movement of the laser tower with the voice.
The positions to define the movement of the servos are already defined in an array previously.
I can now make very fluid and precise movements, by improving the algorithm and trying different servo motors, but I have always made the movement from the same task, first moving the horizontal servo and then the vertical one. Furthermore, the task that controls the microphone and the one that makes the movement are tied to different cores, and this is precisely what I would like to take advantage of....the SMP and use both cores of an ESP32 so that each core moves a servo.
Since I only have two servos and the use of resources is not a problem, I use two tasks anchored to a different core each.
I'm already writing the code, let's see if I finish it soon and can test it.
Thank you very much, if you have any suggestions or clarifications, I am very grateful.

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Independent and Simultaneous Tasks (ESP-IDF FreeRTOS)

Postby MicroController » Wed Sep 27, 2023 10:11 pm

this is precisely what I would like to take advantage of....the SMP and use both cores of an ESP32
In fact, by pinning tasks to cores you explicitly limit, i.e. reduce, the use of both cores. An unpinned task can run on any core that becomes available; a pinned task cannot run if its core is currently busy with another higher-or-equal priority task, even if the other core has nothing to do. Try and make sure you choose the 'right' priorities for your tasks.

But, as others have pointed out, for the control of a mechanical system (esp. one controlled via 50Hz signals...) you really don't care if one servo is a microsecond, or ten, ahead of another one or not.

(You do use hardware PWM for the servo signals?)

Nespressif
Posts: 76
Joined: Tue Sep 12, 2017 11:25 am

Re: Independent and Simultaneous Tasks (ESP-IDF FreeRTOS)

Postby Nespressif » Thu Sep 28, 2023 12:19 pm

Yes, I understand what you say about the priorities of the tasks, that is clear to me and everything works perfectly, since the most priority is the task that drives the engine.
Yes, I use PWM to control the motors.

Who is online

Users browsing this forum: cdollar, Google [Bot] and 121 guests