Robotics StackExchange | Archived questions

ROS on python

hi, i wrote my program of node with python and i receive an error of syntaxe. can you help me please? my program:

 security_distance = 25
    if d1 < security_distance:
        if (d0 < security_distance) and (d2 < security_distance):
            moteur_msg = 0
            rospy.loginfo(moteur_msg)
            pub_moteur.publish(moteur_msg)
            time.sleep(2)
            if d0 > d2:
                servo_msg = 2
                rospy.loginfo(servo_msg)
                pub_servo.publish(servo_msg)
            else:
                servo_msg = 3
                rospy.loginfo(servo_msg)
                pub_servo.publish(servo_msg)

        elif (d0 < security_distance) and (d2 > security_distance):
            moteur_msg = 3
            rospy.loginfo(moteur_msg)
            pub_moteur.publish(moteur_msg
        elif (d0 > security_distance) and (d2 < security_distance):
            moteur_msg = 2
            rospy.loginfo(moteur_msg)
            ub_moteur.publish(moteur_msg
        elif (d0 > security_distance) and (d2 > security_distance):                                      
            if d0 > d2:
                servo_msg = 2
                rospy.loginfo(servo_msg)
                pub_servo.publish(servo_msg)
            else:
                servo_msg = 3
                rospy.loginfo(servo_msg)
                pub_servo.publish(servo_msg)
    else:                                             
        moteur_msg = 3
        rospy.loginfo(moteur_msg)
        pub_moteur.publish(moteur_msg)

i receive this error:

pi@raspberrypi:~ $ rosrun control control.py
  File "/home/pi/catkin_ws/src/control/script/control.py", line 82
    elif (d0 > security_distance) and (d2 < security_distance):
       ^
SyntaxError: invalid syntax

Asked by Emilien on 2016-05-05 18:15:07 UTC

Comments

The error is there to give you a hint, look at line 81

Asked by Mehdi. on 2016-05-06 04:23:59 UTC

Answers

You're missing a close parenthesis on this line:

ub_moteur.publish(moteur_msg 

Asked by robustify on 2016-05-05 19:00:51 UTC

Comments

Same thing four lines higher as well.

Asked by robustify on 2016-05-05 19:01:58 UTC