Skip to content

Commit 43dd343

Browse files
authored
Merge pull request #26 from gsokoll/ros2
Added timeout parameter
2 parents 73fd71b + 936b424 commit 43dd343

14 files changed

+26
-11
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ documentation
2626
Documentation
2727
.idea
2828
# Visual Studio files
29+
.vscode
2930
.vs
3031
*.db
3132
*.pdb

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Configuration of the node is done by default via the configuration YAML file [`c
3535
- `port` - the virtual kernel device name for a port, `ttyUSB0` by default
3636
- `baud_rate` - port rate value to be used by the library for opening the port, _9600 baud_ by default
3737
- `polling_interval` - the sensor polling interval in milliseconds. If this parameter is omitted, the default value is set up by the library (50 ms).
38+
- `timeout_ms` - the sensor timeout period in milliseconds. If no data is received from the sensor after this period, then an error is raised and the node terminates. If this parameter is omitted, a default value of 3 times the polling interval is used. If this parameter is zero, the timeout check is disabled.
3839
- `restart_service_name` - the service name used to restart the sensor connection after an error.
3940
- `imu_publisher:`
4041
- `topic_name` - the topic name for IMU data publisher, `imu` in the node's namespace by default

config/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ witmotion:
33
port: ttyUSB0
44
baud_rate: 9600 # baud
55
polling_interval: 50 # ms
6+
timeout_ms: 150 # ms
67
restart_service_name: /restart_imu
78
imu_publisher:
89
topic_name: /imu

config/wt31n.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ witmotion_ros:
33
port: ttyUSB3
44
baud_rate: 115200 # baud
55
polling_interval: 10 # ms
6+
timeout_ms: 150 # ms
67
restart_service_name: /restart_imu
78
imu_publisher:
89
topic_name: /imu

config/wt61c.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ witmotion:
44
#port: /dev/ttyUSB0
55
baud_rate: 115200 # baud
66
polling_interval: 25 # ms
7+
timeout_ms: 150 # ms
78
restart_service_name: /restart_imu
89
imu_publisher:
910
topic_name: /imu_data

config/wt901.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ witmotion:
22
ros__parameters:
33
port: ttyUSB0
44
baud_rate: 115200 # baud
5-
polling_interval: 10 # ms
5+
polling_interval: 50 # ms
6+
timeout_ms: 150 # ms
67
restart_service_name: /restart_imu
78
imu_publisher:
89
topic_name: /imu

include/witmotion/witmotion_ros.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ROSWitmotionSensorController: public QObject, public rclcpp::Node
4444
std::string port_name;
4545
QSerialPort::BaudRate port_rate;
4646
uint32_t interval;
47+
uint32_t timeout_ms;
4748
QThread reader_thread;
4849
QBaseSerialWitmotionSensorReader* reader;
4950
static bool suspended;

include/witmotion_ros.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class ROSWitmotionSensorController: public QObject
4747
std::string port_name;
4848
QSerialPort::BaudRate port_rate;
4949
uint32_t interval;
50+
uint32_t timeout_ms;
5051
QThread reader_thread;
5152
QBaseSerialWitmotionSensorReader* reader;
5253
static bool suspended;

launch/witmotion.py launch/witmotion.launch.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ def generate_launch_description():
88
ld = LaunchDescription()
99

1010
config = os.path.join(
11-
get_package_share_directory('witmotion'),
11+
get_package_share_directory('witmotion_ros'),
1212
'config',
1313
'witmotion.yml'
1414
)
1515

1616
node=Node(
17-
package = 'witmotion',
17+
package = 'witmotion_ros',
1818
executable = 'witmotion_ros_node',
1919
parameters = [config]
2020
)

launch/wt31n.py launch/wt31n.launch.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ def generate_launch_description():
88
ld = LaunchDescription()
99

1010
config = os.path.join(
11-
get_package_share_directory('witmotion'),
11+
get_package_share_directory('witmotion_ros'),
1212
'config',
1313
'wt31n.yml'
1414
)
1515

1616
node=Node(
17-
package = 'witmotion',
17+
package = 'witmotion_ros',
1818
executable = 'witmotion_ros_node',
1919
parameters = [config]
2020
)

launch/wt61c.py launch/wt61c.launch.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ def generate_launch_description():
88
ld = LaunchDescription()
99

1010
config = os.path.join(
11-
get_package_share_directory('witmotion'),
11+
get_package_share_directory('witmotion_ros'),
1212
'config',
1313
'wt61c.yml'
1414
)
1515

1616
node=Node(
17-
package = 'witmotion',
17+
package = 'witmotion_ros',
1818
executable = 'witmotion_ros_node',
1919
parameters = [config]
2020
)

launch/wt901.py launch/wt901.launch.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ def generate_launch_description():
88
ld = LaunchDescription()
99

1010
config = os.path.join(
11-
get_package_share_directory('witmotion'),
11+
get_package_share_directory('witmotion_ros'),
1212
'config',
1313
'wt901.yml'
1414
)
1515

1616
node=Node(
17-
package = 'witmotion',
17+
package = 'witmotion_ros',
1818
executable = 'witmotion_ros_node',
1919
parameters = [config]
2020
)

src/witmotion_ros.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,21 @@ ROSWitmotionSensorController::ROSWitmotionSensorController()
440440
port_rate);
441441

442442
int int_interval;
443-
444443
node->declare_parameter("polling_interval", 10);
445444
int_interval = node->get_parameter("polling_interval")
446445
.get_parameter_value()
447446
.get<int>();
448447
interval = static_cast<uint32_t>(int_interval);
449448
reader->SetSensorPollInterval(interval);
450449

450+
int int_timeout_ms;
451+
node->declare_parameter("timeout_ms", 1000);
452+
int_timeout_ms = node->get_parameter("timeout_ms")
453+
.get_parameter_value()
454+
.get<int>();
455+
timeout_ms = static_cast<uint32_t>(int_timeout_ms);
456+
reader->SetSensorTimeout(int_timeout_ms);
457+
451458
reader->ValidatePackets(true);
452459
reader->moveToThread(&reader_thread);
453460
connect(&reader_thread, &QThread::finished, reader, &QObject::deleteLater);

0 commit comments

Comments
 (0)