Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout #2

Open
neochaos42 opened this issue Mar 15, 2023 · 7 comments
Open

Timeout #2

neochaos42 opened this issue Mar 15, 2023 · 7 comments

Comments

@neochaos42
Copy link

Hello I am running both nodes on a single machine and serial_motor_demo keeps timing out. Error: Serial Timeout on command: e
This keeps printing.
The system works using miniterm but not using these nodes.

@neochaos42
Copy link
Author

neochaos42 commented Mar 20, 2023

ros2 run serial_motor_demo driver --ros-args -p encoder_cpr:=1796 -p loop_rate:=30 -p serial_port:=/dev/ttyUSB0 -p baud_rate:=57600
Connecting to port /dev/ttyUSB0 at 57600.
Connected to Serial<id=0xffffb4471c40, open=True>(port='/dev/ttyUSB0', baudrate=57600, bytesize=8, parity='N', stopbits=1, timeout=1.0, xonxoff=False, rtscts=False, dsrdtr=False)
Error: Serial timeout on command: e
Error: Serial timeout on command: e
Error: Serial timeout on command: e
Error: Serial timeout on command: e

@joshnewans
Copy link
Owner

As I was testing this today for the humble upgrade, I realised that I had always sort of had problems like this, except usually just on the first connection and after that it was fine. I.e. it would print only once.

I wonder if this is related or not...

@virensompura
Copy link

@neochaos42 same issue

@ryanmaxwell96
Copy link

ryanmaxwell96 commented Sep 21, 2023

Same issue. Mine prints 3 times. The gui reads: "Encoders: XXX XXX Speed rev/s: XXX XXX" and the motors do not spin. However I can listen to the topic from my dev machine and see that the messages are being successfully published. The rpi is just not listening to it.

On the raspberry pi:

rpi@rpi:~/robot_ws$ ros2 run serial_motor_demo driver --ros-args -p serial_port:=/dev/ttyUSB0 -p baud_rate:=57600 -p loop_rate:=30 -p encoder_cpr:=2500
Connecting to port /dev/ttyUSB0 at 57600.
Connected to Serial<id=0xffff9cc68700, open=True>(port='/dev/ttyUSB0', baudrate=57600, bytesize=8, parity='N', stopbits=1, timeout=1.0, xonxoff=False, rtscts=False, dsrdtr=False)
Error: Serial timeout on command: e
Error: Serial timeout on command: e
Error: Serial timeout on command: e

On the development machine after running, "ros2 run serial_motor_demo gui" and "ros2 topic echo /motor_command" in a separate terminal after 3 different publishes:
is_pwm: true
mot_1_req_rad_sec: 57.0
mot_2_req_rad_sec: 47.0

is_pwm: true
mot_1_req_rad_sec: -133.0
mot_2_req_rad_sec: -140.0

is_pwm: true
mot_1_req_rad_sec: 128.0
mot_2_req_rad_sec: -140.0

@ryanmaxwell96
Copy link

Update: The XXX XXX clued me in that ROS2 communication was not working so I used the talker/listener program to test this. Sure enough, ROS was not communicating over my network. This ended up being firewall issues which were overcome by

  1. Putting ROS_DOMAIN_ID=0 in to the .bashrc on each machine
  2. Entering "sudo ufw allow in proto udp to/from " on both machines, both for "to" and "from"
  3. Actually running "ros2 run demo_nodes_cpp talker/listener" on both machines rather than just using "ros2 topic list" to make sure the machine could see the other's published topics. When I first just ran the talker and then ros2 topic list, nothing showed up so I think it takes some time for the ros node to appear.

So now it is working!

@huubeikens
Copy link

Same issue. The ROS2 communication works fine but still get serial timeouts:

ros2 run serial_motor_demo driver --ros-args -p encoder_cpr:=3440 -p loop_rate:=30 -p serial_port:=/dev/ttyACM0 -p baud_rate:=57600
Connecting to port /dev/ttyACM0 at 57600.
Connected to Serial<id=0xffff8e370cd0, open=True>(port='/dev/ttyACM0', baudrate=57600, bytesize=8, parity='N', stopbits=1, timeout=1.0, xonxoff=False, rtscts=False, dsrdtr=False)
Error: Serial timeout on command: e
rror: Serial timeout on command: e
Error: Serial timeout on command: e
Error: Serial timeout on command: m 573 573
Error: Serial timeout on command: e
Error: Serial timeout on command: e

If I open a python3 terminal and past the following code snipit from driver.py, I get a valid response:

import serial

ser = serial.Serial('/dev/ttyACM0', 57600, timeout=1.0)  # open serial port

cmd_string= "e"
cmd_string += "\r"
ser.write(cmd_string.encode("utf-8"))
print("Sent: " + cmd_string)

c = ''
value = ''
while c != '\r':
    c = ser.read(1).decode("utf-8")
    if (c == ''):
        print("Error: Serial timeout on command ")
        break
    value += c

print(value)

Anyone has an idea how to debug this further?

@huubeikens
Copy link

Solved it! Add a 2 second sleep after creating the Serial object:

        print(f"Connecting to port {self.serial_port} at {self.baud_rate}.")
        self.conn = serial.Serial(self.serial_port, self.baud_rate, timeout=1.0)
        time.sleep(2)

Issue (and solution) that's causing it is described here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants