Homework 4: (GRADUATE VERSION)

Similar documents
Week 5: Files and Streams

Call-by-Type Functions in C++ Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #5

COMP322 - Introduction to C++

Text File I/O. #include <iostream> #include <fstream> using namespace std; int main() {

Reading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary

In either case, remember to delete each array that you allocate.

Solving a 2D Maze. const int WIDTH = 10; const int HEIGHT = 10;

C++ 프로그래밍실습. Visual Studio Smart Computing Laboratory

CS103 Lecture 1 Slides. Introduction Mark Redekopp

ECE 2036 Lab 1: Introduction to Software Objects

Programming with Haiku

CS2141 Software Development using C/C++ Stream I/O

Outline. Review of Last Week II. Review of Last Week. Computer Memory. Review Variables and Memory. February 7, Data Types

File I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents

FILE IO AND DATA REPRSENTATION. Problem Solving with Computers-I

Motion Planning. Howie CHoset

Input and Output File (Files and Stream )

CSCI-1200 Data Structures Spring 2015 Lecture 2 STL Strings & Vectors

Random File Access. 1. Random File Access

Today in CS161. Lecture #7. Learn about. Rewrite our First Program. Create new Graphics Demos. If and else statements. Using if and else statements

C++ Programming Lecture 10 File Processing

BITG 1113: Files and Stream LECTURE 10

Code Coverage Metrics And How to Use Them

Lecture 5 Files and Streams

Lab: Supplying Inputs to Programs

Convenient way to deal large quantities of data. Store data permanently (until file is deleted).

I/O Streams and Standard I/O Devices (cont d.)

CSCI-1200 Data Structures Fall 2017 Lecture 2 STL Strings & Vectors

Summary of basic C++-commands

PROGRAMMING EXAMPLE: Checking Account Balance

Maciej Sobieraj. Lecture 1

Navigation and Metric Path Planning

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts

What will happen if the user presses <enter> after every input? Will all work like below? Enter the values of x, y, z: Result: The sum is 17.

Streams in C++ Stream concept. Reference information. Stream type declarations

CS103 Lecture 1 Slides. Introduction Mark Redekopp

CSCI-1200 Data Structures Fall 2009 Lecture 12 Advanced Recursion

Praktikum: 4. Content of today s lecture. Content of today s lecture. Manfred Grove Houxiang Zhang. Program introduction. Program introduction

Pointers and scanf() Steven R. Bagley

CSE 100: STREAM I/O, BITWISE OPERATIONS, BIT STREAM I/O

Name Section: M/W T/TH Number Definition Matching (8 Points)

2) F_TEST.CPP) //f_test.cpp

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Advanced Programming in Engineering Saurabh Srivastava, Thomas Weinhart Martin Robinson, and Stefan Luding MSM, CTW, UTwente, NL

Objects and streams and files CS427: Elements of Software Engineering

#include <iostream> #include <algorithm> #include <cmath> using namespace std; int f1(int x, int y) { return (double)(x/y); }

CSE 333 Midterm Exam 7/29/13

C++ Input/Output: Streams

Grades. Notes (by question) Score Num Students Approx Grade A 90s 7 A 80s 20 B 70s 9 C 60s 9 C

Manfred Grove Houxiang Zhang

Introduction. Lecture 5 Files and Streams FILE * FILE *

Project 1: Convex hulls and line segment intersection

CE221 Programming in C++ Part 1 Introduction

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

Chapte t r r 9

Chapter 11 Introduction to Programming in C

EE 355 OCR PA You Better Recognize

CS 201 (Intro. to Computing) Fall 2015 Sabancı University Sample Questions for Midterm 1

CSE au Midterm Exam Nov. 2, 2018 Sample Solution

Chapter 3 - Notes Input/Output

typedef Labeling<unsigned char,short> LabelingBS; typedef Labeling<unsigned char,short>::regioninfo RegionInfoBS;

CSCI-1200 Computer Science II Spring 2006 Lecture 10 Recursion Examples

Programming Robots with ROS, Morgan Quigley, Brian Gerkey & William D. Smart

The C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.

BSc (Hons) Computer Science. with Network Security. Examinations for / Semester1

[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 7. Seungkyu Lee. Assistant Professor, Dept. of Computer Engineering Kyung Hee University

More on Func*ons Command Line Arguments CS 16: Solving Problems with Computers I Lecture #8

File Operations. Lecture 16 COP 3014 Spring April 18, 2018

CS 376b Computer Vision

Today in CS161. Week #3. Learn about. Writing our First Program. See example demo programs. Data types (char, int, float) Input and Output (cin, cout)

G52CPP C++ Programming Lecture 17

Lab 1: First Steps in C++ - Eclipse

CSCS 261 Programming Concepts Exam 1 Fall EXAM 1 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

Streams. Rupesh Nasre.

Midterm Exam #2 Spring (1:00-3:00pm, Friday, March 15)

Chapter 5: Loops and Files

Week 3: File I/O and Formatting 3.7 Formatting Output

Introduction to C ++

Example problem: Solution of the 2D unsteady heat equation with restarts

CSE 333 Midterm Exam July 24, Name UW ID#

Chapter 11 Introduction to Programming in C

Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

C++ Structures Programming Workshop 2 (CSCI 1061U)

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.

Chapter 13. Recursion. Copyright 2016 Pearson, Inc. All rights reserved.

Software Design & Programming I

C++ Input/Output Chapter 4 Topics

Today in CS162. External Files. What is an external file? How do we save data in a file? CS162 External Data Files 1

Lecture 3 The character, string data Types Files

Name Section: M/W T/TH Number Definition Matching (6 Points)

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Ch 4. Parameters and Function Overloading

Strings and Stream I/O

C++ Constructor Insanity

A SHORT COURSE ON C++

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

CSE 333 Midterm Exam Sample Solution 7/29/13

Program Organization and Comments

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Transcription:

Homework 4: Wavefront Path Planning and Path Smoothing (GRADUATE VERSION) Assigned: Thursday, October 16, 2008 Due: Friday, October 31, 2008 at 23:59:59 In this assignment, you will write a path planner that makes use of wavefront propagation, smooth the resulting path, and then visualize the smoothed path by plotting it on the map of the environment. In this assignment, the path is a set of x, y positions from the starting position to the goal position. Note that the orientation of the robot is not considered in this exercise. In this assignment, your robot does not have to execute the planned path only derive it. (Note: Player includes a Planner proxy. However, the purpose of this assignment is for you to gain experience writing your own planning software. So, you are not allowed to copy or make use of the existing planner proxy software. Instead, you must write your own wavefront planner using the algorithm outlined in class on October 7.) Your software should operate as follows: Your code accepts the robot s goal position (in terms of x,y only) from the user using standard input. Your user interface should make it clear how the user should enter the goal (x,y) position. The exact format is up to you. You should do some modest error checking to make sure the goal position entered is numeric, and within the bounds of the robot s environment. Your code inputs the map of the environment, and then creates the Cspace version of the map by growing the obstacles for the standard Pioneer robot. Your code executes a wavefront path planning method. Here, you should start the planning at the goal position, and work back to the start.. The output of this function is a series of waypoints the robot should visit to reach the goal position. Your code smoothes the resulting path, resulting in fewer waypoints. Your code visualizes the generated path by plotting it on the map of the environment (so that it is visible in the Stage simulation window.) More details on these processes follow. Inputting the map. Obviously, for the path planner to function correctly, it needs to load the map of the environment into memory. For this assignment, we ll use the hospital_section map. At present, we have a bitmap version of this map in png format. However this format makes use of data compression, and isn t the easiest for you to read in directly into memory for the purposes of this assignment. So, we ll convert the bitmap to another format. We have several to pick from; we ll choose the pnm format. Later in this document, I provide instructions on how to do this, as well as a function you can use to read in the map into a 2-dimensional binary occupancy grid array, in which 0 s represent free space and 1 s Page 1 of 6

represent obstacles. Note that you will still use the png format for Stage display purposes; this pnm format is just for your code to have access to the map for planning purposes. Growing the map for obstacles. You need to write a function that grows the obstacles in the grid map, so that your path planner can represent the robot as a point. This obstacle growth function must input a parameter representing the amount of growth desired, in units of the number of grid cells. Note that you will find there is a tradeoff between growing the obstacles too much and growing them too little. If you grow them too much, your path planner may not be able to plan a path to a reachable goal. If you grow them too little, the robot could come too close to obstacles. In your pdf file that you turn in, include an image of this Cspace representation (i.e., after growing for obstacles). Wavefront path planner. Once you have your map in memory, and have grown the obstacles, you are ready to implement the path planner. Your path planner must make use of the wavefront path planning algorithm that we discussed in class on Oct. 7. You should start your wave propagation from the goal location, back to the start. Once you generate a path, you ll want to smooth it. One way to do this is to start with waypoint 1, and create the line segment to waypoint 3 (skipping waypoint 2), then determine if any cell along that line segment is occupied. If not, then you can eliminate waypoint 2. This process iterates until you have eliminated all intermediate waypoints that you can. The grid cells that remain on the robot path become waypoints. The output of your wavefront path planner should be this series of waypoints to be reached by the robot. Note that if your path planner is given an unreachable goal position, it should state this fact and gracefully exit. A goal position could be unreachable because it is inside an obstacle, or it could be behind a wall, with no access. Your code should be smart enough to recognize this, and let the user know. Displaying the generated path. As you may already know, Player has a drawing tool, called Graphics2dProxy, that you should use to display your generated path on the map in the Stage simulator. Player documentation is available here: http://playerstage.sourceforge.net/doc/player-2.1.0/player/classplayercc_1_1graphics2dproxy.html The gist is that you connect to the graphics proxy in your code ( Graphics2dProxy gp(&robot, 0); ), then use method calls such as gp.clear() to clear the drawing area, gp.color() to set the drawing color, and gp.drawpolyline() to draw a line connecting a set of points. For this exercise, you simply need to draw the line segments from the starting position to each successive waypoint, up to the goal position. Setting up everything. In this exercise, you must use the bitmap called hospital_section.png. The.cfg and.world files are provided for you in HW4.cfg and HW4.world (on the course website), here: http://www.cs.utk.edu/~parker/courses/cs594-fall08/homeworks/hw4.cfg http://www.cs.utk.edu/~parker/courses/cs594-fall08/homeworks/hw4.world Note that the robot s starting pose is [-10.071 3.186 0]. If you re using the correct setup, your environment should look like the following: Page 2 of 6

Testing your code: Your path planner will always start from the same starting position (which is the starting position of the robot in the original environment, above). Your code should work for any goal position given; in the case of unreachable goal positions, as previously stated, your planner should recognize this and gracefully exit. Test your code for lots of different goal positions. Then, create screendumps of the displayed generated path to the following specific goal positions: (7.5, 5.5) (8.5, -4.0) (-18.5, 7) (-9, -4) WRITE UP THE FOLLOWING (written up in a single pdf file called yourlastname-hw4.pdf): 1 image of your Cspace representation (i.e., the map after growing for obstacles) 4 screenshots of the generated paths to the 4 goal points mentioned above. SUBMITTING YOUR HOMEWORK: Place all your files in a single directory. These files should include: Your screen dumps as requested (i.e., the file yourlastname-hw4.pdf ) Your configuration file, called HW4.cfg Your world file, called HW4.world Your makefile, called makefile or Makefile Your path planning code, called yourlastname-hw4.cc. Any additional include files you created (called whatever you want them to be called). Remove all other unnecessary files. Use the submit script 594mr_submit to submit your files. (These will be emailed to Dr. Parker.) Page 3 of 6

Homework 4 Appendix: Reading in Map Files For this assignment, you need to read in the map file into your program s memory. Your path planner will use this map for finding the robot s path. Note that the bitmaps we have been using are stored in PNG format, which makes use of data compression techniques. While this is great for saving file space, it isn t the easiest format to use for path planning. So, we re going to convert the bitmap files to the PNM ( Portable Any Map ) format, which is often used for exchanging between different graphics file formats. [Since the purpose of this class isn t to learn about graphics file formats, we re going to skip over the details. If you want to learn more about these file formats, there is lots of documentation on the web.] Fortunately, we have handy utilities that can do this conversion for us. The utility we need is called, amazingly enough, pngtopnm. This utility is so simple to use, that I m going to let you convert the hospital_section.png file to the pnm version we ll call hospital_section.pnm. Simply issue the following linux command: linux> pngtopnm hospital_section.png > hospital_section.pnm The resulting PNM file has 3 header lines, followed by the pixels defining the map. You can safely ignore the first and third header lines in the PNM file. The 2 nd header line has handy information on the width and height of the image, in pixels. The rest of the file has a character for each pixel, representing white pixels with 1 and black pixels with 0. We ll convert this to 0 s for free space and 1 s for obstacles in our grid map. So, to read in this map file, I ve written a little utility for you. Creatively, it is called inputmap(). You can find the electronic source on the class web site, under Homework Assignments, here: http://www.cs.utk.edu/~parker/courses/cs594-fall08/homeworks/inputmap.cc I ve also attached a hard copy of the function at the end of this document. Let me point out one more detail. Note that the map is scaled using the SCALE_MAP parameter. In this function, the effect of this parameter is to scale down the size of the map by a factor of 1/SCALE_MAP. This effectively sets the grid size of the map that your planner will use. To determine the size of the grid, you need to compare the metric size of the map (as defined in your world file) with the pixel size of the map (as defined in the PNM file). In this case, the metric size of the world map is 40 meters wide by 18 meters high. The size of the PNM file, in pixels, is 1086 wide by 443 high. We can therefore calculate the number of pixels per meter as 1086pixels/40m wide by 443pixels/18m high, giving us 27.15pixels/m and 24.61pixels/m. Inverting this, we get 3.68cm/pixel and 4.06 cm/pixel. We ll approximate this as 4 cm/pixel. If we make one grid cell per pixel, then our grid resolution is 4x4 cm. This is probably a finer-grained resolution than we need. We can double the grid size to 8x8cm (thus halving the resolution). This seems like a reasonable resolution for our purposes. Thus, we scale the map by a factor of 2 (by setting SCALE_MAP to 2) in the inputmap() function. The function is also set up to allow you to print out your scaled-down map to a separate file (called scaled_hospital_section.pnm ). You can then use an image display program, such as gimp, to view the resulting file. You can also use this approach to print out your map after you ve grown obstacles. Then you can have a look at what your program has generated using the gimp utility. This should be helpful for debugging purposes. Page 4 of 6

// inputmap.cc #include <iostream> #include <fstream> #include <string> using namespace std; #define SCALE_MAP 2 #define GRID_ROWS 1000 #define GRID_COLS 1000 // You can change this to use dynamic memory, if you like. float gridmap[grid_rows][grid_cols]; /************************************************************************* * * * Function inputmap converts the input map information into an * * initial occupancy grid, which is stored in gridmap. * * * (Here, the "output" parameter says whether to print out the scaled * * map; output = 1 ==> yes, print; output = 0 ==> no, don't print.) * *************************************************************************/ void inputmap(int output) { int i, j, m, n; char inputline1[80], nextchar; int width, height, maxval; ifstream infile("hospital_section.pnm"); /* Initialize map to 0's, meaning all free space */ for (m=0; m<grid_rows; m++) for (n=0; n<grid_cols; n++) gridmap[m][n] = 0.0; /* Read past first line */ infile.getline(inputline1,80); /* Read in width, height, maxval */ infile >> width >> height >> maxval; cout << "Width = " << width << ", Height = " << height << endl; /* Read in map */ for (i=0; i<height; i++) for (j=0; j<width; j++) { infile >> nextchar; if (!nextchar) gridmap[i/scale_map][j/scale_map] = 1.0; cout << "Map input complete.\n"; if (output) { ofstream outfile("scaled_hospital_section.pnm"); outfile << inputline1 << endl; outfile << width/scale_map << " " << height/scale_map << endl Page 5 of 6

<< maxval << endl; for (i=0; i<height/scale_map; i++) for (j=0; j<width/scale_map; j++) { if (gridmap[i][j] == 1.0) outfile << (char) 0; else outfile << (char) -1; cout << "Scaled map output to file.\n"; int main(int argc, char *argv[]) { inputmap(1); // Here, '1' means to print out the scaled map to a file; // If you don't want the printout, pass a parameter of '0'. Page 6 of 6