Mobile Robot Control 2024 Optimus Prime: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
Line 138: Line 138:


The pair with highest linear velocity which is best oriented towards the goal pose and maximizes the distance it must travel before it gets too close to an obstacle is preferred over others. Given the structure of the <code>main()</code> function, all the reachable velocities are tested for, and the best one is sent to the robot. Updating all relevant variable, the loop carries on until the final goal is reached.  
The pair with highest linear velocity which is best oriented towards the goal pose and maximizes the distance it must travel before it gets too close to an obstacle is preferred over others. Given the structure of the <code>main()</code> function, all the reachable velocities are tested for, and the best one is sent to the robot. Updating all relevant variable, the loop carries on until the final goal is reached.  
'''How These Functions Help DWA Coding'''
* Localization and Coordination: Functions like <code>transformOdometry</code> and <code>normalize_angle</code> ensure the robot accurately knows its position and orientation.
* Path Planning: Functions such as <code>NextPose</code> and <code>CalcClosestDistObstacle</code> are crucial for evaluating possible trajectories and avoiding collisions.
* Trajectory Evaluation: The <code>generateAllPossibleVels</code> and <code>BestVels</code> functions generate and select the best possible velocities, ensuring safe and efficient navigation.
* Obstacle Avoidance: <code>SaveXYCoordinatesObstacle</code> and <code>CalcClosestDistObstacle</code> help in mapping obstacles and ensuring that the robot does not collide with them.
* Goal Alignment: The <code>calcAngleError</code> function ensures that the robot's trajectory is aligned with its goal, improving navigation efficiency.
====Learnings from each solution====
====Learnings from each solution====



Revision as of 14:37, 7 June 2024

Introduction

We are Optimus Prime, a team of six members applying various control techniques and coding skills to optimize a robot for restaurant environments. Our goal is to enable the robot to efficiently deliver orders from the kitchen to the tables, even when faced with various obstacles. This project focuses on ensuring precise and reliable performance, ultimately improving service efficiency and the overall dining experience.

Group Members

Caption
Name student ID
Yuvan Dwaraga 1563793
Wiktor Bocian 1628798
Ramakrishnan Rajasekar 1979027
Ariyanayag Ramesh Skandan 2012618
Abhir Adiverekar 1984136
Suryakumar Hariharan 1974076

Exercise 1 - The art of not crashing

This exercise aims to enhance our understanding of control techniques and obstacle avoidance algorithms.

Simulation of the robot moving

Solution 1

The odometry and laser data were obtained based on the instructions from the manual, enabling the robot to be aware of its surroundings. Although this sensor data does not provide instructions for the robot to stop or go when an obstacle is on its way, a discussion was held to include a constant safe distance value, which ensures that the robot maintains a safe distance from obstacles and avoids collisions. Loops were also introduced as the robot operates to check whether the obstacles are close to the robot or not. Specifically, if an obstacle is detected within a certain range less than the predefined safe distance (0.5 meters) the robot will come to a halt. This algorithm ensures that the robot can navigate in its surroundings safely.

Solution 2

Advancements to the previous solution were made by introducing rotation values and forward motion values to enhance the robot's performance. These values were effective when the obstacle was too close to the robot. The stoppage of the robot comes into play and the rotation values allow it to rotate with movement restriction and later it allows the robot to move in the forward direction with constant units. This approach ensures that the robot not only stops to avoid immediate collisions but also actively seeks a safe route forward. Overall, the combination of a constant safe distance, rotation and forward actions allows the robot to perform more efficiently.

Simulation of the robot movement in x direction

Learnings from solution

The robot's performance in this case was evidenced in both simulation and practical sessions. Alterations in the code were made so that, in case of obstacle detection, the robot was made to move in the x direction in adherence to the safe distance.

Visual representation of sim

https://youtu.be/Q3MBRWl5mNM

Practical session

The live testing of the don't crash test can be evidenced by accessing the link https://youtu.be/QnT6EBChmf4




Exercise 2 - Local navigation

Moving a robot from an initial position to a goal position is done with two components: Global and Local planning. Global planning takes care of the overarching route that the robot must take to reach the final destination. Using the path planned by the global planner as a reference, the local planner ensure that the robot avoids collisions with obstacles (static or dynamic). The two types of local planners chosen to explore in this project are Artificial Potential Field (APF), and Dynamic Window Approach (DWA).

Artificial potential fields

Motivation

Choosing the artificial potential field (APF) method for the local navigation of a robot comes with several compelling motivations:

  1. Simplicity and intuitiveness: The APF approach is reasonably easy to grasp and apply. It mimics the environment using attractive and repulsive forces that naturally direct the robot to its destination while avoiding obstacles.
  2. Continuous and smooth path generation: This approach creates smooth and continuous tracks for the robot without any jerks. Because the forces are computed as gradients of potential fields, the resulting motion is smooth, avoiding the possibility of sudden changes in direction that would be difficult for the robot to perform.
  3. Scalability: APF is easily adaptable to many types and sizes of settings (environment). The approach may be adjusted to a variety of circumstances by modifying the potential field parameters, ranging from basic inside navigation to more difficult outdoor settings.
  4. Combination with Other Methods: APF may be utilized effectively with other navigation systems. For example, it may be used for local navigation inside a larger framework that handles global path planning, integrating the benefits of several frameworks.
  5. Computation time: This method is much less computationally intensive than other ones.

Solutions

  1. Converting the body fixed frame into global coordinates To implement this the transformedOdometry() function was created which was used to convert the odometry data of the robot into the global coordinate system.
  2. Normalizing the angle The normalize_angle() function ensures that any given angle is mapped to an equivalent angle within the standard range of −π to π radians. This is useful because angles can be represented in multiple ways (e.g., 3π is the same as π), and having a consistent representation simplifies many calculations and comparisons.
  3. Calculating attractive forces The attraction_force() function calculates a linear attractive force towards a target position. This force is proportional to the distance between the current position and the target position, scaled by an attraction coefficient. The formula used for calculating attractive forces - [math]\displaystyle{ F_{\text{att}}(\mathbf{q}) = k_a (\mathbf{q}_{\text{goal}} - \mathbf{q}_{\text{current}}) }[/math] where, [math]\displaystyle{ k_a }[/math] is the attraction gain. [math]\displaystyle{ \mathbf{q}_{\text{goal}} }[/math] is the goal position. [math]\displaystyle{ \mathbf{q}_{\text{current}} }[/math] is the current postion of the robot
  4. Calculating repulsive forces The repulsion_force() function calculates a repulsive force that acts to push a point (or robot) away from an obstacle when it gets too close. The force is designed to be strong when the point is very close to the obstacle and diminishes as the point moves away, ensuring safe navigation around obstacles. The formula used for calulating the repulsive forces - [math]\displaystyle{ F_{\text{rep}}(\mathbf{q}) = \begin{cases} k_{\text{rep}} \left( \frac{1}{\|\mathbf{q}\|} - \frac{1}{d_{\text{safe}} + m_{\text{safety}}} \right) \left( \frac{1}{\|\mathbf{q}\|^2} \right) & \text{if } \|\mathbf{q}\| \lt d_{\text{safe}} + m_{\text{safety}} \\ 0 & \text{if } \|\mathbf{q}\| \geq d_{\text{safe}} + m_{\text{safety}} \end{cases} }[/math] where, q is the distance. [math]\displaystyle{ d_{\text{safe}} }[/math] is the safe distance [math]\displaystyle{ m_{\text{safety}} }[/math] is the extra margin. [math]\displaystyle{ k_{\text{rep}} }[/math] is the repulsion gain

Learnings from each solution

While the artificial potential field (APF) approach has significant benefits for robot navigation, it also has certain drawbacks, such as the possibility of being caught in local minima or oscillations. To address these concerns, many fixes and improvements to the APF approach have been proposed:


Gradient Descent with Escape Strategies: One typical problem with APF is getting stuck in local minima when the attractive and repulsive forces cancel out.

Solution: Random Walks or Perturbations - By introducing small random movements or perturbations, the robot can escape local minima. To come out of the local minima random perturbations were added in the APF algorithm and it was successful at the end.


Combination with Global Path Planning: Integrating APF with a global path planning algorithm can provide a more comprehensive navigation solution.

Solution: Hybrid Approaches - Finding a rough path with a global planner such as A* or Dijkstra's algorithm, and then using APF for local navigation to fine-tune the path and avoid obstacles.

Testing and tuning

Initially, the robot was not given a maximum velocity that it can achieve while moving using using artificial potential fields algorithm. This approach worked in simulation well with the robot getting to the end position with a smooth trajectory. However, when testing in practice this proved to be insufficient, since the robot always just drove into obstacles, because it couldn't rotate fast enough. To avoid that behavior and make sure the robot has enough time to avoid the obstacle extra guard for the maximum linear velocity of the robot was added. This method led to less smooth trajectories however it ensured that both in simulation and in practice robot does not hit obstacles.

Furthermore, when testing different gains for the APF, it was found that for some maps it was stuck in the local minima. This is typical for this method, however, to check if by further tuning the goal can be reached on all the given maps parameters were tuned (attractive gains and repulsive gains) for each map and after implementing this strategy the robot was able to complete the task in every scenario.

Visual representation of sim

  1. Map 1 - https://www.youtube.com/watch?v=PWZg0-T9-U8
  2. Map 2 - https://www.youtube.com/watch?v=E6Xz24zsPdE
  3. Map 3 - https://www.youtube.com/watch?v=ZnRjnttkkrE
  4. Map 4 - https://www.youtube.com/watch?v=ERdRPLcliLk

For the first three simulations, the parameters were the same, but for the fourth simulation, the parameters were a bit different.

Practical video

  1. Map 1-https://youtube.com/shorts/2iPmLHOHZgY?feature=share
  2. Map 2-https://youtube.com/shorts/V9yEWU9jpt0?feature=share
  3. Map 3-https://youtube.com/shorts/jpvrOMJoCuI?feature=share
  4. Map 4-https://youtu.be/s8pXRdhEtTc
  5. Map 3 with a dynamic moving obstacle (most recent) -

Dynamic window approach

Dynamic Window Approach (DWA) is a dynamic velocity-based approach wherein the best combination of linear and angular velocity is sent to the robot every iteration. In this application, an iteration is initiated every time the LIDAR sensor logs new data. This section details the DWA algorithm as well as its implementation.

Working principle and motivation

Given that DWA is a velocity based approach, it is important to define the range of velocities that is possible for the robot to achieve for both the linear and angular cases. Realistically, not all the possible velocities might be reachable due to acceleration constraints, so it is required to define the maximum linear and angular deceleration of the robot. For all the velocities that are admissible, and reachable, the algorithm choses the best combination from a cost function which accounts for the orientation of the robot with respect to the goal, the distance to obstacles. Another term is included in the cost function which prioritizes high velocities. Once the best combination is sent to the robot at the end of the first iteration, it is important to note that the reachable velocities (from the current) will change. Hence, the search space of velocities  will dynamically evolve each iteration. The algorithm will remain active until the desired position is reached. While the algorithm might be computationally heavy, it is relatively easy to comprehend, implement. And since it can also be easily expanded to a global planner, DWA algorithm is chosen to implement as the second local path planner.

Implementation

As mentioned above, the velocity and acceleration constraints for both the linear and angular cases must be defined first. The set of all possible velocities is generated according to:

[math]\displaystyle{ V_S = \{v, \omega \mid v \in [v_{\text{min}}, v_{\text{max}}] \wedge \omega \in [\omega_{\text{min}}, \omega_{\text{max}}]\} }[/math]

Implementation wise, the all_possible_velocities() function is used which takes as inputs the maximum velocity, and the number of samples. The velocities are discretized based on (Max_vel/samples) and stored as floats in a vector. This function is called twice, once for the linear case and also for the angular case. The implementation ensures that linear velocities are always non-negative, while angular velocities can be either positive or negative. All possible combinations of velocities from the two sets are checked for reachability based on the current velocity of the robot and the acceleration constraints within a predefined timestep. The following formula is used to check reachability.

[math]\displaystyle{ V_d = \{v, \omega \mid v \in [v_a - \dot{v}t, v_a + \dot{v}t] \wedge \omega \in [\omega_a - \dot{\omega}t, \omega_a + \dot{\omega}t]\} }[/math]

Here, va and wa correspond to the pair of velocities for which the reachability is tested for. Only if a pair is reachable, it is checked if the pair is also admissible such that it avoids running onto obstacles if sent to the robot within the next timestep. A modification of one of the SUVAT equations is used to check admissibility. This is shown below:

[math]\displaystyle{ V_a = \{v, \omega \mid v \leq \sqrt{2d(v, \omega) \dot{v}_b}} \wedge \omega \leq \sqrt{2d(v, \omega) \dot{\omega}_b\} }[/math]

Here, d(v,w) is the distance to the obstacles measured by the LIDAR sensor, vbd and wbd are the maximum linear and angular accelerations. The guard imposed checks if each of the reachable velocities will travel more than the distance to the closest obstacle if a certain pair is assigned to the robot. To compute the admissible velocities, it is important to calculate the distance to the closest obstacle. This is done using the min_dist_to_obj()function which takes in as input the coordinates of all measurements by the LIDAR sensor in the map frame, the current pose, and each of the reachablevelocity pair. This function iterates over N time steps calculating its future pose using the input velocity pair, and calculates the distance to each obstacle in each of these discretised time steps. Over these time steps, if the distance to any of the obstacle is less than a limit, it calculates the minimum distance it must travel(from current pose) before it gets too close to the limit. This function gives the minimum distance the robot has to travel before it is very close to the obstacle. In fact, this limit is set such that the robot’s dimensions are also accounted for. The reachable pairs that satisfy the kinematic constraint imposed will proceed for cost calculations which is used to identify the best pair. The cost function considers the heading direction of the robot, its distance to the closest obstacle that prioritizes high linear velocities. The expression below shows the cost function design for this application:

[math]\displaystyle{ G(v, \omega) = \sigma(k_h h(v, \omega) + k_d d(v, \omega) + k_s s(v, \omega)) }[/math]

Kh, Kd, and Ks are gains that balance the three components relative to one another. H(v, w) calculates the heading direction, d(v, w) measures the distance the robot can travel before approaching too close to the nearest obstacle, and s(v, w) is the function that favors high velocities. The Next_Pose()function is used to compute the pose of the robot one time step into the future which takes the current pose, the time step, and a velocity pair as inputs. This future pose, the final goal pose, and the current yaw orientation are used in the Header_Error()function which computes the relative difference in orientation to the final goal when a pair is chosen. When computing the reward function, the heading angle is normalized between -pi and pi degrees. The high velocity prioritization term normalizes the velocity with respect to the maximum linear velocity.

The pair with highest linear velocity which is best oriented towards the goal pose and maximizes the distance it must travel before it gets too close to an obstacle is preferred over others. Given the structure of the main() function, all the reachable velocities are tested for, and the best one is sent to the robot. Updating all relevant variable, the loop carries on until the final goal is reached.

Learnings from each solution

  1. While the Dynamic Window Approach (DWA) is effective for robot navigation, it also faces certain challenges. Here are three common problems that were faced during Implementation:
  2. Local Minima: DWA can get stuck in local minima, particularly in complex environments where optimal paths are not available we introduced recovery behaviours such as random perturbations or backtracking. Combine DWA with global path planning algorithms to guide the robot out of local minima.
  3. Handling Dynamic Obstacles: DWA may struggle with many obstacles within a small space and recalculations that can be computationally demanding we tried implementing predictive modelling for dynamic obstacles, allowing the algorithm to anticipate and react to future positions of obstacles.
  4. Parameter Tuning: DWA performance heavily depends on parameter tuning, such as velocity bounds and acceleration limits we tried implementing adaptive tuning techniques that adjust parameters dynamically based on the robot's position.

Visual representation of sim

  1. Map 1-
  2. Map 2-https://youtu.be/pB4MbaJzdcg
  3. Map 3-
  4. Map 4-

Practical video

  1. Map 1-https://youtube.com/shorts/-xgMeAtbdBQ?feature=share
  2. Map 2-https://youtube.com/shorts/nsv2eGVvw7o?feature=share
  3. Map 3-https://youtube.com/shorts/1eL7xdEf0vs?feature=share
  4. Map 4-

Assignment questions - Rough draft

  1. What are the advantages and disadvantages of your solutions?
    1. Artificial Potential fields:
      • Advantages
        1. Simplicity: The APF approach is straightforward to implement and understand. It uses simple mathematical functions to represent attractive forces towards the goal and repulsive forces away from obstacles.
        2. Real-time Computation: APF algorithms are computationally efficient, making them suitable for real-time applications. The computations involved are minimal and can be handled by most modern processors with ease.
        3. Scalability: APF methods can be scaled to handle different sizes and types of robots without significant modifications to the algorithm.
      • Disadvantage
        1. Local Minima Problem: One of the significant drawbacks of APF methods is the local minima problem, where the robot can get stuck in a position that is not the goal due to equal attractive and repulsive forces cancelling each other out.
        2. Inability to Handle Complex Environments: APF methods may struggle with complex environments with narrow passages or multiple closely spaced obstacles, leading to suboptimal or infeasible paths.
        3. Parameter Tuning: The performance of APF methods heavily depends on the tuning of parameters such as the strength of attractive and repulsive forces. Improper tuning can lead to inefficient navigation or failure to reach the goal.
    2. Dynamic Window Approach:
      • Advantages
        1. Dynamic Feasibility: DWA accounts for the robot's dynamic constraints (like velocity and acceleration) ensuring that the generated paths are feasible and safe for the robot to follow.
        2. Collision Avoidance: The algorithm effectively avoids collisions by evaluating possible trajectories within a feasible velocity window.
        3. Real-time Feedback: DWA computes in real-time, making it suitable for applications where the robot needs to react quickly to changing environments.
        4. Smooth Path Generation: It generates smooth and continuous paths, which are essential for the stable and efficient movement of robots.
      • Disadvantages
        1. Computational Load: DWA evaluates numerous possible trajectories within each window, which can become computationally intensive, especially in environments with many obstacles.
        2. Local Minima Problem: Like APF, DWA can get stuck in local minima, particularly in complex environments where optimal paths are hard to find.
        3. Handling Dynamic Obstacles: DWA adapts to dynamic environments but may struggle with fast-moving obstacles, requiring frequent recalculations that can be computationally expensive
  2. What are possible scenarios which can result in failures (crashes, movements in the wrong direction, ...) for each implementation? For example, set the target position in an obstacle and let the robot try to get to the target; what happens? Try to think of more examples yourself!
    1. Artificial Potential Fields:
      • Crash
        1. If the target position is set inside an obstacle - The robot collides with the obstacle repeatedly as it tries to get as close as possible to the goal.
        2. Not initializing the maximum velocity - The robot follows the path and once it detects the obstacles, it droves into the obstacle and crashes.
        3. Less repulsive force - The robot is confused with the less repulsive force and safe distance ultimately crashing into obstacles
      • Movement in the wrong direction
        1. Poor tuning of the values - The robot makes an oscillatory behaviour by moving back and forth between obstacles and is unable to make a decision.
      • Repeated movement
        1. Local minima - The robot gets trapped in a local minimum where the attractive and repulsive forces balance out to zero. It makes a constant circular movement wasting energy.
    2. Dynamic Window Approach:
      • Crash
        1. If the target position is set inside an obstacle - The robot collides with the obstacle repeatedly as it tries to get as close as possible to the goal.
        2. Moving obstacles - The robot fails to avoid fast-moving dynamic obstacles effectively, especially if the other entities are moving unpredictably, leading to a crash.
      • No movement
        1. Dead end - The robot encounters a narrow passage that is difficult to navigate due to its velocity and acceleration constraints. The DWA may fail to find a feasible velocity that fits through the narrow opening, causing the robot to get stuck.
  3. How would you prevent these scenarios from happening?
    1. Artificial Potential Fields:
      • Crash
        1. Target position and obstacle - Use a map of the environment to ensure the target is in a free space and not inside an obstacle.
        2. Maximum velocity -Always initialize and cap the robot's maximum velocity based on the environment's characteristics and the robot's specifications. Implement obstacle detection and dynamic re-planning to slow down or stop when obstacles are detected.
        3. Repulsive force - Adjust the repulsive force parameters through careful calibration so that the robot maintains a safe distance from obstacles without causing instability.
      • Movement in the wrong direction
        1. Tuning the values - Use a systematic approach to tune the attractive and repulsive parameters. Implement adaptive parameter tuning algorithms that adjust parameters in real time based on the robot's performance and the environment.
      • Repeated movement
        1. Local minima - - By introducing small random movements or perturbations, the robot can escape local minima.
    2. Dynamic Window Approach:
      • Crash
        1. Target position and obstacle - Using an occupancy grid or another mapping technique to validate goal positions before the robot starts moving towards them.
        2. Moving obstacles - Incorporate algorithms that can model and anticipate the trajectories of moving obstacles. This might include machine learning models or probabilistic approaches to predict future positions of dynamic obstacles and adjust the robot's path accordingly.
      • No movement
        1. Dead end - Improve the DWA by incorporating global path planning algorithms that can recognize dead ends and provide alternative routes. Additionally, enhances the local planning aspect of DWA to better handle narrow passages by fine-tuning velocity and acceleration constraints and implementing more sophisticated search techniques within the dynamic window.
  4. For the final challenge, you will have to link local and global navigation. The global planner will provide a list of (x, y) (or (x, y, θ)) positions to visit. How could these two algorithms be combined? (Implementing this will be part of next week's assignment.)
    • Hybrid Approaches - Combine APF and DWA with other navigation strategies. Use a global path planner like A* or Dijkstra's algorithm for long-term planning and APF or DWA for local, real-time adjustments. This can help mitigate the weaknesses of each method. This would be done by first computing the optimal path using global navigation algorithm and sending the position of certain points along this path to the robot. When one of those points is reached or the robot is in proximity of it the goal of the local planner would be updated to the next sub-goal along the path. This way the local navigation algorithm can avoid extra obstacles that can be present that were not placed on the map.

Exercise 3 - Global Path Planning

A* algorithm

A* algorithm is used to determine the shortest path from the start node to the goal node through the known network of nodes and their connections. It initializes the _nodelist() which contains all the nodes and the connection data generated by the PRM algorithm. During each iteration, the next node in the connection of the current node is chosen based on the minimum cost (f) to reach the goal. (i.e.) the sum of cost-to-come and cost-to-go (heuristic cost). This cost represents the absolute distance between the node being evaluated and the goal node. The algorithm iterates until the goal node is reached and all open nodes have been evaluated.

  • Node with minimum f

The node with a minimum f value from the list of open nodes is selected. The variable 'nodeID minimum f' is initialized to signify that no node has been identified yet. The 'minimum_f' variable is initialized to infinity assuming that the actual 'f' value will be from the nodes will be finite and lower when iteration starts. Subsequently, a for-loop iterates over all node IDs in the 'open nodes' container. For each node, it retrieves the 'f' value from the '_nodelist' vector storing nodes. If the 'f' value of the current node is less than the recorded minimum, 'minimum f' is updated with the new lower value and 'nodeID minimum f' will be set to the current node's ID.

  • Exploring the node connections

Exploration of node connections is iterating over nodes connected to the current node, verifying if they have already been evaluated (in the 'closed nodes' list). For each unprocessed adjacent node, it computes a new cost-to-come ('g') as the sum of the current node's 'g'(value) and the distance between both nodes. If this new 'g' is lower than the adjacent node's existing 'g', the node's 'g', heuristic estimate ('h'), and total cost ('f') are updated, and its parent is set to the current node. If the adjacent node isn't in the 'open nodes' list, it is added for subsequent evaluation. After processing all connections, the current node is moved to the 'closed nodes' list, marking it as evaluated. This ensures that the search focuses on the path with the optimal cost, efficiently guiding the search towards the goal.

  • Trace back the optimal path

The final step involves tracing back the optimal path, As soon as the goal node is reached the algorithm starts tracing the optimal path. It begins at the goal node and works backwards using the 'parent node ID' of each node, which points to the preceding node on the optimal path. In the loop, the current node ID is appended at the beginning of the 'path node IDs' list within a loop, constructing the path from start to goal. This backtracking persists until it reaches the start node, which is then added to the list. Once the path is fully identified, the list of node IDs is stored and the algorithm marks the path as successfully found. This ensures that the shortest path is clearly outlined and can be utilized by the respective local planner to navigate towards the goal while avoiding obstacles.

Inflated walls with dilation size equal to 1

Probabilistic Road Map (PRM)

To implement the path planning algorithm, a preliminary step involves generating a set of potential paths on the map that will be used to find an optimal path. The Probabilistic Roadmap Method (PRM) serves this purpose by generating connections between randomly positioned points on the map.

  • Wall inflation

In the process of wall inflation, the walls on the map are expanded to mitigate the risk of collision for the robot, which occupies more space than a point. This inflation is achieved through dilation on the map image. To do that, the map colours are first inverted since dilation works on white parts of the binary image. It is done by specifying the type and size of the Kernel that is used to check if there is a white point inside it and if there is such a point it changes the other ones inside the kernel to this color. For the desired implementation the square kernel is being used since all of the maps mostly consist of straight lines and the size of this kernel can be adjusted by changing the dilation size variable.

Inflated walls with dilation size equal to 2

After the dilation, the map is reverted to its original color scheme and examples with different kernel sizes can be seen on the Figures.

  • Distance from other points

To ensure a more even distribution of points across the map, the distance between newly generated vertices and previously existing ones is checked. This is done by verifying the difference between the x and y coordinates of each vertex exceeds a predefined threshold which is no smaller than 0.3 meters. Thus, each vertex occupies a distinct 0.3x0.3 meter area without overlapping with neighboring vertices.

  • Check for valid edge

To verify if the vertex is valid, two checks are done. First verification is to ensure only the vertices that are relatively close to each other are connected and the distance between them is being checked. This is done by computing the absolute value of a difference between the x and y variables of 2 vertices and then taking a square root of a sum of those values squared, which allows us to compute the distance between them in a straight line.

Another crucial validation step involves checking for the presence of walls between two nodes. This is done by using Bresenham's algorithm to create a line between the two points of interest. By generating all points along this straight line, the algorithm detects any instances of a black point, indicating the presence of a wall obstructing the path. In such cases, the line is deemed invalid and consequently, the edge connecting the two nodes is not established. This algorithm works by calculating the difference between the x and y positions along the line and its final destination. Subsequently, the difference in y is subtracted from the difference in x and doubled to ensure integer operations. This algorithm provides insights into the deviation of the generated line from the ideal straight line connecting the two points. If this error exceeds the difference in the y coordinate, adjustments are made to render the lines less horizontal. A similar process is applied to the x coordinate.

This approach ensures the identification of obstacles between nodes, thereby guaranteeing a path between the generated network of nodes. By systematically validating edge connections, the algorithm effectively constructs a representation of traversable paths on the map, essential for efficient path planning and avoiding collisions with obstacles.

Example

Example of the map created using the probabilistic roadmap

To test the algorithm the example map was used with several vertices equal to 70, and a dilation size equal to 2 which means that (5,5) square kernel was used for dilation and a maximum distance between two edges of 1 m was created and can be seen on the Figure.

Assignment questions

  1. How could finding the shortest path through the maze using the A* algorithm be made more efficient by placing the nodes differently? Sketch the small maze with the proposed nodes and the connections between them. Why would this be more efficient?
    • The A* algorithm functions by systematically searching through nodes within a graph to identify those offering the shortest path from the start node to the end goal. Firstly, By reducing the number of nodes, both storage space utilization within the node_lists() and computational demands can be minimized as the algorithm will have fewer nodes to evaluate. This can be done by placing the nodes strategically at places where there are junctions, ends or where paths diverge in the maze. Focusing on these critical junctures ensures that the algorithm concentrates its evaluation efforts on nodes to path determination. As a result, the algorithm's efficiency is enhanced, enabling more streamlined pathfinding through the maze.
  2. Would implementing PRM in a map like the maze be efficient?
    • Yes, Utilizing Probabilistic Roadmap (PRM) in a maze-like environment can indeed offer efficiency, particularly in scenarios where the maze and has many obstacles to tackle. PRM uses a approach of sampling nodes which are more useful to find possible paths around the obstacles. However, it is worth noting that while PRM excels in such environments, the reliance on numerous sampling nodes can lead to increased storage requirements and computational demands. In instances where the maze features relatively straightforward passages or corridors, the abundance of nodes generated by PRM may not be necessary. In these cases, it is more efficient and practical to position nodes strategically at pivotal points within the maze. This ensures that computational resources are allocated where needed the most and focusing efforts on evaluating nodes at key decision points. Thus, while PRM offers valuable capabilities in negotiating complex mazes, careful consideration must be given to balancing its benefits with the associated storage and computational costs.
  3. What would change if the map suddenly changes (e.g. the map gets updated)?
    • In case the map changes, the robot has certain time to try to reach the next node. In case if the time exceeds before reaching the node the robot will hold onto its current position and initiate a function which sets the parent_node_ID of the unreachable node as a new _start_nodeID and discards all the connections to the unreachable node. Further, initiating pathplan() again to plan a new path with a new start node and a same end goal. Once a new path is generated the local planner is initiated again to follow new path until it reaches the goal. This will help whenever there is an unexpected obstacle in the path or the way is blocked and also to escape when the robot gets stuck in a local minima while using AFP local planner.
  4. How did you connect the local and global planner?
    • When seen conceptually, the local planner uses the global planner as an input or guide to reach a given goal from its starting point. Global planner uses PRM or the grid map algorithm to explore and plot the feasible nodes with connections between them throughout the map forming networks and potential paths and stores it. These are used by the A* algorithm to find the most optimal path by evaluating each node connection and the result is stored in a structured path_node_ID() list. Whereas the local planner retrieves this list from "planner.h". Then planner algorithm sets the initial node in the list as the target node and continuously updates its target node coordinates (Target_x, Target_y) to the next node in the list. This is updated when the robot reaches within a predefined safe distance of the current target node, as soon as the robot reaches the goal node (last item in the list) the target node updating loop is terminated.
    • Conceptually, the connection between the local and global planners is implemented in a manner where the local planner utilizes the global planner as a reference or guide to navigate from its initial position to a designated goal. the global planner implements techniques like Probabilistic Roadmap (PRM) or grid map algorithms to explore the map, identifying feasible nodes and establishing connections between them to form networks and potential paths. These paths are then stored for retrieval. Subsequently, the A* algorithm is utilized by the global planner to determine the most optimal path by evaluating each node connection. The resulting optimal path is structured and stored in a list known as "path_node_ID()". In the implementation of the local planner, this list is retrieved from "planner.h". The local planner algorithm sets the initial node in the list as the target node. Continuously, it updates the coordinates of the target node (Target_x, Target_y) to the next node in the list. This updating occurs when the robot approaches within a predefined safe distance of the current target node. Upon reaching the goal node (the last item in the list), the loop for updating the target node is terminated. This synchronization between the local and global planners ensures that the robot effectively follows the optimal path generated by the global planner while navigating towards the goal, thereby facilitating efficient and safe navigation within the environment.
  5. Test the combination of your local and global planner for a longer period on the real robot. What do you see that happens in terms of the calculated position of the robot? What is a way to solve this?
    • It was observed that the actual position of the robot was not exactly equal to what the odometry data shown. This could be due to the slip of wheels while turning and was observed more when angular velocity was high. For now, this slip can be avoided by lowering the angular velocity and avoiding jerks. Also, Localization will help to solve this issue by identifying the exact location of the robot in the environment.
  6. Run the A* algorithm using the grid map (with the provided node list) and using the PRM. What do you observe? Comment on the advantage of using PRM in an open space.

Testing

Simulation

Physical setup

Global + Local (Artificial potential fields): https://www.youtube.com/watch?v=__dvgxrpebI

Global + Local (Artificial potential fields) with the moving obstacle: https://www.youtube.com/watch?v=6UgUIg0o0kk

Exercise 4 - Localization

Assignment 0.1

1. How is the code structured?


2. What is the difference between the ParticleFilter and ParticleFilterBase classes, and how are they related to each other?

Particle filter inherits from the ParticlefilterBase class which gives it access to the members of PatricleFilterBase. In the ParticleFilterBase, the particles are initialized, and then their average positions are computed. It also uses the computeLikelihood() function that provides a weight for each of the LIDAR data points which is used to compute the average pose of the robot. While in the particleFilter, multiple resampling methods can be defined and used.

3. How are the ParticleFilter and Particle class related to each other?

The ParticleFilter class consists of the information about all the particles that are created by the particle filter and this data can be used to estimate state of the system. Particle class, however consists of information about a singular particle and has several information about it like the position and its weight.

4. Both the ParticleFilterBase and Particle classes implement a propagation method. What is the difference between the methods?

The Particle class propagates the particle position of a singular node using the odometry and noise data for each particle individually. While the ParticleFilterBase propagates all particles by iterating over each of the paritcles.

Assignment 0.2

The figure to the right depicts that all test cases are passed when running the Localization code after including code form the other assignments.

Ass. 1.1 Initialization of the particle filter

Assignment 1.1- Initialization

What are the advantages/disadvantages of using the first constructor, what are the advantages/disadvantages of the second one?

The first constructor uses a uniform distribution to initialize the particle by creating the particles around the initial guess area, while the second one uses Gaussian distributions to do the same.

Uniform constructor

Advantages:

  • Spread over the entire map allows the robot to find its position even when there is no initial estimate and the robots previous position was unknown.

Disadvantages:

  • Computationally inefficient- many particles may be placed in unrealistic positions that have low likelihood of being the robots actual position. It may also need more particles to find the robots position.

Gaussian constructor

Advantages:

  • The particles are more concentrated around the initial guess area, which in the case of good initial estimate gives more particles around the real position of the robot.
  • Computationally efficient- less particles needed to find the robot position if the previous position had a good guess.

Disadvantages:

  • If the robot loses its position or the initial guess is wrong the Gaussian constructor may lead to the robot not being able to find its actual position this is due to the fact that the robot may have traveled to far from the previous known location.


In which cases should either of them be used?

Ass. 1.2 Pose estimate

If there is a good initial guess the Guassian particle should be used this is due to the fact that hen most of the particles would be around the robots actual position which would allow the robot position from the particle filter to converge much faster. However, the uniform constructor still has its use, if the initial position on the map is unknown it spreads particles around the entire map which allows the particle filter to converge to the certain position which would be impossible when using the Gaussian constructor.

Assignment 1.2- Pose estimate

Interpret the resulting filter average. What does it resemble? Is the estimated robot pose correct? Why?

The resulting filter average is shown by the green arrow on the Figure to the right. It shows the position computed using the weighted average of the particles created using the Gaussian constructor and gives the psosition and rotation of the robot. It is close to the initial guess of the particle filter and because of that it is shifted relative to the actual position of the robot, since position of the initial guess was not exactly the same as robots position on the map.


Imagine a case in which the filter average is inadequate for determining the robot's position.

If there are similar environmental features in a map that are present at different ends or far away from each other, then the particles will be distributed near both these positions. In this scenario the average will be in between the two features which completely does not resemble the true robot position. The computed average robot position would be placed in between those two areas where the particles are concentrated and not in one of those two positions.

Assignment 1.3- Propagation of particles

Why do we need to inject noise into the propagation when the received odometry information already has an unknown noise component?

the sensor measurement is not accurate so we add noises to get more data and we compare it with the Gaussian distribution to get more sample data which has similar properties.


What happens when we stop here and do not incorporate a correction step?

If the correction step is not done, then the initially created particles propagate continuously which leads to multiple particles indicating positions that have a low likelihood that do not help with localization. This is computationally demanding even though it does not give reasonable approximations.


Video-

Assignment 2.1- LiDAR correction

In the measurement model all the components of measurement model are guarded by the max range, in reality, in both simulation and practical test it became apparent that lidar can give the value as infinity for the range and because of that the likelihood of the particle would be zero since we multiply with the likelihood with another particle, if one particle is out of range it will get the likelihood to out of range or as infinity. because of this, an if statement was added which checks the range value of each laser data, if it were higher than the max range this value was overwritten to the max range.


What does each of the components of the measurement model represent, and why is each necessary.

Measurement model consists of 4 different components:

  • Gaussian Distribution - From the map the expected range that the LiDAR would read is known this value is represented with the Gaussian distribution. Thanks to the bell shape of this distribution it also accounts for potential noises and inaccuracies of the reading since it also assigns higher likelihood to the particles that are close to the expected distance, but are not exactly the same.
  • Exponential component - There is a chance that an unexpected obstacle that is not present on the map can be seen by the LiDAR. This may be a new static object or a person passing by. In this scenario a lower reading than expected from the map is given by the LiDAR. The exponential guess is used to compute likelihood of the particle in these scenario. Thanks to it the readings that are lower than the ones expected from the map are also considered when computing the likelihood of the particle.
  • Uniform component - LiDAR can have some noise which leads to unexpected readings. Those are accounted for in the uniform distribution that assigns the probability to the reading over the entire range of the LiDAR without it even one inaccurate reading could lead to the likelihood of the particle being 0.
  • Uniform component for max range - This components is used to account for the readings that are returned when the LiDAR doesn't hit an obstacle inside its range. FUrthermore, during testing on physical setup and in the simulator LiDAR returned the range of inf those values where also accounted for by changing those readings to the value of max range.


With each particle having N >> 1 rays, and each likelihood being ∈ [0, 1], where could you see an issue given our current implementation of the likelihood computation.


Assignment 2.2- Resampling

What are the benefits and disadvantages of both the multinomial resampling and the stratified resampling? Multinomial resampling

Multinomial resampling

Advantages:

Disadvantages:

Stratified resampling

Advantages:

Disadvantages:


Video-

Assignment 2.3- Physical setup test

How you tuned the parameters.

With initial parameters that were given the particle filter had a negative impact on the robots performance the localization was updating quite fast on the visualization but sending commands via teleop was much slower and there was a big delay between the command and actual movement. Because of the limited amount of time that the group had available only the particle number was decreased to 1500. This change increased the performance of the robot drastically. However, more tuning may still be needed before the final assignment to see how accurate the initial guess needs to be especially since this will have an impact on how well the robot can do any of the tasks.


How accurate and fast your localization is, and whether this will be sufficient for the final challenge.

The accuracy of localization is quite high as can be seen in the video below. However the exact value was not quantified. But as shown on the video the robot position correlates the position on the map and it is also updated in the real time. However via further testing other sampling schemes can be tested if it becomes even faster.

How your algorithm responds to unmodeled obstacles.

As mentioned before only a limited time for testing the localization was available so no tests with unmodeled obstacles were conducted. However if there are unmodeled obstacles the exponential component of the measurement model should handle them if this will not be the case the weight of this component will need to be adjusted.

Video- https://www.youtube.com/watch?v=pfD3A7Y9ox8