Advanced Programming Techniques Assignment 1 - Implementing A Path Planning Algorithm
Advanced Programming Techniques Assignment 1 - Implementing A Path Planning Algorithm
1 Overview
In this assignment you will implement a simplified algorithm for Path Planning, and use it with a simple
simulated 2D robot moving around a room.
In this assignment you will:
• Practice the programming skills such as:
– Pointers
– Dynamic Memory Management
– Arrays
• Implement a medium size C++ program using predefined classes
• Use a prescribed set of C++11/14 language features
This assignment is marked on three criteria, as given on the Marking Rubric
on Canvas:
• Milestone 1: Writing Tests.
• Milestone 2-4: Implementation of the Path Planner.
• Style & Code Description: Producing well formatted, and well Figure 1: An example robot
documented code.
1
• Analyse and Solve computing problems; Design and Develop suitable algorithmic solutions using
software concepts and skills both (a) introduced in this course, and (b) taught in pre-requisite courses;
Implement and Code the algorithmic solutions in the C++ programming language.
• Discuss and Analyse software design and development strategies; Make and Justify choices in
software design and development; Explore underpinning concepts as related to both theoretical and
practical applications of software design and development using advanced programming techniques.
• Discuss, Analyse, and Use appropriate strategies to develop error-free software including static code
anal-ysis, modern debugging skills and practices, and C++ debugging tools.
• Implement small to medium software programs of varying complexity; Demonstrate and Adhere to
good programming style, and modern standards and practices; Appropriately Use typical features of
the C++ language include basic language constructs, abstract data types, encapsulation and
polymorphism, dy-namic memory management, dynamic data structures, file management, and
managing large projects containing multiple source files; Adhere to the C++14 ISO language features.
• Demonstrate and Adhere to the standards and practice of Professionalism and Ethics, such as
described in the ACS Core Body of Knowledge (CBOK) for ICT Professionals.
2 Introduction
One challenge in robotics is called path planning. This is the process of the robot figuring out how to navigate
between two points within some environment. In this assignment you will implement a simplified path
planning algorithm for a robot moving about a simple 2D environment - a rectangular room with obstacles.
We will represent a simple 2D environment as a grid of ASCII characters. For example:
==========
=S.......=
========.=
=......=.=
==.=.=...=
=..=..=.==
=.===.=..=
=..==G==.=
===.======
==========
Each location in the environment is indexed by a (col,row) co-ordinate. The top-left corner of the environment
is always the co-ordinate (0,0), the col-coordinate increases right-wards, and the row-coordinate increases
down-wards. For the above environment, the four corners have the following co-ordinates:
(0,0) . . (9,0)
. .
. .
(0,8) . . (9,8)
Two dimensional environments can be designed in different ways. For this assignment we will use
environments where:
1. There is one goal (ending) point denoted by character “G”.
2. The environment is always surrounded by walls.
3. The environment can contains junctions, corridors “open” space, loops or islands.
For the purposes of this assignment we will make several important assumptions:
2
• The robot knows the map of the whole environment it is in at the start.
• Robot can only be located at cells marked as empty/open spaces.
• It may not be possible for the robot to reach every empty space.
• The robot can move to any one of 4 cells, that are to the left, right, up, or down from the robots
originating cell. Robot cannot move diagonally.
• For this assignment the direction the robot is “facing” is ignored.
In this assignment, the path planning problem is divided into two parts:
1. forward search: Conduct a forward search algorithm starting from the “start”, until the goal is reached.
The pseudo-code for the algorithm you need to implement is provided to you in Section 3.2.1.
2. backtracking: Move backwards from the “goal” using, the results of forward search, to identify the
shortest path from the start to goal. You will have to develop the pseudo-code for this part. A
description of the algorithm you need to implement is provided to you in Section 3.3.1.
While there are many ways to navigate a 2D environment, you must implement the algorithms provided in
this document. If you don’t, you will receive a NN grade.
3 Assessment Details
The task for this assignment is to write a full C++ program that:
1. Reads in a 20x20 environment from standard-input (std::cin).
2. Finds the robot’s starting position within the environment.
3. Executes the forward search algorithm (Section 3.2.1) until the robot reaches the goal.
4. Executes the backtracking algorithm (Section 3.3.1) to find the shortest path.
5. Prints out the environment and the path to be followed by robot to standard output (std::cout).
You may assume that the environment is a fixed size of 20x20, except for Milestone 4.
This assignment has four Milestones. To receive a PA/CR grade, you only need to complete Milestones 1 &
2. To receive higher grades, you will need to complete Milestones 3 & 4. Take careful note of the Marking
Rubric on Canvas. Milestones should be completed in sequence.
3
Pseudocode for the forward Search algorithm
The Manhattan distance from node p with coordinates (col p; rowp) to node G with coordinates (colG; rowG) is
computed as:
Manhattan_distance = jcolp colGj + jrowp rowGj
here jxj is the absolute value of x. The Manhattan distance represent the shortest distance from a node to
goal if there are no obstacles.
4
// Constructor/Desctructor
Node(int row, int col, int dist_traveled);
~Node();
//getter for estimated dist to goal - need to return -> Manhatten distance + distance traveled int
getEstimatedDist2Goal(Node* goal);
#define ENV_DIM 20
#define NODE_LIST_ARRAY_MAX_SIZE 4*(ENV_DIM * ENV_DIM)
/ Constructor/Desctructor
NodeList();
~NodeList();
/ Copy Constructor
/ Produces a DEEP COPY of the NodeList
NodeList(NodeList& other);
These methods let you add positions to the NodeList, and get a pointer to an existing position. Be aware,
that the NodeList class has full control over all position objects that are stored in the array. Thus, if position
objects are removed from the array you must remember to “delete” the objects.
5
3.2.6 PathSolver Class
The PathSolver class executes the two parts (forward search, backtracking) of the path planning algorithm
by using the NodeList and Node classes. It has three main components:
1. forwardSearch: Execute the forward search algorithm.
2. getNodesExplored: returns a DEEP COPY of the explored NodeList in forward search.
3. getPath: Execute backtracking and Get a DEEP COPY of the path the robot should travel. To be
implemented for milestone 3.
/ Constructor/Destructor
PathSolver();
~PathSolver();
This uses a custom data type Env, which is given in the Types.h. It is a 2D array of characters that
represents a environment using the format in Section 2. It is a fixed size, because we assume the size of the
environment is known.
It is very important to understand the Env type. It is defined as a 2D array. If you recall from lectures/labs, a
2D array is indexed by rows then columns. So if you want to look-up a position (col,row) in the environment,
you find this by env[row][col], that is, first you look-up the row value, then you look-up the col value.
The forwardSearch method is given an environment, and conducts the forward search in Section 3.2.1. Re-
member, that the initial position of the robot is recorded in the environment. Importantly, the forwardSearch
method must not modify the environment it is given. The forwardSearch method will generate a list of nodes
the robot explored (“closedList” C in pseudo-code) and will store this list of positions in the private field:
The getNodesExplored method returns a deep copy of the nodesExplored field. Be aware that this is a deep
copy, so you need to return a new NodeList object.
The implementation of getPath method is part of milestone 3 and will be discussed in detail in Section 3.3.
6
/ Read a environment from standard input. void
readEnvStdin(Env env);
==========
=S>>>>>>v=
========v=
=...v<<=v=
==.=v=^<<=
=..=>v=.==
=.===v=..=
=..==G==.=
===.======
==========
When showing the output of the path, it must show the direction in needs to be in order to get to the next
position. To represent the robot’s direction, we use the 4 symbols shown below:
7
Symbol Meaning
> Move Right
< Move Left
ˆMove Up
vMove Down.
When printing the environment, you might find it easier to first update the environment with navigation path,
and then print out the whole environment.
The milestone4.h file in the starter code has a sample method to help you dynamically allocate memory
for a 2D array.
• Change the type of the field nodes in the NodeList class to a generic 1D array of pointers:
Node** nodes;
4 Getting Started
4.1 Starter Code
We have provided starter code to help you get underway. This includes files for the classes, the Types.h and
main files, and the.
To compile your program, you will need to use a command similar to the following:
g++ -Wall -Werror -std=c++14 -O -o assign1 Node.cpp NodeList.cpp PathSolver.cpp main.cpp
8
4.2 Suggestions for starting Milestone 1
The starter code also contains a folder with one sample test case for Milestone 3. This should give you an
idea of how your tests should be formatted.
5 Submission
Follow the detailed instructions on Canvas to complete your submission for Assignment 1.
Assessment declaration: When you submit work electronically, you agree to the assessment declaration.
6 Marking guidelines
The marks are divided into three categories:
• Tests: 4/30 (15%)
• Software Implementation: 18/30 (60%)
• Code Style, Documentation & Code Description: 8/30 (25%)
The detailed breakdown of this marking guidelines is provided on the rubric linked on Canvas.
Please take note that the rubric is structured with with three “brackets”:
9
• If you do a good job on Milestone 1 & 2, then your final mark will be a CR. This will mean you have a
CR in all three rubric categories
• If you do a good job for Milestone 3, then you mark will be a DI, getting a DI in all rubric categories
• If you do a good job for Milestone 4, your mark will be a HD.
The purpose of this is for you to focus on successfully completing each Milestone one-at-a-time. You will also
notice there are not many marks for “trying” or just “getting started”. This is because this is an advanced course.
You need to make significant progress on solving the task in this assignment before you get any marks.
10