Ask Your Question

syntax error near unexpected token [SOLVED]

asked 2013-11-02 07:55:34 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi guys,

I am new in ros and i am having trouble with the odometry c++ publish turorial ( I am using the code in this link.

When i try to rosrun the program it gives me this:

line 5: syntax error near unexpected token `('

line 5: ` int main(int argc, char** argv){'

I don't understand why. BTW i am using groovy.

my c code is:

    #include <ros/ros.h>
    #include <tf/transform_broadcaster.h>
    #include <nav_msgs/Odometry.h>

int main(int argc, char** argv){
    ros::init(argc, argv, "odometry_publisher");

    ros::NodeHandle n;
    ros::Publisher odom_pub = n.advertise<nav_msgs::Odometry>("odom", 50);
    tf::TransformBroadcaster odom_broadcaster;

    double x = 0.0;
    double y = 0.0;
    double th = 0.0;

    double vx = 0.1;
    double vy = -0.1;
    double vth = 0.1;

    ros::Time current_time, last_time;
    current_time = ros::Time::now();
    last_time = ros::Time::now();

    ros::Rate r(1.0);
        current_time = ros::Time::now();

        //compute odometry in a typical way given the velocities of the robot
        double dt = (current_time - last_time).toSec();
        double delta_x = (vx * cos(th) - vy * sin(th)) * dt;
        double delta_y = (vx * sin(th) + vy * cos(th)) * dt;
        double delta_th = vth * dt;

        x += delta_x;
        y += delta_y;
        th += delta_th;

        //since all odometry is 6DOF we'll need a quaternion created from yaw
        geometry_msgs::Quaternion odom_quat = tf::createQuaternionMsgFromYaw(th);

        //first, we'll publish the transform over tf
        geometry_msgs::TransformStamped odom_trans;
        odom_trans.header.stamp = current_time;
        odom_trans.header.frame_id = "odom";
        odom_trans.child_frame_id = "base_link";

        odom_trans.transform.translation.x = x;
        odom_trans.transform.translation.y = y;
        odom_trans.transform.translation.z = 0.0;
        odom_trans.transform.rotation = odom_quat;

        //send the transform

        //next, we'll publish the odometry message over ROS
        nav_msgs::Odometry odom;
        odom.header.stamp = current_time;
        odom.header.frame_id = "odom";
        odom.child_frame_id = "base_link";

        //set the position
        odom.pose.pose.position.x = x;
        odom.pose.pose.position.y = y;
        odom.pose.pose.position.z = 0.0;
        odom.pose.pose.orientation = odom_quat;

        //set the velocity
        odom.twist.twist.linear.x = vx;
        odom.twist.twist.linear.y = vy;
        odom.twist.twist.angular.z = vth;

        //publish the message

        last_time = current_time;


edit retag flag offensive close merge delete


We need to see the code that you try to compile

yigit gravatar image yigit  ( 2013-11-02 08:42:59 -0500 )edit

Ok,sorry about the editing,i don't now why it appears like that!

trbf gravatar image trbf  ( 2013-11-02 09:02:20 -0500 )edit

It is because of indentation. It would be better if you shift your code to right by one tab, then paste it here. I'm not sure I understand it correctly but isn't there a problem with your "include"s?

yigit gravatar image yigit  ( 2013-11-02 09:22:08 -0500 )edit

Thanks, now it is better. Maybe is the includes but i don't know why...

trbf gravatar image trbf  ( 2013-11-03 12:25:37 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-11-05 15:02:36 -0500

trbf gravatar image

The problem is solved! I was trying to run de cpp file instead of the one made with the rosmake! It was a really nub problem! Thanks

edit flag offensive delete link more


Hello! I have the same problem :) which file is the one made with the rosmake? :(

Andrea019 gravatar image Andrea019  ( 2016-12-15 20:53:30 -0500 )edit

wow I knew I was a noob but I never imagined I was this much of a frikkin n0000b. Thanks for the thread.

trashperson gravatar image trashperson  ( 2020-01-25 20:56:58 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-11-02 07:55:34 -0500

Seen: 5,045 times

Last updated: Nov 05 '13