test_speed.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
3 #include <geometry_msgs/Twist.h>
4 #include <boost/assign/list_of.hpp>
5 #include <float.h>
6 
7 #define polling_timeout_ 20
8 using namespace std;
9 double speed_x=0;
10 double speed_z=0;
11 namespace
12 {
13  const uint8_t LEFT = 0, RIGHT = 1;
14 };
16 {
17 
18  std::ostringstream ostream;
20  ostream << " { " ;
21  ostream << std::setfill('0') << std::uppercase;
22  for (unsigned int i=0; i < data.length; i++)
23  ostream << std::hex << std::setw(2) << static_cast<unsigned int>(data.data[i]) << " " << std::dec;
24  ostream << "}";
25  std_msgs::StringPtr msg(new std_msgs::String);
26  msg->data = ostream.str();
27  ROS_INFO("reveive command:%s",msg->data.c_str());
28 }
29 void controloverallSpeed(double lin_vel, double ang_vel, double accel_left, double accel_right)
30  {
31  bool success = false;
32 
33  double acc = (accel_left + accel_right)*0.5;
34 
35  while (!success)
36  {
37  try
38  {
39  sawyer::SetVelocity(lin_vel,speed_z,acc).send();
40  success = true;
41  }
42  catch (sawyer::Exception *ex)
43  {
44  ROS_ERROR_STREAM("Error sending velocity setpt command: " << ex->message);
45 
46  }
47  }
48  }
49 void speedCallBack(const geometry_msgs::Twist::ConstPtr& speed){
50 
51  cout<<"setspeed "<<speed_x<<" "<<speed_z<<endl;
52  speed_x = speed->linear.x;
53  speed_z = speed->angular.z;
54 
55 
57 
62  if (overallspeed)
63  {
64  ROS_DEBUG_STREAM("Received speed information (speed:" << overallspeed->getTranslational() << " Rotational:" << overallspeed->getRotational()<<" Acceleration:"<<overallspeed->getTransAccel() << ")");
65 
66  ROS_INFO("Received speed information, speed:%.2lf, Rotational:%.2lf, Acceleration:%.2lf",overallspeed->getTranslational(),overallspeed->getRotational(),overallspeed->getTransAccel());
67 
68  }
69 
70 }
72 int main(int argc, char** argv){
73 
74  ros::init(argc, argv, "test_speed");
75  ros::NodeHandle nh;
76  speedSubscriber_ = nh.subscribe("/roch_velocity_controller/cmd_vel",100000,&speedCallBack);
77  std::string port = "/dev/ttyUSB0";
78  core::connect(port);
79 
80  //while(ros::ok()){
81 
82  ROS_INFO("begin send requestData");
83 
84  //}
85  ros::spin();
86  return 0;
87 }
msg
double speed_z
Definition: test_speed.cpp:10
void controloverallSpeed(double lin_vel, double ang_vel, double accel_left, double accel_right)
Definition: test_speed.cpp:29
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
roch_driver::RawData getdata()
Definition: Transport.h:103
static Transport & instance()
Definition: Transport.cpp:129
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
data
#define polling_timeout_
Definition: test_speed.cpp:7
ROSCPP_DECL void spin(Spinner &spinner)
const char * message
Definition: Exception.h:49
#define ROS_INFO(...)
void connect(std::string port)
#define ROS_DEBUG_STREAM(args)
ros::Subscriber speedSubscriber_
Definition: test_speed.cpp:71
void speedCallBack(const geometry_msgs::Twist::ConstPtr &speed)
Definition: test_speed.cpp:49
int main(int argc, char **argv)
Definition: test_speed.cpp:72
unsigned char data[MAX_MSG_LENGTH]
Definition: serial.h:62
void publishRawData()
Definition: test_speed.cpp:15
#define ROS_ERROR_STREAM(args)
static Ptr requestData(double timeout)
Definition: core_wrapper.h:98
double speed_x
Definition: test_speed.cpp:9


roch_base
Author(s): Mike Purvis , Paul Bovbel , Chen
autogenerated on Mon Jun 10 2019 14:41:14