Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 49

Dr. Paige H.

Meeker
Senses
Humans rely on their senses to understand whats
going on in the world.
Touch, Vision, Hearing, Taste, and Smelling
(sometimes Balance)
Inner Senses (we keep up with our internal state
whats going on inside you and where
everything is)
Robots Senses
Senses are important to robots, too. All robots
come with internal and external senses.
Your robots come with several sensors lets look
at them together, as well as how you can gain
access to them.
Proprioception
Internal senses of the robots!
Whats inside the robot that it would need
to keep up with?
Stall is it stuck?
Time how long does it do certain operations?
Battery Level is it out of juice?
Time
All computers have a built in computer clock;
the scribbler is no different
Functions that use time:
timeRemaining
wait
currentTime
Stalling
Internally, the robot can sense when it is
stalled when trying to move.
getStall()
This returns a true or false value (aka a
Boolean value)
Battery Levels
Now, wouldnt it make sense if the robot could
sense its power levels?
getBattery() returns a value between 0 and 9
volts.
As the battery gets low, the robots behavior
varies.
Operations on Lists
len(L) #this will return the length of list L
Sevens + Fives #this will return the combined list:
[7,14,21,28,5,10,15,20,25]
Names[0] = Tom
Names[3:5] = [Piper, Tango]
Names.sort() = [Amber, Melody, Piper, Tango, Tom]
Names.reverse() = [Tom, Tango, Piper, Melody, Amber]
Names.append(Cherry) = [Tom, Tango, Piper,
Melody, Amber, Cherry]
15 in Fives
Lists as Sequences
Lists can be used in for loops to perform
repetitions:
Classes = [INTD 110, CSC 201, ENG 110]
for classes in Classes:
print classes
Strings are sequences:
ABC = ABCDEFGHIJKLMNOPQRSTUVWXYZ
for letter in ABC:
speak(letter)
Lists as Sequences
You can also convert sentences into lists by
splitting up the words
sentence = Can you play blackjack
words=sentence.split()
words now contains a list: [Can, you,
play, blackjack]
More on functions
Weve learned about writing functions
We use the keyword def followed by the
function name and any parameters. Then,
indented, are the commands to issue for the
function.
Weve used functions that give us values in
return how do we write those?
return <expression>
Returning Functions:
def triple(x):
return x*3

What value would this function return if x=4?


x=100?
Checking Conditions:
if statement: this is a way to allow the
program to make decisions based on
conditions. For example:
if <CONDITION>:
<do something>
<do something>
etc
If the condition is True then whatever is
specified in the body of the if statement is
carried out; if not, this code block is skipped.
Dr. Paige H. Meeker

Slides from Institute for Personal Robots in Education (IPRE)s


Senses
Humans rely on their senses to understand whats
going on in the world.
Touch, Vision, Hearing, Taste, and Smelling
(sometimes Balance)
Inner Senses (we keep up with our internal state
whats going on inside you and where
everything is)
Now that we have our robots, lets take a look at
how they see/sense the world around them
16
Pythons Senses
To get a quick, overall look at the behavior of
the senses of the robots sensors, use the
Myro function senses()
You will see the results of all the sensor calls
in real time (except the camera)
IR Obstacle Sensors
The Scribbler has two IR obstacle sensors
(under the light sensors) that return a binary
value of 0 or 1.
The robot actually has 1 IR receiver located in
the center, and two emitters located on the
left and right side of the emitter.
IR Obstacle Sensors
Return value of: 0 IR light is bouncing back
to the receiver (off of an obstacle)
IR Obstacle Sensors
Return value of: 1 means that infrared light
is not bouncing back to the receiver, so
nothing is in front of the emitter/detector.
IR Obstacle Sensors
getIR() returns a list of two items [1,1]. You
can also call getIR(left) to get just the left
sensor, and similarly with getIR(right). The
function also accepts 0 and 1 as the
parameter to select which sensor value to
return.
IR Obstacle Sensors
With the senses() function running, place
various objects in front of the IR sensors and
see what values are being reported. How
near/far must an object be to be detected?
Light Sensors (3)
The scribbler has 3 light sensors pointing
Left, Center and Right on the same side as
the getIR sensors.
[45, 200, 430] = getLight()
Light Sensors (3)
Light sensor values range from 0 to 5000.
Zero is very bright, 5000 is full dark.
getLight() returns a list of all 3 values.
getLight(left / center / right) or
getLight(0/1/2) selects one value
Light Sensors (3)
Can we make the robot move using the light
sensors?
Lets type in the code on p. 105 -106 of your
text (chapter 5) and play with the robot and a
flashlight.
Internal Scribbler
getBattery() - returns battery voltage
Sensors
getStall() - returns stall condition (0 or 1)
This value changes to a 1 when the motors are
working extra hard (possibly due to the robot
hitting something and being unable to turn the
wheels)
Note that it takes a half second to re-set the
stall sensor once the motors are turned off, so
wait a bit before sampling it again.
getName() - returns the robot's name (can be
changed with setName(newName)
Fluke Board
The Fluke add-on board has its own IR
obstacle sensors and a camera.
Fluke Board IR Obstacle
sensors
Myro uses the getObstacle() function to
differentiate the IR sensors on the Fluke from
the IR sensors on the Scribbler.
The fluke sensors are more sensitive than the
Scribbler sensors Instead of just returning a
zero or one, they return an integer value
between zero and 7000.
Fluke Board IR Obstacle
sensors
The fluke has 3 IR emitters, one pointing
forward...
Fluke Board IR Obstacle
sensors
The fluke has 3 IR emitters, one pointing
forward...
And two pointing to the left and right.
Fluke Board IR Obstacle
sensors
The fluke has 3 IR emitters, one pointing
forward...
And two pointing to the left and right.
They all bounce light back to a center mounted
receiver.
Fluke Board IR Obstacle
sensors
Zero indicates no IR light is bouncing back
from an obstacle.
[0,0,0] = getObstacle()
Fluke Board IR Obstacle
sensors
Larger numbers indicate that more IR light is
bouncing back.
[0, 1842, 0] = getObstacle()
Fluke Board IR Obstacle
sensors
As with the Scribbler, you can select
individual sensors to use (I recommend using
the center sensor).
getObstacle(0 / 1 / 2)
getObstacle(left / center / right)
Fluke Board Camera
You can take a picture using the camera on
the Fluke board.
p = takePicture()
show(p)
Fluke Board Camera
You can then save your photo as a .jpg
(savePicture(picName, name.jpg)
You can turn a series of photos into an
animated gif
(type in code from p. 102, Chapter 5)
Fluke Camera as a
brightness sensor
Similar to the getLight() function on the Scribbler,
the fluke allows you to use the camera as a
brightness sensor with the getBright() function
call.
getBright() returns a list of three values
getBright(0 / 1 / 2) or getBright( right / center /
left) return a single value.
The numbers returned represent the sum of the
luminance values of the pixels in the
right/center/left of the camera, so they are quite
large!
The lower the number, the darker that area of the
camera is.
Robot Actuators
Beep
Motors
LED Lights
Speaker command
Beep
beep() - issues a random beep
beep(1) random beep for 1 second
beep(1,800) Beep at 800Hz for 1 second
beep(1,440,880) two tone beep at 440 &
880Hz for 1 second.
Robot Actuators - Motors
Two motors (left,right) that can be set to a
power level between -1 and 1.
-1 is full reverse
0 is stopped
1 is full speed forward.
Controlled directly with the motors(left,right)
function.
Robot Actuators Motors
These
Utility Functions
functions make it easier to use the
motors to do simple things:
forward(speed, seconds) Moves the robot
forward at the specified speed for the specified
seconds, and then stops.
turnLeft(speed,seconds) Turns the robot left
at the specified speed and for the specified
seconds, then stops.
turnRight() and backward() are similar.
Robot Actuators Motors
Utility Functions
The previous functions would all start the robot, go for a
certain amount of time, and then stop the robot
automatically.
You an also start the robot moving without specifying how
long it should do so:
forward(speed), turnLeft(speed), backward(speed),
turnRight(speed), stop()
Very important to call the stop() function when you want
the robot to stop!
The wait(seconds) function can be used to specify how
long the robot should travel:
forward(0.85)
wait(1.5)
stop()
Motor commands
Synchronous vs
Asynchronous
What is the difference between these pieces
of code?
forward(0.85)
wait(1.5)
stop()

And...
forward(0.85,1.5)
Motor commands
Synchronous vs
Asynchronous
What is the difference between these pieces
of code?
forward(0.85)
beep(1.5,880)
stop()

And...
forward(0.85,1.5)
beep(1.5,880)
Motor commands
Translate & Rotate
Other functions exist:
translate(speed)
rotate(speed)
These functions allow you to add together
different types of motion, allowing the robot
to move forward -- translate(1) while also
turningrotate(0.5).
stop() is equivalent to translate(0); rotate(0)
LED commands
setLED()
The Scribbler robot has 3 green LED lights.
You can control these three lights with
setLED(position, value).
Position is a number: 0, 1, or 2 or a string
left, center, or right
Value is either 0 (off) or 1 (on)
The center light blinks continuously, so
unless you keep setting it's value, it will just
start blinking again.
LED commands
setLEDFront() and
The Fluke board has 2 user controlled red LED
setLEDBack()
lights.
One on the front (small, near the camera) and
one on the back (large, near the white GPIO
connector)
You can control these three lights with
setLEDFront(value) and setLEDBack(value)
functions.
Value is either 0 (off) or 1 (on)
The back LED is VERY bright! And you can set it
to half power with a 0.5 value, or quarter power
with 0.25.
Go play with your robot!

Go play with your


robot's sensors
and actuators!
Something to think
about
Using the Python commands we now know,
can we create a little program to play
blackjack?
What do we need to do to play?
A way to randomly draw the cards
A knowledge of the users desire to hit or stand

A way to repeat until the user desires to quit or


looses.

You might also like