ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

python method to initialize mass variable with random data types

asked 2022-10-17 19:59:46 -0500

fury.nerd gravatar image

updated 2022-10-17 20:03:00 -0500

hi, in python, i got a massive signals with random data types need to initialize, below is a sample:

import rclpy

from std_msgs.msg import Float32
from std_msgs.msg import Int8

x = Float32()
y = Int8()


x.data = 0.0
y.data = 0

where the initials of = 0.0 or = 0 depends on data types, when i coding i need to check type manually first then decide to write 0.0 or 0, is quite not smart.

if i directly make them all like

x.data = 0
y.data = 0

it's easy to coding but i got error AssertionError: The 'data' field must be of type 'int'

is there a way like auto in cpp to make this case easier to coding?

like auto_type() below

import rclpy

from std_msgs.msg import Float32
from std_msgs.msg import Int8

x = Float32()
y = Int8()


x.data = auto_type(0)
y.data = auto_type(0)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-10-17 20:16:16 -0500

fury.nerd gravatar image

turn out to use the following code temporarily:

x.data # = 0
y.data # = 0
edit flag offensive delete link more

Question Tools

Stats

Asked: 2022-10-17 19:59:46 -0500

Seen: 32 times

Last updated: Oct 17 '22