Closed beetlegigg closed 3 months ago
Hi @beetlegigg,
Documentation for Yukon and its modules can be found within the docs
folder of this repo. For example, the one for Big Motor Module can be found here: https://github.com/pimoroni/yukon/blob/main/docs/modules/big_motor.md
If you scroll down, there's a section called Accessing The Motor
, which has a link to the doc for the Motor library Yukon uses. This is over in our Pimoroni Pico repository at: https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/modules/motor/README.md
All modules have similar pages, with links to relevant library documentation (or should do if I've not missed any!)
If by reverse you mean "change the direction it spins when given a forward command", then here's the section of the docs detailing how to do that: https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/modules/motor/README.md#direction
You can also swap the plus and minus wires of your motor (it's not to know if it's wired backwards).
If instead you mean, it's spinning in one direction and you want its speed to be inverted when an event happens, then you can do:
module.motor.speed(0 - module.motor.speed())
There are also motor.full_positive()
and motor.full_negative()
functions you can call if your code already knows the direction it was spinning. E.g.
while True:
if is_sensor_triggered():
module.motor.full_negative()
else:
module.motor.full_positive()
These functions are explained at: https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/modules/motor/README.md#full-speed
And here's the function reference for the Motor
class: https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/modules/motor/README.md#function-reference
Generally, I would have a speed variable for the left and right wheels of such a robot and set the motor's speed with module.motor.speed()
every loop. Then change that value based on whatever sensor inputs your robot may have. The rover showcase example does this when it receives new joystick inputs.
https://github.com/pimoroni/yukon/blob/02b2d9f1a66cdd60cce06b3a5762794e5db87979/examples/showcase/rover/main.py#L80-L88
Hope that makes sense. Let me know if you need any more explanation 🙂
Thanks @ZodiusInfuser I see that, whilst perhaps a bit labyrinthine, theres lots of documents relating to issuing commands to drive the motors as desired via the Yukon board. I'll be downloading all the doc's and knocking up some test code to familiarise myself.
I maybe missing some documentation that is available but I've not found much on using the libraries for the various modules. Whilst there are example programs, trawling through code is probably not the best way to understand the full use of the provided Yukon libraries.
During my first of the brief test of the Big Motor module I failed to see how to put a motor into reverse. And reversing a rover robot that has gone too close to an obstacle is rather fundamental to controlling the bot :-) Please can you either point me to the appropriate docs or inform on the correct code to put a motor in reverse. (in micropython of course)
Thanks.