how to add a subscriber in keyboard teleop ?
Hi, I have an incomplete C++ code which intends to add a subscriber to get state from robot model. Due to my limited knowledge, I can not proceed on the below code. What I want from this code is to get robot states ("base_pose_ground_truth":position and velocity) and put a simple proportional trajectory following controller for a desired trajectory (double desired_pos = 15 * sin(ros::Time::now().toSec());).
During compiling it, I have the error messages:
.../src/keyboard.cpp:113:17: error: cannot convert ‘ros::Subscriber’ to ‘double’ in assignment
.../src/keyboard.cpp:117:45: error: ‘max_force’ cannot be used as a function
.../src/keyboard.cpp:118:45: error: ‘max_force’ cannot be used as a function
----The below is the incomplete C++ code -------------------
#include <termios.h>
#include <signal.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/poll.h>
#include <boost/thread/thread.hpp>
#include <ros/ros.h>
#include <geometry_msgs/Wrench.h>
#include <nav_msgs/Odometry.h>
class ErraticKeyboardTeleopNode
{
private:
double thrust_;
geometry_msgs::Wrench box_force_;
nav_msgs::Odometry states_;
ros::NodeHandle n_;
ros::Publisher pub_;
ros::Subscriber sub_;
public:
ErraticKeyboardTeleopNode()
{
pub_ = n_.advertise<geometry_msgs::Wrench>("box_force", 1);
ros::NodeHandle n_private("~");
n_private.param("thrust", thrust_, 30.0);
}
~ErraticKeyboardTeleopNode() { }
void keyboardLoop();
void stopRobot()
{
box_force_.force.x = 0.0;
box_force_.force.y = 0.0;
box_force_.force.z = 0.0;
pub_.publish(box_force_);
}
};
ErraticKeyboardTeleopNode* tbk;
int kfd = 0;
struct termios cooked, raw;
bool done;
int main(int argc, char** argv)
{
ros::init(argc,argv,"tbk", ros::init_options::AnonymousName | ros::init_options::NoSigintHandler);
ErraticKeyboardTeleopNode tbk;
boost::thread t = boost::thread(boost::bind(&ErraticKeyboardTeleopNode::keyboardLoop, &tbk));
ros::spin();
t.interrupt();
t.join();
tbk.stopRobot();
tcsetattr(kfd, TCSANOW, &cooked);
return(0);
}
void ErraticKeyboardTeleopNode::keyboardLoop()
{
double max_force = thrust_;
double current_pos;
for(;;)
{
boost::this_thread::interruption_point();
ros::Subscriber base_pose_sub_ = n_.subscribe<nav_msgs::Odometry> ("base_pose_ground_truth", 15, &ErraticKeyboardTeleopNode::keyboardLoop, this);
double desired_pos = 15 * sin(ros::Time::now().toSec());
current_pos = base_pose_sub_;
max_force = -10 * (current_pos - desired_pos);
box_force_.force.x = 1 * max_force(4);
box_force_.force.y = 1 * max_force(5);
box_force_.force.z = 0;
pub_.publish(box_force_);
}
}