Python message with uint32 Assertion `PyLong_Check(field)' failed
wangchong666 opened this issue · comments
Bug report
Required Info:
-
Operating System:
- centos 7
-
Installation type:
- docker image ros:rolling
-
Version or commit hash:
- image ID
1186d494b6a3
- image ID
-
Client library (if applicable):
- rclpy
Steps to reproduce issue
RadarMessage.msg
uint32 radar_id
float32 sx
float32 sh
float32 bx
float32 bh
float32 warming_distance
float32 daoxian_height
float32 danger_height
Node publisher_member_function.py
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
from twvs_inf.msg import RadarMessage # CHANGE
class MinimalPublisher(Node):
def __init__(self):
super().__init__('minimal_publisher')
self.publisher_ = self.create_publisher(RadarMessage, 'topic', 10)
timer_period = 0.5 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
self.i = 0
def timer_callback(self):
msg = RadarMessage()
msg.sx = 1.0
msg.sh = 1.0
msg.bx = 1.0
msg.bh = 1.0
msg.warming_distance = 1.0
msg.daoxian_height = 1.0
msg.danger_height = 2.0
msg.radar_id = 1,
# print(self.radar_settings["radarId"])
print(msg.radar_id)
# print(msg.radar_id)
self.publisher_.publish(msg)
self.i += 1
def main(args=None):
rclpy.init(args=args)
minimal_publisher = MinimalPublisher()
rclpy.spin(minimal_publisher)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
minimal_publisher.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
Expected behavior
twvs_inf.msg.RadarMessage(radar_id=1, sx=1.0, sh=1.0, bx=1.0, bh=1.0, warming_distance=1.0, daoxian_height=1.0, danger_height=2.0)
twvs_inf.msg.RadarMessage(radar_id=1, sx=1.0, sh=1.0, bx=1.0, bh=1.0, warming_distance=1.0, daoxian_height=1.0, danger_height=2.0)
twvs_inf.msg.RadarMessage(radar_id=1, sx=1.0, sh=1.0, bx=1.0, bh=1.0, warming_distance=1.0, daoxian_height=1.0, danger_height=2.0)
Actual behavior
(1,)
python3: /home/ros/build/twvs_inf/rosidl_generator_py/twvs_inf/msg/_radar_message_s.c:58: twvs_inf__msg__radar_message__convert_from_py: Assertion `PyLong_Check(field)' failed.
[ros2run]: Aborted
Additional information
---- radar_id became (1,)
Feature request
Feature description
Implementation considerations
this work well, very strange
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
from twvs_inf.msg import RadarMessage # CHANGE
class MinimalPublisher(Node):
def __init__(self):
super().__init__('minimal_publisher')
self.publisher_ = self.create_publisher(RadarMessage, 'topic', 10)
timer_period = 0.5 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
self.i = 0
def timer_callback(self):
msg = RadarMessage()
msg.radar_id = 1
msg.sx = 1.0
msg.sh = 1.0
msg.bx = 1.0
msg.bh = 1.0
msg.warming_distance = 1.0
msg.daoxian_height = 1.0
msg.danger_height = 2.0
print(msg)
self.publisher_.publish(msg)
self.i += 1
def main(args=None):
rclpy.init(args=args)
minimal_publisher = MinimalPublisher()
rclpy.spin(minimal_publisher)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
minimal_publisher.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
Finally, there was an extra comma
msg.radar_id = 1,