Robotics-II-Circuit-Python

Circuit Python tutorials in Robotics II

View the Project on GitHub MrPrattASH/Robotics-II-Circuit-Python

Table of Contents

Rotational Servo Challenges

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.

Wiring your Rover

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. rover roverjpeg

Writing User Defined Functions

For this challenge, it will be useful to create several user defined functions. We’ll step through the various challenges to create these functions.

  1. straight()
  2. stop()
  3. turn_right()
  4. turn_left()

1. Straight Movement:

Calibrate the motors on your rover so that:

Key Design Constraints

Define Functions

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

Call Functions

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

2. 90 Degree* Turns

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.

Key Design Constraints

3. Square Movement

Make your rover: