... | @@ -122,8 +122,33 @@ for row in data["results"]["bindings"]: |
... | @@ -122,8 +122,33 @@ for row in data["results"]["bindings"]: |
|
print(row)
|
|
print(row)
|
|
```
|
|
```
|
|
|
|
|
|
**Transformation** If you need to transform points from a frame to an other, you can use `tf.transform_listener`, look at `move_to_point.py` script from lab 2 for an example.
|
|
**Transformation** If you need to transform points from a frame to an other, you can use `tf2`:
|
|
You can also use the `transformPoint(dst_frame, point)` function to transform the points from the sensor frame to the global frame.
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
|
|
|
import rclpy
|
|
|
|
from rclpy.node import Node
|
|
|
|
|
|
|
|
from tf2_ros import TransformException
|
|
|
|
from tf2_ros.buffer import Buffer
|
|
|
|
from tf2_ros.transform_listener import TransformListener
|
|
|
|
|
|
|
|
# The tf_buffer and tf_listener needs to be kept alive and should be created in a constructor
|
|
|
|
node = Node()
|
|
|
|
tf_buffer = Buffer()
|
|
|
|
tf_listener = TransformListener(self.tf_buffer, node)
|
|
|
|
|
|
|
|
# To use them for point transformation
|
|
|
|
|
|
|
|
try:
|
|
|
|
point_transformed = self.tf_buffer.transform(point, to_frame_rel)
|
|
|
|
except TransformException as ex:
|
|
|
|
node.get_logger().info(f'Could not transform {point} to {to_frame_rel}: {ex}')
|
|
|
|
return
|
|
|
|
```
|
|
|
|
|
|
|
|
Where `to_frame_rel` is the destination frame, in our case, it should be `"map"`. `point` is the point stamped from the observation.
|
|
|
|
|
|
|
|
|
|
## C++
|
|
## C++
|
... | @@ -138,8 +163,26 @@ QJsonDocument doc = QJsonDocument::fromJson(QByteArray::fromStdString(result)); |
... | @@ -138,8 +163,26 @@ QJsonDocument doc = QJsonDocument::fromJson(QByteArray::fromStdString(result)); |
|
|
|
|
|
You can check the API online for [QJsonDocument](https://doc.qt.io/qt-5/qjsondocument.html)
|
|
You can check the API online for [QJsonDocument](https://doc.qt.io/qt-5/qjsondocument.html)
|
|
|
|
|
|
**Transformation** If you need to transform points from a frame to an other, you can use `tf::transform_listener`, look at `ls_to_occ` program from lab 3 for an example.
|
|
**Transformation** If you need to transform points from a frame to an other, you can use `tf2`:
|
|
You can also use the `transformPoint(dst_frame, point)` function to transform the points from the sensor frame to the global frame.
|
|
|
|
|
|
```c++
|
|
|
|
|
|
|
|
// The tf_buffer and tf_listener needs to be kept alive and should be created in a constructor
|
|
|
|
std::unique_ptr<tf2_ros::Buffer> tf_buffer_ = std::make_unique<tf2_ros::Buffer>(node->get_clock());
|
|
|
|
std::shared_ptr<tf2_ros::TransformListener> tf_listener_ = std::make_shared<tf2_ros::TransformListener>(*tf_buffer_);
|
|
|
|
|
|
|
|
// To use them for point transformation
|
|
|
|
|
|
|
|
try {
|
|
|
|
point_transformed = tf_buffer_->tranform(point, to_frame_rel);
|
|
|
|
} catch (const tf2::TransformException & ex) {
|
|
|
|
RCLCPP_INFO(node->get_logger(), "Could not transform %s to %s: %s",
|
|
|
|
point.header.frame_id.c_str(), to_frame_rel.c_str(), ex.what());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Where `to_frame_rel` is the destination frame, in our case, it should be `"map"`. `point` is the point stamped from the observation.
|
|
|
|
|
|
# Visualisation
|
|
# Visualisation
|
|
|
|
|
... | | ... | |