Circuit Python tutorials in Robotics II
View the Project on GitHub MrPrattASH/Robotics-II-Circuit-Python
Now that you know how to program a rotational servo, let’s do some challenges to continue to build your knowledge. You’ll need your basic rover for this challenge.
Let’s wire up your rover first. Don’t forget your 10uF Capacitor and 0.22uF ceramic capacitor to help filter out some noise. Remember, the closer these capacitors are to your power rail jumpers, the better.
For this challenge, it will be useful to create several user defined functions. We’ll step through the various challenges to create these functions.
straight()
stop()
turn_right()
turn_left()
Calibrate the motors on your rover so that:
After calibrating your motor, write your user defined function. Note, do not include a sleep or pause in your straight function. It might look something like this:
def straight():
m1.throttle = 0.5
m2.throttle = -0.45
You may also find it useful to make a stop()
function as well. These functions will save you having to re-write code multiple times. Ensure you have calibrated your servo stop for each servo
def stop():
m1.throttle = 0 # m1's stop value
m2.throttle = -0.1 # m2's stop value
After defining your functions, you’ll need to “call” or run them. For example:
while True:
straight()
time.sleep(5) #move straight for 5 sec
stop()
time.sleep(5) #stop for 5 sec
Calibrate the motors on your rover so that:
Ensure you make x2 functions, 1 for left_turn()
and right_turn()
respectively. You should include a sleep in these functions.
time.sleep(x.x)
for x.x seconds.Make your rover: