Showing posts with label Writing. Show all posts
Showing posts with label Writing. Show all posts

Monday, October 28, 2024

SLAM! - The Basics

[Note: this article is mostly a conversation I had with an AI. I likeed the output, so I am including it here. It may not be the most genuine of blog posts, but it is something I will refer back to, so I am sharing it with you as well.]

A Simple SLAM Simulation

SLAM, which stands for Simultaneous Localization and Mapping, is a critical concept in robotics, especially in autonomous systems where the robot must navigate through an unknown environment. Here’s a detailed breakdown of the basic components and methods involved in SLAM:

What is SLAM?

SLAM is the process by which a robot can:

1.  Map an Environment: Create a representation (usually a 2D or 3D map) of an unfamiliar area.

2.  Localize Itself: Determine its own position within that map, in real time.

SLAM is a solution to the "chicken and egg" problem of robotics: To map the environment, a robot needs to know where it is, but to know where it is, it needs a map. SLAM solves both tasks simultaneously.


Key Components of SLAM

1. Sensors: 

   - Lidar: Light Detection and Ranging (uses laser beams to measure distances).

   - Cameras: Visual or stereo cameras for Visual SLAM (VSLAM).

   - Ultrasonic Sensors: Simple but effective for obstacle detection.

   - IMUs (Inertial Measurement Units): Track orientation and movement changes.

   - Encoders: Simple but effective for tracking movement changes.


2. State Estimation: 

   - Pose: Position (x, y, z) and orientation (yaw, pitch, roll) are estimated continuously.

   - Common methods for estimating this are Kalman Filters or Particle Filters. For complex non-linear systems, the Extended Kalman Filter (EKF) or Unscented Kalman Filter (UKF) is often used.


3. Mapping:

   - The robot gathers spatial information about obstacles and free space.

   - Maps are usually grid-based (like occupancy grids) or feature-based. 

   - Occupancy Grid Mapping divides space into a grid of cells, marking each cell as occupied, free, or unknown.


4. Loop Closure: 

   - The robot must recognize a location it has visited before, called loop closure.

   - Without recognizing these loops, errors can accumulate, leading to an inaccurate map.

   - Visual features, like walls or landmarks, are often used for loop closure.


Mathematical Foundations

1. Probabilistic Approach:

   - SLAM typically involves Bayesian Estimation. A robot's state is represented as a probability distribution that evolves as new data arrives from the sensors.

   - Bayes Filters and Markov Localization are used to manage the uncertainty of sensor data and robot motion.


2. State-Space Representation:

   - The SLAM problem can be represented in terms of states and measurements, where states represent robot and feature positions and measurements represent distances and angles to landmarks.

   - The sensor model and motion model help update the robot’s understanding of the environment.


Approaches to SLAM

1. Kalman Filter-Based SLAM:

   - The Extended Kalman Filter (EKF) SLAM is one of the earliest methods.

   - It’s efficient but suffers from scalability issues in large environments due to the computational cost of updating a large covariance matrix.


2. Particle Filter-Based SLAM:

   - Also called Monte Carlo Localization (MCL).

   - Uses particles to represent possible positions of the robot. It’s highly robust for non-linear problems and can handle multi-modal distributions better than EKF.


3. Graph-Based SLAM:

   - The problem is represented as a graph, where nodes represent robot poses and landmarks, and edges represent constraints between them (from sensors).

   - After creating the graph, optimization is used to adjust all nodes, effectively minimizing the error in both localization and mapping.


4. Visual SLAM (VSLAM):

   - Uses cameras to detect visual landmarks. ORB-SLAM (Oriented FAST and Rotated BRIEF) is a popular implementation.

   - Visual SLAM can use either monocular or stereo cameras. Stereo cameras provide depth information directly, while monocular cameras infer depth using techniques like feature triangulation over time.


Mapping Techniques

1. Occupancy Grid Mapping:

   - The environment is divided into a discrete grid where each cell holds a probability of being occupied.

   - Updates occur using sensor data and can be represented by Bayes’ rule.

2. Feature-Based Mapping:

   - Instead of dividing space into grids, the system identifies key features or landmarks (corners, edges, unique patterns) and tracks them.

   - It’s computationally efficient in sparse environments.

3. Octomap (3D Occupancy Grid Mapping):

   - Uses octrees to create maps that efficiently represent 3D environments.


Challenges in SLAM

1. Sensor Noise: Every sensor has inherent noise that needs to be filtered out.

2. Motion Model Uncertainty: The real-world movements of robots have slippage and drift, leading to deviations between intended and actual motion.

3. Loop Closure Errors: If not correctly handled, identifying previously visited locations can lead to misaligned maps.

4. Scalability: Larger maps become computationally intensive, and optimizing these graphs for large environments requires sophisticated approaches.


Popular SLAM Frameworks and Libraries

1. GMapping: A well-known 2D SLAM algorithm using Particle Filters, often used with ROS (Robot Operating System).

2. Hector SLAM: Uses a Lidar and an IMU, known for high speed and low latency mapping in indoor environments.

3. Cartographer by Google: Supports both 2D and 3D SLAM, popular for its real-time mapping capabilities.

4. ORB-SLAM: A Visual SLAM library focusing on feature-based landmarks, very popular in robotics and augmented reality.


Use Cases in Robotics

1. Autonomous Vacuum Cleaners: These use SLAM to map a house layout and optimize cleaning routes while avoiding obstacles.

2. Delivery Robots: Like those used in Amazon warehouses, where they navigate autonomously through aisles and handle dynamic obstacles.

3. Drones: Drones often employ Visual SLAM to create maps of unknown environments for navigation and avoid collisions.

4. Self-Driving Cars: While more sophisticated, they often employ a form of SLAM to localize the vehicle and build environmental maps for path planning.

Ah...  These Use Cases are just the basic ones the AI can share, the low hanging fruit. The Use Cases are much, much, more expansive.  All robots and machines interacting in physical space will need some form of SLAM. Once the machine is localized and positions are known, then the applications of the sensors, manipulators, and motion can become effective. This is just the beginning, there are many applications that are yet to be realized or identified!


Advanced SLAM Topics to Explore

- Multi-Robot SLAM: Where a team of robots collaborates to create a common map.

- SLAM with Deep Learning: Incorporating neural networks to aid feature extraction and recognition, which can improve SLAM reliability, especially in challenging environments.

- SLAM in Dynamic Environments: Handling environments where objects are constantly in motion, requiring more sophisticated filtering to identify static versus dynamic features.


Conclusion

SLAM forms the backbone of autonomous navigation, providing a robot with the ability to understand and navigate in its environment. Whether using traditional Lidar-based approaches, visual methods, or newer graph-based optimization techniques, each approach has its own strengths and trade-offs depending on the application scenario.

Moving forward, I will be expanding my Simple SLAM! Simulator to explore the necessary components of SLAM.  My interest is (at-least!) two fold: 

1) The digitalization of physical space, fusing sensor data to observer and record that in our world that is difficult for humans to perceive in spectrum, space, and temporal dimensions.

2) Develop the concepts around Machine Perception of the physical world.

Friday, July 10, 2020

Crappy Robot Stories #1: Secondhand Love

 Crappy Robot Stories...


The front door to the shop slammed open andValk stalked through, block trench coat swirling around his ankles. He marched through the store, past the ranks of metallic soldiers standing motionless, to the counter at the back of the store. Beneath the display cabinet, rows of motherboards and semi-organic AI’s sparkled in the lights.
              Val slammed both hands down on the glass.
              “I demand a refund!” he shouted at the clerk behind the counter. Electricity sparked off of the stray white hairs that stood out in all directions from his head like a puffy cloud.
              The clerk behind the counter didn’t flinch from the sudden noise. Instead, he slowly dog-eared the page of Evil Today that he was reading before closing the magazine and laying it off to the side. Finally, he raised his bored gaze to the puffing scientist on the other side of the counter.
              “Welcome to Secondhand Evil, how can I help you today?” he intoned.
              “I demand a refund for… for… for that!” Valk shouted again, pointing behind him. As the clerk looked, a metallic head with a single eye widget poked around the villain’s back.
              “Hello,” the robot whirred. “My name is Bobs, minion robot 001.”
              “What seems to be the problem?” The clerk asked.
              “It’s supposed to be an evil robot. I specifically asked for the Villainy 2.0 software to be installed, and it hasn’t been!”
              “All our models come standard with the henchman software Villainy 2.0 installed. Why do you believe your model does not?”
              “It doesn’t do anything evil!”
              The clerk sighed and pulled a complaint form out from beneath the counter. “Can you give me some examples?” he droned.
              “I told it to prepare the lab for experiments, and it cleaned my lair. The floors are freaking sparkling!”
              The clerk looked up, one eyebrow raised.
              “I had just the right amount of evil chaos! It’s too neat now! It interferes with my evil creativity!” Valk screeched.
              Behind him, gears whirred as the cycloptic robot peeked around its owner again. “There were roaches.”
              “That’s not the point!”
              “Okay, it cleaned without command. Anything else?” The clerk asked.
              “Yes! I identified a homeless man that would make the perfect minion, and I sent Bobs out to recruit him. The guy was recruited…. to an IT firm as a manager! He now makes six figures and can comfortably support his family!”
              The clerk rolled his eyes and began to scrawl on the form. “Failure to follow directive to necessary level. Anything else?”
              “He made me contribute to the middle class. I loathe the middle class!”
              “Yes, yes, I know the Evil Rulebook as well. Anything else?”
              “He’s constantly baking cupcakes. My entire lair smells like vanilla!” Valk’c chest heaved as he turned to glare at the robot.
              The clerk looked at the robot as well. Bobs held up a pink box and offered it to the clerk. He opened it up to a perfectly frosted cupcake, wrapped in a lacy doily.
              “Oookay, that’s a new one,” he said slowly. “Are they any good?”
              “They’re delicious!” Valk screeched. “And they aren’t even poisoned? What kind of villainy is that?”
              “I see.” The clerk closed the box and stored it beneath the counter. He pointed up above his head, at the large sign suspended from the ceiling.
              All purchases are final. NO REFUNDS, NO EXCHANGES.
              “Oh, come on, you have to do something for me!” Valk insisted. “What about in-store credit?”
              “Nope. All sales are final. You acknowledged the risks of buying a second-hand robot when you signed the contract with us. Would you like to see your signature? I can pull up the agreement right now.”
              “I want to see your manager!”
              The clerk rolled his eyes. “I mean, I can call her if you want me too, but she said she was working on her death ray and she was going to use anyone who interrupter her as target practice.”
              Valk glared at the clerk, who stared back with the dead gaze of someone who had spent way to long in retail.
              “Fine!” he snapped, spinning around. “Bobs, we’re leaving. Se if I ever come to this stupid store again! I’m going to tell everyone how terrible the place is!”
              The robot waved one, then raced off after its master with a whirr of gears.
              The clerk sighed, shook his head, and flicked his magazine open.
              “Cupcakes,” he sighed. “Really?”