Commit 4bd6292 1 parent c03469e commit 4bd6292 Copy full SHA for 4bd6292
File tree 2 files changed +19
-4
lines changed
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 16
16
17
17
from launch import LaunchDescription
18
18
from launch_ros .actions import Node
19
+ from launch .actions import DeclareLaunchArgument
20
+ from launch .substitutions import LaunchConfiguration
21
+
22
+
23
+ port = DeclareLaunchArgument (
24
+ "port" ,
25
+ default_value = "/dev/pts/13" ,
26
+ description = "The gripper's serial port" ,
27
+ )
28
+ args = [port ]
19
29
20
30
21
31
def generate_launch_description ():
22
32
return LaunchDescription (
23
- [
33
+ args
34
+ + [
24
35
Node (
25
36
package = "schunk_gripper_driver" ,
26
37
namespace = "schunk" ,
27
38
executable = "driver.py" ,
28
39
name = "driver" ,
40
+ parameters = [
41
+ {"port" : LaunchConfiguration ("port" )},
42
+ ],
29
43
)
30
44
]
31
45
)
Original file line number Diff line number Diff line change @@ -28,12 +28,13 @@ class Driver(Node):
28
28
29
29
def __init__ (self , node_name : str , ** kwargs ):
30
30
super ().__init__ (node_name , ** kwargs )
31
- self .mb_client = ModbusSerialClient (
32
- port = " /dev/pts/13" , baudrate = 9600 , timeout = 1
33
- )
31
+ self .declare_parameter ( "port" , rclpy . Parameter . Type . STRING )
32
+ self . port = self . get_parameter_or ( " port" , " /dev/ttyUSB0" ). value
33
+ self . mb_client = ModbusSerialClient ( port = self . port , baudrate = 9600 , timeout = 1 )
34
34
35
35
def on_configure (self , state : State ) -> TransitionCallbackReturn :
36
36
self .get_logger ().info ("on_configure() is called." )
37
+ self .get_logger ().info (f"Connecting on port { self .port } " )
37
38
if not self .mb_client .connect ():
38
39
self .get_logger ().warn ("Modbus client connect failed" )
39
40
return TransitionCallbackReturn .FAILURE
You can’t perform that action at this time.
0 commit comments