# Slam

This section contains API calls for using the Occipital Core Structure sensors and Slam capabilities on Misty II Pro.&#x20;

### GetMap

Obtains the occupancy grid data for Misty's currently active map.To obtain a valid response from `GetMap`, Misty must first have successfully generated a map. To change the currently active map, use the [`SetCurrentSlamMap`](https://docs.mistyrobotics.com/misty-ii/web-api/api-reference/#setcurrentslammap) command.

<details>

<summary>Additional Notes</summary>

Misty's maps are squares that are constructed around her initial physical location when she starts mapping. When a map is complete, it is a square with Misty's starting point at the center.

The occupancy grid for the map is represented by a two-dimensional matrix. Each element in the occupancy grid represents an individual cell of space. The value of each element (0, 1, 2, or 3) indicates the nature of the space in those cells (respectively: "unknown", "open", "occupied", or "covered").

Each cell corresponds to a pair of X,Y coordinates that you can use with the `FollowPath`, `DriveToLocation`, and `GetSlamPath` commands. The first cell in the first array of the occupancy grid is the origin point (0,0) for the map. The X coordinate of a given cell is the index of the array for the cell. The Y coordinate of a cell is the index of that cell within its array.

</details>

{% hint style="success" %}

```
misty.get_map()
```

{% endhint %}

### GetCurrentSlamMap

Obtains the key for the currently active map.

{% hint style="success" %}

```
misty.get_current_slam_map()
```

{% endhint %}

### GetSlamIrExposureAndGain

Obtains the current exposure and gain settings for the infrared cameras in the Occipital Structure Core depth sensor.

{% hint style="success" %}

```
misty.get_slam_ir_exposure_and_gain()
```

{% endhint %}

### GetSlamVisibleExposureAndGain

Obtains the current exposure and gain settings for the fisheye camera in the Occipital Structure Core depth sensor.

{% hint style="success" %}

```
misty.get_slam_visible_exposure_and_gain()
```

{% endhint %}

### GetSlamMaps

Obtains a list of keys and names for Misty's existing maps.

**Example code**

{% hint style="success" %}
misty.get\_slam\_maps()
{% endhint %}

**Parameters**

### GetSlamNavigationDiagnostics

Obtains diagnostic information about Misty's navigation system.

The information in the data object for this command is primarily used by the Misty Robotics engineering and support staff to troubleshoot and root-cause issues with Misty's SLAM system. The contents of this data object are likely to change without notice in future system updates.

{% hint style="success" %}
misty.get\_slam\_navigation\_diagnostics()
{% endhint %}

### GetSlamPath

Obtain a path from Misty's current location to a specified set of X,Y coordinates. Pass the waypoints this command returns to the path parameter of `FollowPath` for Misty to follow this path to the desired location.

This command is not functional with the Misty II Basic Edition.

**Important!** Make sure to use `StartTracking` before using this command to have Misty start tracking her location, and use `StopTracking` to have her stop tracking her location after she arrives at the specified location

**Example code**

{% hint style="success" %}
{% code overflow="wrap" %}

```python
misty.get_slam_path(x=13,y=37)
```

{% endcode %}
{% endhint %}

**Parameters**

{% code overflow="wrap" %}

```python
misty.get_slam_path(self, x : int = None, y : int = None, minGap : float = None, wallCostDistance : float = None, unknownIsOpen : bool = None)
```

{% endcode %}

* X (integer) - The X coordinate of the destination.
* Y (integer) - The Y coordinate of the destination.

### GetSlamStatus

Obtains values representing the current activity and status of Misty's SLAM system. Check these values for information about the current status of Misty's depth sensor, the SLAM system, and to see information relevant to any ongoing mapping or tracking activities.

{% hint style="success" %}
misty.get\_slam\_status()
{% endhint %}

### SetCurrentSlamMap

Sets a map to be Misty's currently active map for tracking and relocalization.

**Example code**

{% hint style="success" %}

```python
misty.set_current_slam_map("Map_20190912_21.16.32.UTC")
```

{% endhint %}

**Parameters**

```python
misty.set_current_slam_map(self, key : str = None)
```

* Key (string) - The unique `key` of the map to make currently active. **Note:** This command does not work when passed the value for the `name` associated with a map.

### SetSlamIrExposureAndGain

Sets the exposure and gain settings for the infrared cameras in the Occipital Structure Core depth sensor.

**Example code**

{% hint style="success" %}

```python
misty.set_slam_ir_exposure_andGain(
```

{% endhint %}

**Parameters**

{% code overflow="wrap" %}

```python
misty.set_slam_ir_exposure_andGain(self, exposure : float = None, gain : float = None)
```

{% endcode %}

* Exposure (double) - Exposure levels for the infrared cameras in the depth sensor (in seconds). Range: `0.001` - `0.033`.
* Gain (integer) - Gain levels for the infrared cameras in the depth sensor (in dB). Range: `0` - `3`.

### SetSlamVisibleExposureAndGain

Sets the exposure and gain settings for the fisheye camera in the Occipital Structure Core depth sensor.

**Example code**

{% hint style="success" %}

```python
misty.set_slam_visible_exposure_andGain(exposure=0.007987,gain=2)
```

{% endhint %}

**Parameters**

{% code overflow="wrap" %}

```python
misty.set_slam_visible_exposure_andGain(self, exposure : float = None, gain : float = None)
```

{% endcode %}

* Exposure (double) - Exposure levels for the fisheye camera in the depth sensor (in seconds). Range: `0.001` - `0.033`
* Gain (integer) - Gain levels for the fisheye camera in the depth sensor (in dB). Range: `1` - `8`

### RenameSlamMap

Renames an existing map.

**Example code**

{% hint style="success" %}

```python
misty.rename_slam_map("Map_20190911_21.47.16.UTC", "Kitchenmap2")
```

{% endhint %}

**Parameters**

```python
misty.rename_slam_map(self, key : str = None, name : str = None)
```

* `Key` (string) - The unique `key` value of the map to rename.
* `Name (`string) - A new `name` value for the map.

### ResetSlam

Resets Misty's SLAM sensors

{% hint style="success" %}
misty.reset\_slam()
{% endhint %}

### StartMapping

Starts Misty mapping an area.

Misty saves each map she creates to local storage. Each map is associated with a unique key at the time of the map's creation. Map keys are formatted as date timestamps in UTC (i.e. `Map_20190911_21.47.16.UTC`). To obtain a list of Misty's existing maps, use the [`GetSlamMaps`](https://docs.mistyrobotics.com/misty-ii/web-api/api-reference/#getslammaps) command.

{% hint style="success" %}
misty.start\_mapping()
{% endhint %}

### StopMapping

Stops Misty from mapping the environment.

{% hint style="success" %}
misty.stop\_mapping()
{% endhint %}

### DeleteSlamMap

Deletes a specified Slam map.

**Example code**

{% hint style="success" %}

```python
misty.delete_slam_map("Map_20190912_21.16.32.UTC")
```

{% endhint %}

**Parameters**

```python
misty.delete_slam_map(self, key : str = None)
```

* Key (string) - The unique `key` value of the map to delete. **Note:** This command does not work when passed the value for the `name` associated with a map.

### StartSlamStreaming

Opens the data stream from the Occipital Structure Core depth sensor, so you can obtain image and depth data when Misty is not actively tracking or mapping.

**Important!** Always use `StopSlamStreaming` to close the depth sensor data stream after sending commands that use Misty's Occipital Structure Core depth sensor. Using `StopSlamStreaming` turns off the laser in the depth sensor and lowers Misty's power consumption.

**Example code**

{% hint style="success" %}
misty.start\_slam\_streaming()
{% endhint %}

### StopSlamStreaming

Stops Misty's streaming data from the Occipital Structure Core depth sensor.

{% hint style="success" %}
misty.stop\_slam\_streaming()
{% endhint %}

### StartTracking

Enables Misty to start tracking the mapped enviornment.

{% hint style="success" %}

```
misty.start_tracking()
```

{% endhint %}

### StopTracking

Stops Misty from tracking the mapped environment.

{% hint style="success" %}

```
misty.stop_tracking()
```

{% endhint %}

### TakeDepthPicture

Provides the current distance of objects from Misty's Occipital Structure Core depth sensor. Note that depending on the scene being viewed, the sensor may return a large proportion of "unknown" values in the form of `NaN` ("not a number") values.

{% hint style="success" %}

```python
misty.take_depth_picture()
```

{% endhint %}

### TakeFisheyePicture

Takes a photo using Misty's Occipital Structure Core depth sensor..&#x20;

{% hint style="success" %}

```
misty.take_fisheye_picture()
```

{% endhint %}
