ROS service server and client node to publish on serial port
Hi
I need to create ROS SERVICE server and client node that check lets say IMU sensor data and publish the IMU value on serial port. So I though the only way is to create two separates nodes for server and client. I create them but not sure that's the correct way of implementation in python (Im more familiar with C++ but in this case have to use python as my midlleware and firmware are in python and easier ti import all those library in python). Here is the server node python:
#!/usr/bin/env python3
import rospy
from std_msgs.msg import String
import Microcontroller_Manager_Serial as Serial
import IMU_Functions as IMU
from ros_services.srv import RosService,ImuResponse
def handle_ros_service(data_received_imu):
rospy.init_node('imu_server')
data_received_imu = IMU.IMU_Get_Values(1, 1)
Imu = (np.int16((data_received_imu[6]<<24) | (data_received_imu[7]<<16) | (data_received_imu[8]<<8) | (data_received_imu[9])))/10000
return ImuResponse(data_received_imu.Imu)
def publish_on_serial():
Imu = data_out
data_out = Serial.Serial_Port_Send_Data(20,0.2)
data_out = rospy.Service('add_two_ints', RosService, handle_ros_service)
rospy.spin()
if __name__ == "__main__":
publish_on_serial()
And here is the client node python:
#!/usr/bin/env python3
import sys
import rospy
from ros_services.srv import RosService,ImuResponse
# init a node as usual
rospy.init_node('imu_service_client')
# wait for this service to be running
def imu_client(imu_data):
rospy.wait_for_service('imu_service')
imu_client = rospy.ServiceProxy('imu_service', ImuResponse)
So, Im not sure these is correct. Any help? And also i search online but so far I understand the server and client can not be in the same node , is that correct? Or using service and client in same node is possible?
Thanks