test_encoder.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
3 
4 #include <boost/assign/list_of.hpp>
5 #include <float.h>
6 #define polling_timeout_ 20
7 using namespace std;
8 namespace
9 {
10  const uint8_t LEFT = 0, RIGHT = 1;
11 };
12 double speed_x;
13 double speed_z;
15 {
16 
17  std::ostringstream ostream;
19  ostream << " { " ;
20  ostream << std::setfill('0') << std::uppercase;
21  for (unsigned int i=0; i < data.length; i++)
22  ostream << std::hex << std::setw(2) << static_cast<unsigned int>(data.data[i]) << " " << std::dec;
23  ostream << "}";
24  std_msgs::StringPtr msg(new std_msgs::String);
25  msg->data = ostream.str();
26  ROS_INFO("reveive command:%s",msg->data.c_str());
27 }
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,ang_vel,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 
59 #if 1
63 
64  if (enc)
65  {
66  // for (int i = 0; i < 2; i++)//新本 双驱
67  // {
68  //ROS_INFO("encoder[%d].distance.x:%.2lf ",i,enc->getTravel(i % 2));
69  ROS_INFO("encoder[0].distance.x:%.2lf ,encoder[1].distance.x:%.2lf . ",enc->getTravel(LEFT),enc->getTravel(RIGHT));
70  // }
71  }
72  else
73  {
74  ROS_ERROR("Could not get encoder data to calibrate travel offset");
75  }
76 #endif
79  if(encoderraw){
80  ROS_INFO("encoder[0].clicks:%.2d ,encoder[1].clicks:%.2d . ",encoderraw->getTicks(LEFT),encoderraw->getTicks(RIGHT));
81  }else{
82  ROS_ERROR("Could not get encoder raw data to calibrate travel offset");
83  }
84 }
86 int main(int argc, char** argv){
87  ros::init(argc,argv,"test_encoder");
88  std::string port = "/dev/roch";
89  core::connect(port);
90 
91  ros::NodeHandle nh;
92  speedSubscriber_ = nh.subscribe("/twist_mux/keyboard_teleop/cmd_vel",100000,&speedCallBack);
93 
94  ROS_INFO("begin send requestData");
95 
96  ros::spin();
97  return 0;
98 }
msg
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
void controloverallSpeed(double lin_vel, double ang_vel, double accel_left, double accel_right)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
data
ROSCPP_DECL void spin(Spinner &spinner)
const char * message
Definition: Exception.h:49
ros::Subscriber speedSubscriber_
#define ROS_INFO(...)
void connect(std::string port)
int main(int argc, char **argv)
unsigned char data[MAX_MSG_LENGTH]
Definition: serial.h:62
void speedCallBack(const geometry_msgs::Twist::ConstPtr &speed)
double speed_z
#define ROS_ERROR_STREAM(args)
void publishRawData()
static Ptr requestData(double timeout)
Definition: core_wrapper.h:98
double speed_x
#define ROS_ERROR(...)
#define polling_timeout_
Definition: test_encoder.cpp:6


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