How to get the int value instead of BOOL?
I'm doing the sample of publisher.
Here is the section of the file:
def __init__(self):
super().__init__('minimal_publisher')
self.publisher_ = self.create_publisher(Int64, "scan", 10)
timer_period = 0 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
self.i = 0
def timer_callback(self): # this is the part where we need to get it keep running
check = ser.readline()
if check == ' ': # this if statement is to skip string id. It doesn't seem like it works
print("Skipped the ' '") # in #44 line, it kept recieving a string ' '
else:
sensorvalue = float(ser.readline()) # posts the value
msg = sensorvalue
print(msg)
msg = self.get_logger().info("distance: ".format(float(ser.readline())))
print(type(msg)) # this is to verify the type of the value. It should be float only
self.publisher_.publish(check) # this is to publish the data to topic 'scann'. It can change to 'scan' in #34 line
self.i += 1
As you can see that I use print(type(msg))
, this is for me to verify if the msg is being sent to publisher data as an integer or float. Somehow, it kept getting BOOL value.
Here is the actual output using HC-SR04 sonar sensor.
Also if I run ros2 topic echo /scan
(I'm using /scan but that name can be changed at anytime anyway)
The memory suddenly dumped, take a look at the picture
To be honest with you, I'm super confused how I get a BOOL value instead of float/int.
Software: Ubuntu 20.04 Distro: Foxy Language: Python 3 with Ardiuno (Doing Ardiuno + ros2 using Serial)