error python serial ros arduino

asked 2016-04-20 15:51:50 -0600

g-emad gravatar image

i am trying to make a node to send the ROS time to the arduino all the time through serial and am getting this error

syntax error near unexpected token `('
/home/gemad/catkin_ws/src/hello_world/scripts/ros_time_arduino.py: line 5: `ser = serial.Serial('/dev/ttyACM1',115200)'

the code of the node is :

import rospy 
import serial


ser = serial.Serial('/dev/ttyACM1',115200)
rospy.init_node('ros_time_arduino')

while not rospy.is_shutdown():
   ros_time = rospy.get_rostime()
   ser.write(ros_time)   
   mont=ser.readline()
   print(mont)

any ide about what is wrong ?

edit retag flag offensive close merge delete

Comments

first of all, does your user have permissions to access the serial port?

second, ros_time is of type 'rospy.rostime.Time' so you can't write that directly to the serial port, you should do something like ros_time = ser.write(str(ros_time)) to send the time.

Gary Servin gravatar image Gary Servin  ( 2016-04-26 10:22:29 -0600 )edit