0
$\begingroup$

Rosanswers logo

i wrote fdisplay.cpp in src folder, when i run rosmake , i have error .

    #include <ros/ros.h>
#include <tf/transform_broadcaster.h>
#include <tf/transform_listener.h>
#include <geometry_msgs/WrenchStamped.h>
#include <geometry_msgs/Vector3Stamped.h>
#include <visualization_msgs/Marker.h>

class Transforms{
public:
    Transforms();
    void f1Callback(const geometry_msgs::WrenchStamped&);
    void f2Callback(const geometry_msgs::WrenchStamped&);
    void DrawFn(int,char*,geometry_msgs::Vector3Stamped,int);

    geometry_msgs::Vector3Stamped f1ft,f2ft;
    geometry_msgs::PointStamped f1cl,f2cl;
    geometry_msgs::PointStamped start;

    ros::NodeHandle node;
    tf::TransformListener listener;
    ros::Subscriber f1_sub,f2_sub;
    ros::Publisher marker_pub;
    visualization_msgs::Marker marker;
private:

};

Transforms::Transforms(){
    marker_pub = node.advertise<visualization_msgs::Marker>("fmarker", 10);
    start.point.x=0;
    start.point.y=0;
    start.point.z=0;

}
void Transforms::DrawFn(int id,char* frame, geometry_msgs::Vector3Stamped vector,int color){
    marker.header.frame_id = frame;
    marker.header.stamp = ros::Time();
    marker.ns = "my_namespace";
    marker.id = id;
    marker.type = visualization_msgs::Marker::ARROW;
    marker.action = visualization_msgs::Marker::ADD;
    marker.pose.position.x = 0;
    marker.pose.position.y = 0;
    marker.pose.position.z = 0;
    marker.pose.orientation.x = 0.0;
    marker.pose.orientation.y = 0.0;
    marker.pose.orientation.z = 0.0;
    marker.pose.orientation.w = 1.0;
    marker.scale.x = 0.008;
    marker.scale.y = 0.02;
    marker.scale.z = 0.0;
    marker.color.a = 1.0;
    marker.color.r = 1.0;
    marker.color.g = 0.0;
    marker.color.b = 0.0;
    marker.set_points_size(2);
    marker.points[0].x=(start.point.x)/1000;
    marker.points[0].y=(start.point.y)/1000;
    marker.points[0].z=(start.point.z)/1000;
    marker.points[1].x=start.point.x/1000+vector.vector.x/100;
    marker.points[1].y=start.point.y/1000+vector.vector.y/100;
    marker.points[1].z=start.point.z/1000+vector.vector.z/100;

    marker_pub.publish(marker);

}

void Transforms::f1Callback(const geometry_msgs::WrenchStamped& msg){
    f1ft.vector=msg.wrench.force;
}


void Transforms::f2Callback(const geometry_msgs::WrenchStamped& msg){
    f2ft.vector=msg.wrench.force;
}



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


    Transforms Trans;

    Trans.f1_sub=Trans.node.subscribe("finger1/nano17ft",1000,&Transforms::f1Callback,&Trans);
        Trans.f2_sub=Trans.node.subscribe("finger2/nano17ft",1000,&Transforms::f2Callback,&Trans);

    ros::Rate rate(10.0);
    ros::Time now;
    geometry_msgs::Vector3Stamped wvect,weight,weight1;

    tf::Vector3 weight2;
    tf::Transformer TransClass;
    tf::StampedTransform transform;
    tf::Stamped<tf::Vector3> vaux,w2;


    while (Trans.node.ok()){


        Trans.DrawFn(1,"/BHand/FingerOne/Sensor",Trans.f1ft,1);
        Trans.DrawFn(2,"/BHand/FingerTwo/Sensor",Trans.f2ft,1);




        //DRAW WEIGHT:

        //FINGER 1
        tf::vector3StampedMsgToTF(Trans.f1ft,vaux);

        try{
            now = ros::Time::now();
            vaux.frame_id_="/BHand/FingerOne/Sensor";
            vaux.stamp_=now;

            Trans.listener.waitForTransform("/BHand/FingerOne/Sensor", "/robot_base",   now, ros::Duration(3.0));
            Trans.listener.lookupTransform("/BHand/FingerOne/Sensor", "/robot_base",now/*ros::Time(0)*/, transform);
            Trans.listener.transformVector("/robot_base",vaux,w2);
            tf::vector3TFToMsg(w2,wvect.vector);

            weight=wvect;

    }
    catch (tf::TransformException ex){
            ROS_ERROR("%s",ex.what());
        }
        try{

            //FINGER 2
            tf::vector3StampedMsgToTF(Trans.f2ft,vaux);
            now = ros::Time::now();
            vaux.frame_id_="/BHand/FingerTwo/Sensor";
            vaux.stamp_=now;

            Trans.listener.waitForTransform("/BHand/FingerTwo/Sensor", "/robot_base",now, ros::Duration(3.0));
            Trans.listener.lookupTransform("/BHand/FingerTwo/Sensor", "/robot_base",now, transform);
            Trans.listener.transformVector("/robot_base",vaux,w2);
            tf::vector3TFToMsg(w2,wvect.vector);

            weight.vector.x=weight.vector.x+wvect.vector.x;
            weight.vector.y=weight.vector.y+wvect.vector.y;
            weight.vector.z=weight.vector.z+wvect.vector.z;

            Trans.DrawFn(5,"/robot_base",weight,3);
            printf("Weight:%f %f %f = %f\n",weight.vector.x,weight.vector.y,weight.vector.z,sqrt(weight.vector.x*weight.vector.x+weight.vector.y*weight.vector.y+weight.vector.z*weight.vector.z));
        }
        catch (tf::TransformException ex){
            ROS_ERROR("%s",ex.what());
        }

        ros::spinOnce();
        rate.sleep();
    }
    return 0;
};

error :

  Scanning dependencies of target rospack_genmsg_libexe
  [  0%] Built target rospack_genmsg_libexe
  Scanning dependencies of target rosbuild_precompile
  [  0%] Built target rosbuild_precompile
  Scanning dependencies of target fdisplay
  [ 50%] Building CXX object CMakeFiles/fdisplay.dir/src/fdisplay.cpp.o
  /home/zakizadeh/catkin_ws6/src/tf_workshop/src/fdisplay.cpp: In member function ‘void Transforms::DrawFn(int, char*, geometry_msgs::Vector3Stamped, int)’:
  /home/zakizadeh/catkin_ws6/src/tf_workshop/src/fdisplay.cpp:62:9: error: ‘visualization_msgs::Marker’ has no member named ‘set_points_size’
    marker.set_points_size(2);
           ^
  /home/zakizadeh/catkin_ws6/src/tf_workshop/src/fdisplay.cpp: In function ‘int main(int, char**)’:
  /home/zakizadeh/catkin_ws6/src/tf_workshop/src/fdisplay.cpp:107:56: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
     Trans.DrawFn(1,"/BHand/FingerOne/Sensor",Trans.f1ft,1);
                                                          ^
  /home/zakizadeh/catkin_ws6/src/tf_workshop/src/fdisplay.cpp:108:56: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
     Trans.DrawFn(2,"/BHand/FingerTwo/Sensor",Trans.f2ft,1);
                                                          ^
  /home/zakizadeh/catkin_ws6/src/tf_workshop/src/fdisplay.cpp:151:41: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
      Trans.DrawFn(5,"/robot_base",weight,3);
                                           ^
  make[2]: *** [CMakeFiles/fdisplay.dir/src/fdisplay.cpp.o] Error 1
  make[1]: *** [CMakeFiles/fdisplay.dir/all] Error 2

Originally posted by zakizadeh on ROS Answers with karma: 217 on 2017-03-05

Post score: 0


Original comments

Comment by ahendrix on 2017-03-05:
This compiler error is trying to tell you that the set_points_size method doesn't exist on a visualization_msgs::Marker object.

Comment by zakizadeh on 2017-03-05:
what can i do ?? i need points_size

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

No, you don't need points_size . You need to set the size of the points vector within the marker object. Since points is a std::vector, I would start with the std::vector documentation.

From the std::vector documentation, you should look for a method that sets the size of the vector, and you should find the resize method. Now you know that the proper way to set the size of marker.points is marker.points.resize(2)


Originally posted by ahendrix with karma: 47576 on 2017-03-06

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by zakizadeh on 2017-03-06:
thanks a lot .

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.