-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A method to continuously target an angle and RuntimeError: can't start a new thread
#195
Comments
Hi, Do you mind trying running your example on the 'main' version of buildhat in this repo (The change isn't released It implements a queuing system, so that you shouldn't get an error. Does that help re. the questions? Thanks You can install from git doing
|
Hi, I ran my example with the 'main' version of buildhat and my first observations are:
I tried a little other example: from buildhat import Motor, Hat
import time
h = Hat(debug=True)
motor_a = Motor('A')
start_time = time.time()
motor_a.run_to_position(degrees=0, speed=20, blocking=True, direction="shortest")
sleep_time_seconds = 0.001
angles_from_controller = [-90, 0, 0, 0, 90, 0, 0, 0]
try:
while True:
for angle in angles_from_controller:
motor_a.run_to_position(degrees=angle, speed=20, blocking=False, direction="shortest")
time.sleep(sleep_time_seconds)
except RuntimeError as e:
duration = time.time() - start_time
print(f"-> Duration: {duration}")
print(e) You can see that the angles are But for my use case I should have a way to delete (or overwrite) an actual command. I think the comment in #175 (comment) meant the same use case. If I send a command There comes my third question in: Maybe I should try to implement a draft of such a method and we could discuss about it when I created a pull request. |
That's a good question, I assume provided a command to move the motor hasn't been issued to the hat itself, there should be a way to do that. It does look to me there aren't ways to alter the synchronised queue though, I can't see any public methods to do this - https://docs.python.org/3/library/queue.html. I wonder if something like https://docs.python.org/3/library/collections.html#collections.deque may be useful here. If you've got any suggestions/ideas/pull reqs. though, that'd be cool. I'm just testing a new firmware currently, but can get back to thinking about this soon. |
Hi, I have a car with an ackermann steering which I would like to control with a ps4 controller. I searched for a way to continuously target the angle delivered by the controller. But I can't find a satisfactory solution with the library at the moment. I hope that someone here can put me on the right track.
I found also a related question #175 (comment) asked by natikgadzhi:
Here is a little program which should simulate the behavior:
Depending on how the sleep time was chosen, the sooner no more threads can be started.
I know that pybricks has a method https://docs.pybricks.com/en/stable/pupdevices/motor.html#pybricks.pupdevices.Motor.track_target or https://docs.pybricks.com/en/stable/pupdevices/motor.html#pybricks.pupdevices.Motor.run_target which does exactly what I would need.
Questions:
track_target
method for motors in the library, maybe I could try to implement a draft of it - but I would have to know a little more first so that the whole thing would fit into the existing concepts and future development. Maybe there are also changes in a future firmware that would help with it.Currently I'm trying to implement my project directly with the serial protocol of the Build HAT without using the Python library - but of course it would be great to be able to use the library.
Thank you for inputs and ideas
The text was updated successfully, but these errors were encountered: