ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Error: no matching function for call to ‘std::vector<double>::back(double&)

asked 2022-07-04 19:04:13 -0600

lutinplunder gravatar image

I am writing a node to move my robots abdomen the same angle as the body pitch but opposite direction and I am getting an error during compiling

Errors     << abdomen:make /home/robdome/shelob_ws/logs/abdomen/build.make.010.log /home/robdome/shelob_ws/src/abdomen/src/abdomen.cpp: In member function ‘void Abdomen::callback(const Twist&)’: /home/robdome/shelob_ws/src/abdomen/src/abdomen.cpp:31:71: error: no matching function for call to ‘std::vector<double>::back(double&)’   31 |         desired_joint_state_publisher_.publish(output.position.back(ab));
      |                                                                       ^ In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/boost/math/special_functions/math_fwd.hpp:26,
                 from /usr/include/boost/math/special_functions/round.hpp:15,
                 from /opt/ros/noetic/include/ros/time.h:58,
                 from /opt/ros/noetic/include/ros/ros.h:38,
                 from /home/robdome/shelob_ws/src/abdomen/src/abdomen.cpp:6: /usr/include/c++/9/bits/stl_vector.h:1140:7: note: candidate: ‘std::vector<_Tp,
_Alloc>::reference std::vector<_Tp, _Alloc>::back() [with _Tp = double; _Alloc = std::allocator<double>; std::vector<_Tp, _Alloc>::reference = double&]’  1140 |       back()
_GLIBCXX_NOEXCEPT
      |       ^~~~ /usr/include/c++/9/bits/stl_vector.h:1140:7: note:   candidate expects 0 arguments, 1 provided /usr/include/c++/9/bits/stl_vector.h:1151:7: note: candidate: ‘std::vector<_Tp,
_Alloc>::const_reference std::vector<_Tp, _Alloc>::back() const [with _Tp = double; _Alloc = std::allocator<double>; std::vector<_Tp,
_Alloc>::const_reference = const double&]’  1151 |       back() const
_GLIBCXX_NOEXCEPT
      |       ^~~~ /usr/include/c++/9/bits/stl_vector.h:1151:7: note:   candidate expects 0 arguments, 1 provided

Here is my code for the node

//
// Created by lutinplunder on 6/28/22.
//


#include <ros/ros.h>
#include <std_msgs/Float64.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/JointState.h>

class Abdomen
{
public:
    Abdomen()
    {
        //Topic you want to publish
        desired_joint_state_publisher_ = n_.advertise<sensor_msgs::JointState>("desired_joint_states", 1);

        //Topic you want to subscribe
        pose_subscriber_ = n_.subscribe("shc/pose", 1, &Abdomen::callback, this);
    }

    void callback(const geometry_msgs::Twist& msg)
    {
//       ROS_INFO_STREAM("Msg: " << msg.angular.y);
        sensor_msgs::JointState output;
        double ab = 0.0;
        //.... do something with the input and generate the output...
        ab = msg.angular.y * -1;
        desired_joint_state_publisher_.publish(output.position.back(ab));
    }

private:
    ros::NodeHandle n_;
    ros::Publisher desired_joint_state_publisher_;
    ros::Subscriber pose_subscriber_;

};//End of class Abdomen

int main(int argc, char **argv)
{
    //Initiate ROS
    ros::init(argc, argv, "abdomen");

    //Create an object of class Abdomen that will take care of everything
    Abdomen ABObject;

    ros::spin();
//while(true) { ros::Rate(YOUR_DESIRED_RATE).sleep(); ros::spinOnce(); }
    return 0;
}
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2022-07-17 09:29:07 -0600

Mike Scheutzow gravatar image

I see several errors in your callback() code:

  1. The method std::vector<double>::back() does not take an argument.

  2. the publish() method needs to be passed a JointState message, not a double.

  3. you have not populated all the fields of local variable output.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-07-04 19:04:13 -0600

Seen: 94 times

Last updated: Jul 17 '22