rosbag
DataframeError
Bases: Exception
Dataframe conversion error.
RosbagLoader(path, topics, msgpaths)
Bases: Dataset
Environment to load data from a rosbag file.
The RosbagEnvironment is used to load data from a rosbag file. The environment is initialized with the path to the rosbag file and a dictionary of topics to load.
Example
from flowcean.environments.rosbag import RosbagLoader
environment = RosbagLoader(
path="example_rosbag",
topics={
"/amcl_pose": [
"pose.pose.position.x",
"pose.pose.position.y",
],
"/odometry": [
"pose.pose.position.x",
"pose.pose.position.y",
],
},
)
environment.load()
data = environment.get_data()
print(data)
Initialize the RosbagEnvironment.
The structure of the data is inferred from the message definitions. If a message definition is not found in the ROS2 Humble typestore, it is added from the provided paths. Once all the message definitions are added, the data is loaded from the rosbag file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | Path
|
Path to the rosbag. |
required |
topics
|
dict[str, list[str]]
|
Dictionary of topics to load ( |
required |
msgpaths
|
list[str]
|
List of paths to additional message definitions. |
required |
Source code in src/flowcean/environments/rosbag.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
guess_msgtype(path)
Guess message type name from path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Path to the message file. |
required |
Returns:
Type | Description |
---|---|
str
|
The message definition string. |
Source code in src/flowcean/environments/rosbag.py
105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
get_dataframe(reader, topicname, keys)
Convert messages from a topic into a polars dataframe.
Read all messages from a topic and extract referenced keys into a polars dataframe. The timestamps of messages are automatically added as the dataframe index.
Keys support a dotted syntax to traverse nested messages. Here is an example of a nested ROS message structure: /amcl_pose (geometry_msgs/PoseWithCovarianceStamped) ├── pose (PoseWithCovariance) │ ├── pose (Pose) │ │ ├── position (Point) │ │ │ ├── x (float) │ │ │ ├── y (float) │ │ │ └── z (float) │ │ └── orientation (Quaternion) │ └── covariance (array[36])
The first key is 'pose.pose.position.x'. The subkeys are separated by dots. So, in this case, the subkeys are ['pose', 'pose', 'position', 'x']. Each subkey is used to traverse the nested message structure. If a subkey matches a field name, the next subkey is used to traverse deeper into the nested structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reader
|
AnyReader
|
Opened rosbags reader. |
required |
topicname
|
str
|
Topic name of messages to process. |
required |
keys
|
Sequence[str]
|
Field names to get from each message. |
required |
Raises:
Type | Description |
---|---|
DataframeError
|
Reader not opened or topic or field does not exist. |
Returns:
Type | Description |
---|---|
DataFrame
|
Polars dataframe. |
Source code in src/flowcean/environments/rosbag.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
create_getter(keys)
Create getter for nested lookups.
Source code in src/flowcean/environments/rosbag.py
266 267 268 269 270 271 272 273 274 275 |
|
ros_msg_to_dict(obj)
Recursively convert a ROS message object into a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
dict
|
A ROS message object represented as a dictionary where keys are field names and values are their corresponding data. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary representation of the ROS message, with all nested fields converted to dictionaries. |
Source code in src/flowcean/environments/rosbag.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
|