44import math
55import rclpy
66from rclpy .node import Node
7+ from std_msgs .msg import Float64
78
89# Initialize serial communication for actuator control
910serial_port = "/dev/ttyUSB0" # Update with your port
@@ -60,9 +61,9 @@ class BoatControlNode(Node):
6061
6162 def __init__ (self ):
6263 super ().__init__ ('boat_control_node' )
63- self .compass_pub = self .create_publisher (BoatHeading , '/compass' , 10 )
64- self .heading_sub = self .create_subscriber (Float64 , '/desired_heading' , self .heading_callback , 10 )
65- self .speed_sub = self .create_subscriber (Float64 , '/desired_speed' , self .speed_callback , 10 )
64+ self .compass_pub = self .create_publisher (Float64 , '/compass' , 10 )
65+ self .heading_sub = self .create_subscription (Float64 , '/desired_heading' , self .heading_callback , 10 )
66+ self .speed_sub = self .create_subscription (Float64 , '/desired_speed' , self .speed_callback , 10 )
6667 self .current_heading = None
6768 timer_period = 1 # Seconds
6869 self .timer = self .create_timer (timer_period , self .timer_callback )
@@ -72,8 +73,8 @@ def timer_callback(self):
7273 current_heading = get_heading_command ()
7374 current_heading = get_heading_command ()# dual reading to flush !
7475
75- msg = BoatHeading ()
76- msg .heading = current_heading
76+ msg = Float64 ()
77+ msg .data = current_heading
7778 self .compass_pub .publish (msg )
7879
7980 def heading_callback (self , heading ):
@@ -94,9 +95,9 @@ def main():
9495 try :
9596 time .sleep (0.5 )
9697 response = ser .readline ().decode ().strip () # Read response from the actuator
97- print (f"Received: { response } " )
98+ print (f"Received: { response } \n " )
9899 response = ser .readline ().decode ().strip () # Read response from the actuator
99- print (f"Received: { response } " )
100+ print (f"Received: { response } \n " )
100101 send_enable_command ()
101102 time .sleep (1 )
102103 send_calib_command ()
0 commit comments