ElettraSciComp / witmotion_IMU_ros

ROS wrapper for the family of IMU sensor devices manufactured by Witmotion Ltd.
MIT License
27 stars 31 forks source link

wit WT901C-TTC not detected on my raspberry pi4 #41

Closed ChehabiMed closed 3 months ago

ChehabiMed commented 3 months ago

Hello, I received lately the WT901C-TTC sensor and i connected the pins to my raspberry pi4 correctly, (Rx to Tx and Tx to Rx, Vcc to 5v ) but i cant detect the sensor on the serial using ls /dev/tty* i'm using ubuntu 20.4 server. Did i miss something? also i have no access to the datasheets.

twdragon commented 3 months ago

@ChehabiMed thank you for raising the issue because the IPFS gateways should be changed. I will fix it soon.

For the serial, if you want to use it on Raspberry, you should at first to configure pins in raspi-config as normal UART port, then to try to read the bytes from them using screen or minicom with connected and powered sensor

ChehabiMed commented 3 months ago

Thank you for your help, I was able to detect the sensor on the ttyS0 and could visualize characters using minicon on a baudrate of 9600.

Now i get an error with the default parameters of the wt901 when using the driver's launch. here is the output:

... logging to /home/ubuntu/.ros/log/2fe389bc-ec29-11ee-8009-eb857ae380be/roslaunch-ubuntu-2302.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://192.168.141.132:41195/

SUMMARY
========

PARAMETERS
 * /rosdistro: noetic
 * /rosversion: 1.16.0
 * /witmotion_imu/altimeter_publisher/addition: 0.0
 * /witmotion_imu/altimeter_publisher/coefficient: 1.0
 * /witmotion_imu/altimeter_publisher/enabled: False
 * /witmotion_imu/altimeter_publisher/topic_name: /altitude
 * /witmotion_imu/barometer_publisher/addition: 0.0
 * /witmotion_imu/barometer_publisher/coefficient: 1.0
 * /witmotion_imu/barometer_publisher/enabled: False
 * /witmotion_imu/barometer_publisher/frame_id: base_link
 * /witmotion_imu/barometer_publisher/topic_name: /barometer
 * /witmotion_imu/barometer_publisher/variance: 0.001
 * /witmotion_imu/baud_rate: 115200
 * /witmotion_imu/gps_publisher/enabled: False
 * /witmotion_imu/gps_publisher/ground_speed_topic_name: /gps_ground_speed
 * /witmotion_imu/gps_publisher/navsat_altitude_topic_name: /gps_altitude
 * /witmotion_imu/gps_publisher/navsat_fix_frame_id: world
 * /witmotion_imu/gps_publisher/navsat_fix_topic_name: /gps
 * /witmotion_imu/gps_publisher/navsat_satellites_topic_name: /gps_satellites
 * /witmotion_imu/gps_publisher/navsat_variance_topic_name: /gps_variance
 * /witmotion_imu/imu_publisher/frame_id: imu
 * /witmotion_imu/imu_publisher/measurements/acceleration/covariance: [0.0364, 0, 0, 0,...
 * /witmotion_imu/imu_publisher/measurements/acceleration/enabled: True
 * /witmotion_imu/imu_publisher/measurements/angular_velocity/covariance: [0.0663, 0, 0, 0,...
 * /witmotion_imu/imu_publisher/measurements/angular_velocity/enabled: True
 * /witmotion_imu/imu_publisher/measurements/orientation/covariance: [0.0479, 0, 0, 0,...
 * /witmotion_imu/imu_publisher/measurements/orientation/enabled: True
 * /witmotion_imu/imu_publisher/topic_name: /imu
 * /witmotion_imu/imu_publisher/use_native_orientation: True
 * /witmotion_imu/magnetometer_publisher/addition: 0.0
 * /witmotion_imu/magnetometer_publisher/coefficient: 1e-08
 * /witmotion_imu/magnetometer_publisher/covariance: [1.87123e-07, 0, ...
 * /witmotion_imu/magnetometer_publisher/enabled: True
 * /witmotion_imu/magnetometer_publisher/frame_id: compass
 * /witmotion_imu/magnetometer_publisher/topic_name: /magnetometer
 * /witmotion_imu/orientation_publisher/enabled: True
 * /witmotion_imu/orientation_publisher/topic_name: /orientation
 * /witmotion_imu/polling_interval: 10
 * /witmotion_imu/port: ttyS0
 * /witmotion_imu/restart_service_name: /restart_imu
 * /witmotion_imu/rtc_publisher/enabled: False
 * /witmotion_imu/rtc_publisher/topic_name: /witmotion_clock
 * /witmotion_imu/temperature_publisher/addition: 0.0
 * /witmotion_imu/temperature_publisher/coefficient: 1.0
 * /witmotion_imu/temperature_publisher/enabled: True
 * /witmotion_imu/temperature_publisher/frame_id: base_link
 * /witmotion_imu/temperature_publisher/from_message: magnetometer
 * /witmotion_imu/temperature_publisher/topic_name: /temperature
 * /witmotion_imu/temperature_publisher/variance: 0.01829
 * /witmotion_imu/timeout_ms: 150

NODES
  /
    witmotion_imu (witmotion_ros/witmotion_ros_node)

ROS_MASTER_URI=http://192.168.141.247:11311

process[witmotion_imu-1]: started with pid [2311]
Opening device "ttyS0" at 115200 baud
Instantiating timer at 10 ms
[ERROR] [1711538490.830615751]: Sensor error: Timed out waiting for data, please check device connection and baudrate!
[ INFO] [1711538490.957474678]: Entering SUSPENDED state
QObject::killTimer: Timers cannot be stopped from another thread
QObject::~QObject: Timers cannot be stopped from another thread
Suspending TTL connection, please emit RunPoll() again to proceed!
[ERROR] [1711538490.959535578]: Sensor error: Timed out waiting for data, please check device connection and baudrate!
[ INFO] [1711538490.959710150]: Entering SUSPENDED state
Suspending TTL connection, please emit RunPoll() again to proceed!
[ERROR] [1711538490.959948407]: Sensor error: Timed out waiting for data, please check device connection and baudrate!
[witmotion_imu-1] process has died [pid 2311, exit code -11, cmd /home/ubuntu/catkin_ws/devel/lib/witmotion_ros/witmotion_ros_node __name:=witmotion_imu __log:=/home/ubuntu/.ros/log/2fe389bc-ec29-11ee-8009-eb857ae380be/witmotion_imu-1.log].
log file: /home/ubuntu/.ros/log/2fe389bc-ec29-11ee-8009-eb857ae380be/witmotion_imu-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete

The log file:

Press Ctrl-C to interrupt
[roslaunch][INFO] 2024-03-27 11:30:11,391: Done checking log file disk usage. Usage is <1GB.
[roslaunch][INFO] 2024-03-27 11:30:11,392: roslaunch starting with args ['/opt/ros/noetic/bin/roslaunch', 'witmotion_ros', 'wt901.launch']
[roslaunch][INFO] 2024-03-27 11:30:11,392: roslaunch env is environ({'SHELL': '/bin/bash', 'ROS_VERSION': '1', 'PKG_CONFIG_PATH': '/home/ubuntu/catkin_ws/devel/lib/pkgconfig:/home/ubuntu/carbot_ws/devel>
[roslaunch][INFO] 2024-03-27 11:30:11,392: starting in server mode
[roslaunch.parent][INFO] 2024-03-27 11:30:11,393: starting roslaunch parent run
[roslaunch][INFO] 2024-03-27 11:30:11,393: loading roscore config file /opt/ros/noetic/etc/ros/roscore.xml
[roslaunch][INFO] 2024-03-27 11:30:11,881: Added core node of type [rosout/rosout] in namespace [/]
[roslaunch.config][INFO] 2024-03-27 11:30:11,882: loading config file /home/ubuntu/catkin_ws/src/witmotion_ros/launch/wt901.launch
[roslaunch][INFO] 2024-03-27 11:30:11,951: Added node of type [witmotion_ros/witmotion_ros_node] in namespace [/]
[roslaunch][INFO] 2024-03-27 11:30:11,951: ... selected machine [] for node of type [witmotion_ros/witmotion_ros_node]
[roslaunch.pmon][INFO] 2024-03-27 11:30:11,954: start_process_monitor: creating ProcessMonitor
[roslaunch.pmon][INFO] 2024-03-27 11:30:11,955: created process monitor <ProcessMonitor(ProcessMonitor-1, initial daemon)>
[roslaunch.pmon][INFO] 2024-03-27 11:30:11,955: start_process_monitor: ProcessMonitor started
[roslaunch.parent][INFO] 2024-03-27 11:30:11,956: starting parent XML-RPC server
[roslaunch.server][INFO] 2024-03-27 11:30:11,956: starting roslaunch XML-RPC server
[roslaunch.server][INFO] 2024-03-27 11:30:11,956: waiting for roslaunch XML-RPC server to initialize
[xmlrpc][INFO] 2024-03-27 11:30:11,957: XML-RPC server binding to 0.0.0.0:0
[xmlrpc][INFO] 2024-03-27 11:30:11,957: Started XML-RPC server [http://192.168.141.132:44925/]
[xmlrpc][INFO] 2024-03-27 11:30:11,958: xml rpc node: starting XML-RPC server
[roslaunch][INFO] 2024-03-27 11:30:11,971: started roslaunch server http://192.168.141.132:44925/
[roslaunch.parent][INFO] 2024-03-27 11:30:11,971: ... parent XML-RPC server started
[roslaunch][INFO] 2024-03-27 11:30:11,973: master.is_running[http://192.168.141.247:11311]
[roslaunch][INFO] 2024-03-27 11:30:12,180: master.is_running[http://192.168.141.247:11311]
[roslaunch][INFO] 2024-03-27 11:30:12,282: ROS_MASTER_URI=http://192.168.141.247:11311
[roslaunch][INFO] 2024-03-27 11:30:12,385: setting /roslaunch/uris/host_192_168_141_132__44925' to http://192.168.141.132:44925/
[roslaunch][INFO] 2024-03-27 11:30:12,394: load_parameters starting ...
[roslaunch][INFO] 2024-03-27 11:30:12,728: ... load_parameters complete
[roslaunch][INFO] 2024-03-27 11:30:12,729: launch_nodes: launching local nodes ...
[roslaunch][INFO] 2024-03-27 11:30:12,729: ... preparing to launch node of type [witmotion_ros/witmotion_ros_node]
[roslaunch][INFO] 2024-03-27 11:30:12,729: create_node_process: package[witmotion_ros] type[witmotion_ros_node] machine[Machine(name[] env_loader[None] address[localhost] ssh_port[22] user[None] assigna>
[roslaunch][INFO] 2024-03-27 11:30:12,730: process[witmotion_imu-1]: env[{'SHELL': '/bin/bash', 'ROS_VERSION': '1', 'PKG_CONFIG_PATH': '/home/ubuntu/catkin_ws/devel/lib/pkgconfig:/home/ubuntu/carbot_ws/>
[roslaunch][INFO] 2024-03-27 11:30:12,771: process[witmotion_imu-1]: args[['/home/ubuntu/catkin_ws/devel/lib/witmotion_ros/witmotion_ros_node', '__name:=witmotion_imu']]
[roslaunch][INFO] 2024-03-27 11:30:12,772: ... created process [witmotion_imu-1]
[roslaunch.pmon][INFO] 2024-03-27 11:30:12,772: ProcessMonitor.register[witmotion_imu-1]
[roslaunch.pmon][INFO] 2024-03-27 11:30:12,772: ProcessMonitor.register[witmotion_imu-1] complete
[roslaunch][INFO] 2024-03-27 11:30:12,772: ... registered process [witmotion_imu-1]
[roslaunch][INFO] 2024-03-27 11:30:12,772: process[witmotion_imu-1]: starting os process
[roslaunch][INFO] 2024-03-27 11:30:12,773: process[witmotion_imu-1]: start w/ args [['/home/ubuntu/catkin_ws/devel/lib/witmotion_ros/witmotion_ros_node', '__name:=witmotion_imu', '__log:=/home/ubuntu/.r>
[roslaunch][INFO] 2024-03-27 11:30:12,773: process[witmotion_imu-1]: cwd will be [/home/ubuntu/.ros]
[roslaunch][INFO] 2024-03-27 11:30:12,783: process[witmotion_imu-1]: started with pid [2374]
[roslaunch][INFO] 2024-03-27 11:30:12,783: ... successfully launched [witmotion_imu-1]
[roslaunch][INFO] 2024-03-27 11:30:12,784: ... launch_nodes complete
[roslaunch.pmon][INFO] 2024-03-27 11:30:12,784: registrations completed <ProcessMonitor(ProcessMonitor-1, started daemon 281473061581280)>
[roslaunch.parent][INFO] 2024-03-27 11:30:12,784: ... roslaunch parent running, waiting for process exit
[roslaunch][INFO] 2024-03-27 11:30:12,784: spin
[roslaunch][ERROR] 2024-03-27 11:30:18,475: [witmotion_imu-1] process has died [pid 2374, exit code -11, cmd /home/ubuntu/catkin_ws/devel/lib/witmotion_ros/witmotion_ros_node __name:=witmotion_imu __log>
log file: /home/ubuntu/.ros/log/2fe389bc-ec29-11ee-8009-eb857ae380be/witmotion_imu-1*.log
[roslaunch.pmon][INFO] 2024-03-27 11:30:18,476: ProcessMonitor.unregister[witmotion_imu-1] starting
[roslaunch.pmon][INFO] 2024-03-27 11:30:18,476: ProcessMonitor.unregister[witmotion_imu-1] complete
[roslaunch][INFO] 2024-03-27 11:30:18,476: all processes on machine have died, roslaunch will exit
[roslaunch.pmon][INFO] 2024-03-27 11:30:18,577: ProcessMonitor._post_run <ProcessMonitor(ProcessMonitor-1, started daemon 281473061581280)>
[roslaunch.pmon][INFO] 2024-03-27 11:30:18,577: ProcessMonitor._post_run <ProcessMonitor(ProcessMonitor-1, started daemon 281473061581280)>: remaining procs are []
[roslaunch.pmon][INFO] 2024-03-27 11:30:18,579: ProcessMonitor exit: cleaning up data structures and signals
[roslaunch.pmon][INFO] 2024-03-27 11:30:18,580: ProcessMonitor exit: pmon has shutdown
[roslaunch][INFO] 2024-03-27 11:30:18,593: process monitor is done spinning, initiating full shutdown
[roslaunch][INFO] 2024-03-27 11:30:18,593: runner.stop()
[roslaunch][INFO] 2024-03-27 11:30:18,593: shutting down processing monitor...
[roslaunch][INFO] 2024-03-27 11:30:18,593: shutting down processing monitor <ProcessMonitor(ProcessMonitor-1, stopped daemon 281473061581280)>
[roslaunch.pmon][INFO] 2024-03-27 11:30:18,594: ProcessMonitor.shutdown <ProcessMonitor(ProcessMonitor-1, stopped daemon 281473061581280)>
[roslaunch][INFO] 2024-03-27 11:30:18,594: ... shutting down processing monitor complete
[roslaunch][INFO] 2024-03-27 11:30:18,594: done
[roslaunch.pmon][INFO] 2024-03-27 11:30:18,594: ProcessMonitor.shutdown <ProcessMonitor(ProcessMonitor-1, stopped daemon 281473061581280)>
[rospy.core][INFO] 2024-03-27 11:30:18,594: signal_shutdown [atexit]

I appreciate your help.

ChehabiMed commented 3 months ago

update: After setting some parameters to default values and using frequency of 100Hz using this commands:

rosrun witmotion_ros witmotionctl-wt901 -d /dev/ttyS0 --set-baudrate 9600
rosrun witmotion_ros witmotionctl-wt901 -d /dev/ttyS0 -b 115200 --set-frequency 100
rosrun witmotion_ros witmotionctl-wt901 -d /dev/ttyS0 -b 115200 -i 50

and this command to test the communication: rosrun witmotion_ros message-enumerator -d ttyS0 -b 9600 -p 50

I get this output:

Press Ctrl+C to stop enumeration and see the report
Opening device "ttyS0" at 9600 baud
Instantiating timer at 50 ms
ERROR: Timed out waiting for data, please check device connection and baudrate!
Closing TTL connection

WITMOTION UART MESSAGE ENUMERATOR BY TWDRAGON

Acquired at Wednesday, 27 March 2024 13:28:48 UTC

ID  Qty Description

0x51    11  Accelerations
0x52    10  Angular velocities
0x53    10  Spatial orientation (Euler angles)
0x54    10  Magnetometer/Magnetic orientation

    Unknown IDs: 0 [  ] 
Total messages: 41

Also i had to change this parameter in the config file use_native_orientation to false, only after that i was able to see messages published on the /imu topic, but only for a short time!

ChehabiMed commented 3 months ago

Update: My node is publishing data now with a baud rate of 9600 and a polling time of 5ms, the only thing i did is to reboot my Rpy! apparently some changes took effect only after a reboot

twdragon commented 3 months ago

@ChehabiMed please make sure that the hardware is able to publish on this frequency with the baudrate 9600 baud. I think, then we can close the issue if the error does not persist.

ChehabiMed commented 3 months ago

I am running into the same problems again once i reboot my Rpy, maybe because i misunderstood the use of the commands i used! The problem i am having now is with the port ttyS0 who disable the permissions for the groups everytime i run the launch or one of the commands i used before, is that due to communication failure? Can you please confirm the role of the following commands:

rosrun witmotion_ros witmotionctl-wt901 -d /dev/ttyS0 --set-baudrate 9600 to set the baudrate of the sensor to 9600

rosrun witmotion_ros witmotionctl-wt901 -d /dev/ttyS0 -b 115200 --set-frequency 100 to set the frequency of the sensor to 100Hz

rosrun witmotion_ros witmotionctl-wt901 -d /dev/ttyS0 -b 115200 -i 50 to set the polling time on the sensor to 50ms

rosrun witmotion_ros message-enumerator -d ttyS0 -b 9600 -p 50 To test the communication with a 9600 baudrate and 50ms polling time

I did notice that i am required to reconnect after each command, do that means to reconnect the cables of the sensor or reboot the system?

Thank you for your clarifications

ChehabiMed commented 3 months ago

communication was not possible: i hade always a service called agetty running after a reboot and taking the ttyS0 port, this service is always running and defining the permissions for the ttyS0 port and his group, whenever i change the permissions, they are set back to default and taking off permissions for groups again and again. here's the service running on the port: ubuntu@ubuntu:~$ sudo ps aux | grep ttyS0

root        1644  0.1  0.0   6836  1904 ttyS0    Ss+  13:31   0:00 /sbin/agetty -o -p -- \u --keep-baud 115200,38400,9600 ttyS0 vt220
ubuntu      1646  0.0  0.0   7696   644 pts/2    S+   13:31   0:00 grep --color=auto ttyS0

this commande helped me find the responsible service: grep -ri serial /lib/systemd/system

/lib/systemd/system/getty@.service:Documentation=http://0pointer.de/blog/projects/serial-console.html
/lib/systemd/system/getty@.service:# that serial gettys are covered by serial-getty@.service, not this 
/lib/systemd/system/getty.target:Documentation=http://0pointer.de/blog/projects/serial-console.html
/lib/systemd/system/serial-getty@.service:Description=Serial Getty on %I 
/lib/systemd/system/serial-getty@.service:Documentation=http://0pointer.de/blog/projects/serial-console.html
/lib/systemd/system/getty-pre.target:Documentation=http://0pointer.de/blog/projects/serial-console.html
/lib/systemd/system/wacom-inputattach@.service:Description=inputattach for Wacom ISDv4-compatible serial devices 
/lib/systemd/system/wacom-inputattach@.service:ExecStart=/usr/bin/isdv4-serial-inputattach /dev/%I 

I solved the problem by modifying this file:

cat /lib/systemd/system/serial-getty@.service

#  SPDX-License-Identifier: LGPL-2.1+ 
# 
#  This file is part of systemd. 
# 
#  systemd is free software; you can redistribute it and/or modify it 
#  under the terms of the GNU Lesser General Public License as published by 
#  the Free Software Foundation; either version 2.1 of the License, or 
#  (at your option) any later version. 
[Unit] 
Description=Serial Getty on %I 
Documentation=man:agetty(8) man:systemd-getty-generator(8) 
Documentation=http://0pointer.de/blog/projects/serial-console.html
BindsTo=dev-%i.device 
After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service [getty-pre.target](http://getty-pre.target/)
After=rc-local.service 
# If additional gettys are spawned during boot then we should make 
# sure that this is synchronized before [getty.target](http://getty.target/), even though
# [getty.target](http://getty.target/) didn't actually pull it in.
[Before=getty.target](http://before=getty.target/)
IgnoreOnIsolate=yes 
# IgnoreOnIsolate causes issues with sulogin, if someone isolates 
# [rescue.target](http://rescue.target/) or starts rescue.service from [multi-user.target](http://multi-user.target/) or
# [graphical.target](http://graphical.target/).
Conflicts=rescue.service 
Before=rescue.service 
[Service] 
# The '-o' option value tells agetty to replace 'login' arguments with an 
# option to preserve environment (-p), followed by '--' for safety, and then 
# the entered username. 
ExecStart=-/sbin/agetty -o '-p -- \\u' --keep-baud 115200,38400,9600 %I $TERM 
Type=idle 
Restart=always 
UtmpIdentifier=%I 
TTYPath=/dev/%I 
TTYReset=yes 
TTYVHangup=yes 
KillMode=process 
IgnoreSIGPIPE=no 
SendSIGHUP=yes 
[Install] 
[WantedBy=getty.target](http://wantedby=getty.target/)

I did comment the Restart option set to Always as follow: #Restart=always

and kill the process after a reboot using this command on .bashrc:

sudo pkill agetty

now i was able to set permissions permanently and modifying the group of ttyS0 as follow:

sudo chown root:dialout /dev/ttyS0 sudo chmod g+rw /dev/ttyS0

Only after that the communication with my sensor worked without interruptions (before is worked for 2 seconds and disconnected because of the permissions being changed from the service).

This Conversation was helpful.

I think this is a problem present on many of linux OS! (I'm using ubuntu 20.04 server) i don't have the same problem on the ubuntu 20.04 on my computer.

(not sure of the consequences of my modification on the service file, but for now it's working well.)