Movement
Working with NanoNav’s motors.
Introduction
To complete the Wumpus challenge, NanoBot will have to navigate the board by moving and turning. It does this by sending power to the motors, which then turn the wheels. Speed of the motors is controlled by the amount of power you send. However, because most microcontrollers can only send LOW or HIGH voltage (0V or 3.3V in the Arduino’s case), power is controlled by a process called Pulse Width Modulation (PWM), which is explained in more detail here if you’re interested.
Sensors called encoders are used to track the rotation of the motors accurately. Encoders track rotation in ticks. You can read more here if you’re interested, but all you have to know is that a positive change in ticks corresponds to a forward rotation of the motor, and a negative change to a backward rotation of the motor.
You don’t have to use encoders in your solution, though they do provide greater accuracy.
Quick Example
from nanonav import NanoBot
import time
# Create a NanoBot object
robot = NanoBot()
# Move forward for 2 seconds
robot.m1_forward(30)
robot.m2_forward(30)
time.sleep(2)
# Stop
robot.stop()
robot.sleep(2)
# Move backward for 2 seconds
robot.m1_backward(30)
robot.m2_backward(30)
time.sleep(2)
# Stop
robot.stop()
Usage
Interact with Arduino and peripheral hardware for movement and sensing.
- Parameters:
saturated_speed – The maximum duty cycle to use for the motors. This is a percentage of max speed the motor can supply from 0-100. If you find that your NanoBot is driving too fast or not driving fast enough, try changing this value.
Return the current encoder 1 count.
- Returns:
The value of the encoder 1.
- Return type:
int
Return the current encoder 2 count.
- Returns:
The value of the encoder 2.
- Return type:
int
Set Motor 1 to turn backward at speed.
- Parameters:
speed (int or float) – The speed to turn Motor 1 backward at. This is a percentage of max speed from 0-100.
Set Motor 1 to turn forward at speed.
- Parameters:
speed (int or float) – The speed to turn Motor 1 forward at. This is a percentage of max speed from 0-100.
Set Motor 2 to turn backward at speed.
- Parameters:
speed (int or float) – The speed to turn Motor 2 backward at. This is a percentage of max speed from 0-100.
Set Motor 2 to turn forward at speed.
- Parameters:
speed (int or float) – The speed to turn Motor 2 forward at. This is a percentage of max speed from 0-100.
Set the current encoder 1 count. This is useful if you want to zero its value.
- Parameters:
value (int) – The new value to set the encoder 1 count to.
Set the current encoder 2 count. This is useful if you want to zero its value.
- Parameters:
value (int) – The new value to set the encoder 2 count to.
Turn off all motors.