day 2 slides uno summer 2010 robotics workshop
DESCRIPTION
Slides for day 2 of UNO summer 2010 high school robotics workshopTRANSCRIPT
![Page 1: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/1.jpg)
Robotics: Designing and Building
Multi-robot Systems
Day 2
UNO Summer 2010 High School UNO Summer 2010 High School
Workshop
Raj Dasupta
Associate Professor
Computer Science Department
University of Nebraska, Omaha
College of Information Science and Technology
![Page 2: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/2.jpg)
Plan for Day 2
• Designing autonomous intelligence in robots...controller– MyBot: Simple Obstacle Avoidance
– Blinking LEDs
– Controlling motors– Controlling motors
– Camera-based object following
– Finte State machine: Lawn mower like pattern
– Obstacle Avoidance: Code review
– Line Follower: Code review
– Odometry: Simulation only
– Braitenberg: Code review
![Page 3: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/3.jpg)
Designing the Robot’s Controller
• Controller contains the ‘brain’ of the robot
Controller
Read input from
sensors
Send output
to actuators
![Page 4: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/4.jpg)
Designing the Robot’s Controller
• Controller contains the ‘brain’ of the robot
Controller
Read input from
sensors
Send output
to actuators
![Page 5: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/5.jpg)
Reading the Input from the sensors
#include <webots/robot.h>#include <webots/distance_sensor.h>#include <stdio.h>
#define TIME_STEP 32
int main() {wb_robot_init();
WbDeviceTag ds = wb_robot_get_device("my_distance_sensor");wb_distance_sensor_enable(ds, TIME_STEP);
while (1) {wb_robot_step(TIME_STEP);double dist = wb_distance_sensor_get_value(ds);printf("sensor value is %f\n", dist);
}
return 0;}
![Page 6: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/6.jpg)
Reading the Input from the sensors
#include <webots/robot.h>#include <webots/distance_sensor.h>#include <stdio.h>
#define TIME_STEP 32
int main() {wb_robot_init();
This is the “name”
field of the robot’s
sensor from the
scene tree
1. Get a handle to
the sensor device
WbDeviceTag ds = wb_robot_get_device("my_distance_sensor");wb_distance_sensor_enable(ds, TIME_STEP);
while (1) {wb_robot_step(TIME_STEP);double dist = wb_distance_sensor_get_value(ds);printf("sensor value is %f\n", dist);
}
return 0;}
2. Enable the sensor device...the general format of this step is
wb_<sensor_name>_enable (sensor_handle, poll_time)
How often to get
the data from the
sensor
3. Get the sensor data...the general format of this step is
wb_<sensor_name>_get_value (sensor_handle)
![Page 7: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/7.jpg)
Designing the Robot’s Controller
• Controller contains the ‘brain’ of the robot
Controller
Read input from
sensors
Send output
to actuators
![Page 8: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/8.jpg)
Sending the output to actuators
#include <webots/robot.h>#include <webots/servo.h>#include <math.h>
#define TIME_STEP 32
int main() {wb_robot_init();
WbDeviceTag servo = wb_robot_get_device("my_servo");WbDeviceTag servo = wb_robot_get_device("my_servo");
double F = 2.0; // frequency 2 Hzdouble t = 0.0; // elapsed simulation time
while (1) {double pos = sin(t * 2.0 * M_PI * F);wb_servo_set_position(servo, pos);wb_robot_step(TIME_STEP);t += (double)TIME_STEP / 1000.0;
}
return 0;}
![Page 9: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/9.jpg)
Designing the Robot’s Controller
• Controller contains the ‘brain’ of the robot
Controller
Read input from
sensors
Send output
to actuators
![Page 10: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/10.jpg)
A simple example#include <webots/robot.h>#include <webots/differential_wheels.h>#include <webots/distance_sensor.h>
#define TIME_STEP 32
int main() {wb_robot_init();
WbDeviceTag left_sensor = wb_robot_get_device("left_sensor");WbDeviceTag right_sensor = wb_robot_get_device("right_sensor");wb_distance_sensor_enable(left_sensor, TIME_STEP);wb_distance_sensor_enable(right_sensor, TIME_STEP);
while (1) {wb_robot_step(TIME_STEP);
// read sensorsdouble left_dist = wb_distance_sensor_get_value(left_sensor);double right_dist = wb_distance_sensor_get_value(right_sensor);
// compute behaviordouble left = compute_left_speed(left_dist, right_dist);double right = compute_right_speed(left_dist, right_dist);
// actuate wheel motorswb_differential_wheels_set_speed(left, right);
}
return 0;}
![Page 11: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/11.jpg)
A simple example#include <webots/robot.h>#include <webots/differential_wheels.h>#include <webots/distance_sensor.h>
#define TIME_STEP 32
int main() {wb_robot_init();
WbDeviceTag left_sensor = wb_robot_get_device("left_sensor");WbDeviceTag right_sensor = wb_robot_get_device("right_sensor");wb_distance_sensor_enable(left_sensor, TIME_STEP);wb_distance_sensor_enable(right_sensor, TIME_STEP);
while (1) {wb_robot_step(TIME_STEP);
// read sensorsdouble left_dist = wb_distance_sensor_get_value(left_sensor);double right_dist = wb_distance_sensor_get_value(right_sensor);
// compute behaviordouble left = compute_left_speed(left_dist, right_dist);double right = compute_right_speed(left_dist, right_dist);
// actuate wheel motorswb_differential_wheels_set_speed(left, right);
}
return 0;}
Get input from sensor data
Send output to actuator
A very simple controller
![Page 12: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/12.jpg)
A few other points#include <webots/robot.h>#include <webots/differential_wheels.h>#include <webots/distance_sensor.h>
#define TIME_STEP 32
int main() {wb_robot_init();
WbDeviceTag left_sensor = wb_robot_get_device("left_sensor");WbDeviceTag right_sensor = wb_robot_get_device("right_sensor");wb_distance_sensor_enable(left_sensor, TIME_STEP);wb_distance_sensor_enable(right_sensor, TIME_STEP);
Keep doing this as long as
the simulation (and the
robot) runs
Mandatory initialization
step...only used in C language
while (1) {wb_robot_step(TIME_STEP);
// read sensorsdouble left_dist = wb_distance_sensor_get_value(left_sensor);double right_dist = wb_distance_sensor_get_value(right_sensor);
// compute behaviordouble left = compute_left_speed(left_dist, right_dist);double right = compute_right_speed(left_dist, right_dist);
// actuate wheel motorswb_differential_wheels_set_speed(left, right);
}
return 0;}
• How often to get data
from simulated robot into
the controller program
• Every controller must
have it
• Must be called at regular
intervals
• Placed inside main()
![Page 13: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/13.jpg)
MyBot Controller
• Simple obstacle avoidance behavior
– Get IR distance sensor inputs (both L and R)
– If both of these readings are > 500... its an
emergency, back up fastemergency, back up fast
– If only one of these readings is > 500...turn
proportionately to the sensor values
– If both readings are < 500...nothing wrong, keep
moving straight
• Let’s program this in Webots
![Page 14: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/14.jpg)
E-puck: Spinning
• Start spinning left
• If left wheel speed > 1234, stop
![Page 15: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/15.jpg)
E-puck: LED blinking
• Blink the 8 LEDs of the e-puck one after another
– Turn all LEDs off
– Count repeatedly from 1...8– Count repeatedly from 1...8
• Turn LED<count> on
• Note that in this example, we are not using any sensor inputs...the LEDS just start blinking in a circle when we start running the simulation
![Page 16: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/16.jpg)
Camera Controller
• Objective: Follow a white ball
• How to do it...
– Get the image from the camera
– Calculate the brightest spot on the camera’s – Calculate the brightest spot on the camera’s
image...the portion of the image that has the
highest intensity (white color of ball will have
highest intensity)
– Set the direction and speed of the wheels of the
robot to move towards the brightest spot
![Page 17: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/17.jpg)
State-based controller for object
following with camera
Analyze
image to
find the
brightest
spot
Do some math
to calculate the
direction and
speed of the
wheels to get to
the brightest spo
Get image
from
camera
the brightest spo
Set wheel
speed to
the
calculated
values
![Page 18: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/18.jpg)
State Machine
• Controller is usually implemented as a finite
state machine
State i
State j
State k
Transition (i,j) Transition (J,k)
![Page 19: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/19.jpg)
A finite state-based controller for
avoiding obstacles
Stop
One of L or R front
sensors recording
obstacles
40 steps complete
Moving
forward
Make a
U-turn
Both L and R front
sensors not recording
any obstacles
40 steps not complete
Angle turned >= 180
degrees
![Page 20: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/20.jpg)
E-puck Webots Review
• Obstacle Avoidance: Code review
• Line Follower: Code review
• Odometry: Simulation only
• Braitenberg: Code review• Braitenberg: Code review
![Page 21: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/21.jpg)
Summary of Day 2 Activities
• Today we learned about the controller of a robot
• The controller is the autonomous, intelligent part of the robotpart of the robot
• The controller processes the inputs from the robot’s sensors and tells the robot’s actuator what to do
• We wrote the code for different controllers and reviewed some complex controllers
![Page 22: Day 2 slides UNO summer 2010 robotics workshop](https://reader034.vdocuments.site/reader034/viewer/2022051412/54b740db4a795987518b4836/html5/thumbnails/22.jpg)
Plan for Day 3
• We will learn how to program some basic
behaviors on the e-puck robot
– Zachary will be teaching this section