Skip to content

Commit 1c162a6

Browse files
committed
refactor(game_controller): only send ball PointStamped
to `game_controller_hsl` as the new [Gamecontroller] only expectes an `(x, y)` coordinate. [Gamecontroller]: https://github.com/RoboCup-HumanoidSoccerLeague/GameController/
1 parent 9bfb6df commit 1c162a6

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

  • src/bitbots_world_model/bitbots_ball_filter/bitbots_ball_filter

src/bitbots_world_model/bitbots_ball_filter/bitbots_ball_filter/ball_filter.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
from ros2_numpy import msgify, numpify
1515
from sensor_msgs.msg import CameraInfo
1616
from soccer_vision_3d_msgs.msg import Ball, BallArray
17-
from std_msgs.msg import Header
17+
from std_msgs.msg import Float32, Header
1818
from std_srvs.srv import Trigger
1919
from tf2_geometry_msgs import PointStamped, PoseStamped
20-
from soccer_model_msgs.msg import Ball as BallWithCovariance
21-
from std_msgs.msg import Float32
2220

2321
from bitbots_ball_filter.ball_filter_parameters import bitbots_ball_filter as parameters
2422

@@ -52,12 +50,10 @@ def __init__(self) -> None:
5250
self.ball_pose_publisher = self.create_publisher(
5351
PoseWithCovarianceStamped, self.config.ros.ball_position_publish_topic, 1
5452
)
55-
self.ball_pose_with_covariance_publisher = self.create_publisher(
56-
BallWithCovariance, "hsl_gamecontroller/ball_with_covariance", 1
57-
)
58-
self.ball_age_publisher = self.create_publisher(
59-
Float32 , "hsl_gamecontroller/ball_age", 1
53+
self.game_controller_ball_position_publisher = self.create_publisher(
54+
PointStamped, "hsl_gamecontroller/ball_position", 1
6055
)
56+
self.ball_age_publisher = self.create_publisher(Float32, "hsl_gamecontroller/ball_age", 1)
6157

6258
# Create callback group
6359
self.callback_group = MutuallyExclusiveCallbackGroup()
@@ -256,7 +252,7 @@ def filter_step(self) -> None:
256252
# Increase covariance
257253
self.ball_state_covariance[:2, :2] += np.eye(2) * self.config.filter.covariance.process_noise
258254

259-
# Build message
255+
# Build message
260256
pose_msg = PoseWithCovarianceStamped()
261257
pose_msg.header = Header(
262258
stamp=Time.to_msg(self.get_clock().now()),
@@ -269,21 +265,19 @@ def filter_step(self) -> None:
269265
pose_msg.pose.pose.orientation.w = 1.0
270266
self.ball_pose_publisher.publish(pose_msg)
271267

272-
# Build message for Ball with Covariance
273-
ball_msg = BallWithCovariance()
274-
ball_msg.header = Header(
268+
ball_position_msg = PointStamped()
269+
ball_position_msg.point = msgify(Point, self.ball_state_position)
270+
ball_position_msg.header = Header(
275271
stamp=Time.to_msg(self.get_clock().now()),
276272
frame_id=self.config.filter.frame,
277273
)
278-
ball_msg.point.point = msgify(Point, self.ball_state_position)
279-
covariance = np.zeros((6, 6))
280-
covariance[:3, :3] = self.ball_state_covariance
281-
ball_msg.point.covariance = covariance.flatten()
282-
self.ball_pose_with_covariance_publisher.publish(ball_msg)
274+
self.game_controller_ball_position_publisher.publish(ball_position_msg)
283275

284276
# Build message for Ball age
285277
ball_age_msg = Float32()
286-
ball_age_msg.data = np.float32(self.get_clock().now() - self.last_ball_time)
278+
nanoseconds_since_last_ball = np.float32((self.get_clock().now() - self.last_ball_time).nanoseconds)
279+
ball_age_msg.data = nanoseconds_since_last_ball / 1e9
280+
287281
self.ball_age_publisher.publish(ball_age_msg)
288282

289283

0 commit comments

Comments
 (0)