Ask Your Question
0

Problem with twist message: unqualified-id before numeric constant

asked 2012-11-12 12:33:47 -0500

0pc0 gravatar image

Hi folks!

I'm having a bit of trouble assigning values to a Twist type message, my code below runs into an error:

    /home/parcon/ros_workspace/arl_ardrone/arl_ardrone_control/src/pid_to_point.cpp:183:22: error: expected unqualified-id before numeric constant
/home/parcon/ros_workspace/arl_ardrone/arl_ardrone_control/src/pid_to_point.cpp:183:22: error: expected ‘;’ before numeric constant
/home/parcon/ros_workspace/arl_ardrone/arl_ardrone_control/src/pid_to_point.cpp:184:22: error: expected unqualified-id before numeric constant
/home/parcon/ros_workspace/arl_ardrone/arl_ardrone_control/src/pid_to_point.cpp:184:22: error: expected ‘;’ before numeric constant
/home/parcon/ros_workspace/arl_ardrone/arl_ardrone_control/src/pid_to_point.cpp:185:22: error: expected unqualified-id before numeric constant
/home/parcon/ros_workspace/arl_ardrone/arl_ardrone_control/src/pid_to_point.cpp:185:22: error: expected ‘;’ before numeric constant
/home/parcon/ros_workspace/arl_ardrone/arl_ardrone_control/src/pid_to_point.cpp:186:23: error: expected unqualified-id before numeric constant
/home/parcon/ros_workspace/arl_ardrone/arl_ardrone_control/src/pid_to_point.cpp:186:23: error: expected ‘;’ before numeric constant

The error comes from the last few lines of the code where the Twist message values are assigned. I've looked at the types, the definition of Twist, with no success. Can anyone see where I'm going wrong? I expect to be able to assign a float to this value: twist_msg.linear.x

Thanks for the help!

/*
     *  Copyright (c) 2012, Parker Conroy
     *  ARLab @ University of Utah
     *  All rights reserved.
     *
     *
     *  
     *
     *
     *
     *  This software is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     */
    #include "ros/ros.h"
    #include <math.h>
    #include <tf/transform_broadcaster.h>
    #include "tf/transform_listener.h"
    #include "geometry_msgs/TransformStamped.h"
    #include "ros/time.h"
    #include <geometry_msgs/Twist.h>

    #define yaw 0
    #define pitch 1
    #define roll 2
    #define thrust 3

    #define x 0
    #define y 1
    #define z 2
    #define t 3

     // Variables!!!
    tf::Transformer transformer;
    tf::TransformListener tf_listener;
    tf::TransformBroadcaster br;

    tf::StampedTransform desired_pos;
    tf::StampedTransform ardrone;
    tf::StampedTransform trackee;
    tf::StampedTransform desired_in_ardrone_coords;

    ros::Publisher pub_twist;
    geometry_msgs::Twist twist_msg;

    //btQuaternion ardrone_yawed;

    double new_data[4];
    double old_data[4];
    double integration[4];
    double derivative[4];
    float controls[4];
    float min_control[4];
    float max_control[4];
    double pid[4];
    float min_pid;
    float max_pid;

    float map(float value, float in_min, float in_max, float out_min, float out_max) {
      return (float)((value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min);
    }

    int main(int argc, char **argv)
    {
        int rate= 200;
        float inv_rate=1/rate;

        ros::init(argc, argv, "Tracker");
        ros::NodeHandle n;
        ros::Rate r(200); //update @ 200hz

        memset(controls, 0, sizeof(int64_t)*4);
        memset(old_data, 0, sizeof(double)*4);
        memset(new_data, 0, sizeof(double)*4);
        memset(integration, 0, sizeof(double)*4);
        memset(derivative, 0, sizeof(double)*4);
        memset(pid, 0, sizeof(double)*4);

        //PID params
        min_control[yaw] =-1.0;
        min_control[roll] =-1.0;
        min_control[pitch]=-1.0;
        min_control[thrust]=-1.0;

        max_control[yaw]=1.0;
        max_control[roll]=1.0;
        max_control[pitch]=1.0;
        max_control[thrust]=1.0;

        min_pid =-5.0;
        max_pid =5.0;

        float K_p[] = {1, 1, 1};
        float K_d[] = {0,0,0};
        float K_i ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
3

answered 2012-11-12 15:55:03 -0500

jbohren gravatar image

updated 2012-11-12 15:59:36 -0500

If you #define x 0 then twist.linear.x is going to turn into twist.linear.0 after the preprocessor.

Don't #define single characters unless you hate happiness.

More here: #defines are EVIL

As an aside, if you look at your preprocessor output, you'll find that your variables like max_pid are actually going to be ma0_pid and so on and so forth... So yeah, don't ever do this.

edit flag offensive delete link more

Comments

Thank you sir! I've learned my lesson.

0pc0 gravatar image 0pc0  ( 2012-11-13 09:16:55 -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

Stats

Asked: 2012-11-12 12:33:47 -0500

Seen: 1,520 times

Last updated: Nov 12 '12