Docsity

Tutorial 2: Implementing Threads for Random Walk and Obstacle Avoidance in Robotics, Study Guides, Projects, Research of Robotics and Autonomous Systems

Toggle sidebar
bg1
Robotics & Autonomous Systems — Tutorial Two
1. StandardRobot.java.
Compile, upload, and run the StandardRobot example from the lecture.
2. Threads.
The use of threads is more or less essential when programming robots. In this exer-
cise, I want you to write a robot controller with two main threads: RandomWalk and
ObstacleAvoidance, as follows:
•The RandomWalk thread is will, under normal circumstances, control the robot,
and will get the robot to explore the robot arena randomly.
•The ObstacleAvoidance thread will continually monitor the touch sensor and
ultrasonic sensor; if an obstacle is detected at close range, or the touch sensor is
pressed, then the robot should turn around 180 degrees, and then continue with
the random walk.
These two threads will need to communicate with each other: the simplest mechanism
will be to have a boolean variable avoid, which is set to true in the ObstacleAvoidance
thread when this thread wants to take control. When this variable is set to true, then the
RandomWalk thread suspends its actions, allowing the ObstacleAvoidance thread
to take action.
Start by just implementing the RandomWalk thread, and tweak it until it generates the
sort of behaviour you want.
1

Partial preview of the text

Download Tutorial 2: Implementing Threads for Random Walk and Obstacle Avoidance in Robotics and more Study Guides, Projects, Research Robotics and Autonomous Systems in PDF only on Docsity!

Robotics & Autonomous Systems — Tutorial Two

  1. StandardRobot.java. Compile, upload, and run the StandardRobot example from the lecture.
  2. Threads. The use of threads is more or less essential when programming robots. In this exer- cise, I want you to write a robot controller with two main threads: RandomWalk and ObstacleAvoidance, as follows: - The RandomWalk thread is will, under normal circumstances, control the robot, and will get the robot to explore the robot arena randomly. - The ObstacleAvoidance thread will continually monitor the touch sensor and ultrasonic sensor; if an obstacle is detected at close range, or the touch sensor is pressed, then the robot should turn around 180 degrees, and then continue with the random walk.

These two threads will need to communicate with each other: the simplest mechanism will be to have a boolean variable avoid, which is set to true in the ObstacleAvoidance thread when this thread wants to take control. When this variable is set to true, then the RandomWalk thread suspends its actions, allowing the ObstacleAvoidance thread to take action. Start by just implementing the RandomWalk thread, and tweak it until it generates the sort of behaviour you want.