Commit 7ccfe07f authored by Inès EL HADRI's avatar Inès EL HADRI 💤

Fix marker pos in map instead of odom

parent 5484b314
...@@ -70,16 +70,30 @@ class BottleMapping(Node): ...@@ -70,16 +70,30 @@ class BottleMapping(Node):
bottleOffsetToRobot.x += camOffset bottleOffsetToRobot.x += camOffset
# Get bottle coordinates relative to map # Get bottle coordinates relative to Odom
newPose = Pose() newPoseInOdom = Pose()
newPose.position = self._robotPose.position newPoseInOdom.position = self._robotPose.position
a = Odometry()
yaw = self.getRobotRotation() yaw = self.quaternionToYaw(self._robotPose.orientation)
newPose.position.x += bottleOffsetToRobot.x * m.cos(yaw) - bottleOffsetToRobot.y * m.sin(yaw) newPoseInOdom.position.x += bottleOffsetToRobot.x * m.cos(yaw) - bottleOffsetToRobot.y * m.sin(yaw)
newPose.position.y += bottleOffsetToRobot.x * m.sin(yaw) + bottleOffsetToRobot.y * m.cos(yaw) newPoseInOdom.position.y += bottleOffsetToRobot.x * m.sin(yaw) + bottleOffsetToRobot.y * m.cos(yaw)
newPosition = newPose.position # Add offset to map
trans = self._tf_buffer.lookup_transform("map", "odom", rclpy.time.Time())
newPoseInMap = Pose()
newPoseInMap.position.x = trans.transform.translation.x
newPoseInMap.position.y = trans.transform.translation.y
newPoseInMap.position.z = trans.transform.translation.z
yaw = self.quaternionToYaw(trans.transform.rotation)
newPoseInMap.position.x += newPoseInOdom.position.x * m.cos(yaw) - newPoseInOdom.position.y * m.sin(yaw)
newPoseInMap.position.y += newPoseInOdom.position.x * m.sin(yaw) + newPoseInOdom.position.y * m.cos(yaw)
newPosition = newPoseInMap.position
# Compare it with other markers # Compare it with other markers
isNewPoint = True isNewPoint = True
...@@ -95,7 +109,7 @@ class BottleMapping(Node): ...@@ -95,7 +109,7 @@ class BottleMapping(Node):
# Create Marker # Create Marker
marker = self.createMarker(newPose) marker = self.createMarker(newPoseInMap)
# Add marker to list # Add marker to list
self._markers.append(marker) self._markers.append(marker)
# Publish marker # Publish marker
...@@ -139,12 +153,12 @@ class BottleMapping(Node): ...@@ -139,12 +153,12 @@ class BottleMapping(Node):
""" """
self._marker_publisher.publish(marker) self._marker_publisher.publish(marker)
def getRobotRotation(self): def quaternionToYaw(self, q):
# Convert robot quaternion to roll # Convert quaternion to yaw
x = self._robotPose.orientation.x x = q.x
y = self._robotPose.orientation.y y = q.y
z = self._robotPose.orientation.z z = q.z
w = self._robotPose.orientation.w w = q.w
siny_cosp = 2 * (w * z + x * y) siny_cosp = 2 * (w * z + x * y)
cosy_cosp = 1 - 2 * (y * y + z * z) cosy_cosp = 1 - 2 * (y * y + z * z)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment