Error: no matching function for call to ‘std::vector<double>::back(double&)
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;
}