test_pid.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 
13 double speed_x;
14 double speed_z;
16 {
17 #if 0
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_STREAM("reveive command:"<<msg->data.c_str()<<" .");
28 #endif
29 }
30 
31 void controloverallSpeed(double lin_vel, double ang_vel, double accel_left, double accel_right)
32  {
33  bool success = false;
34 
35  double acc = (accel_left + accel_right)*0.5;
36 
37  while (!success)
38  {
39  try
40  {
41 // sawyer::SetVelocity(lin_vel,ang_vel,acc).send();
42 // sawyer::SetDifferentialControl(0.1,0.0005,0.08,0.1,0.0005,0.08).send();
43  ROS_INFO_STREAM("Now Left_PID: "<<lin_vel<<", Right_PID: "<<ang_vel<<" .");
44  sawyer::SetDifferentialControl(lin_vel,lin_vel,lin_vel,ang_vel,ang_vel,ang_vel).send();
45  success = true;
46  }
47  catch (sawyer::Exception *ex)
48  {
49  ROS_ERROR_STREAM("Error sending Diff Contrl contets command: " << ex->message);
50 
51  }
52  }
53  }
54 void speedCallBack(const geometry_msgs::Twist::ConstPtr& speed){
55 
56  //cout<<"setspeed "<<speed_x<<" "<<speed_z<<endl;
57  speed_x = speed->linear.x;
58  speed_z = speed->angular.z;
59 
60 
62 
67  if(pidData){
68  ROS_INFO_STREAM("Received PID data information, Left_P: "<<pidData->getLeftP()<<", Left_I: "<<pidData->getLeftI()<<", Left_D: "<<pidData->getLeftD()<<"||| Right_P: "<<pidData->getRightP()<<", Right_I: "<<pidData->getRightI()<<", Right_D: "<<pidData->getRightD()<<" .");
69 
70  }
71  else{
72  ROS_ERROR("Could not get PID Data form MCU.");
73  }
74 #if 0
78  if (overallspeed)
79  {
80  ROS_DEBUG_STREAM("Received speed information (speed:" << overallspeed->getTranslational() << " Rotational:" << overallspeed->getRotational()<<" Acceleration:"<<overallspeed->getTransAccel() << ")");
81 
82  ROS_INFO("Received speed information, speed:%.2lf, Rotational:%.2lf, Acceleration:%.2lf",overallspeed->getTranslational(),overallspeed->getRotational(),overallspeed->getTransAccel());
83 
84  }
85 #endif
86 }
88 int main(int argc, char** argv){
89 
90  ros::init(argc,argv,"test_imu");
91  std::string port = "/dev/roch";
92  core::connect(port);
93 
94  ros::NodeHandle nh;
95  speedSubscriber_ = nh.subscribe("/twist_mux/keyboard_teleop/cmd_vel",100000,&speedCallBack);
96 
97  ROS_INFO("begin send requestData");
98 
99  ros::spin();
100  return 0;
101 }
msg
int main(int argc, char **argv)
Definition: test_pid.cpp:88
void controloverallSpeed(double lin_vel, double ang_vel, double accel_left, double accel_right)
Definition: test_pid.cpp:31
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void speedCallBack(const geometry_msgs::Twist::ConstPtr &speed)
Definition: test_pid.cpp:54
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
ROSCPP_DECL void spin(Spinner &spinner)
double speed_z
Definition: test_pid.cpp:14
#define polling_timeout_
Definition: test_pid.cpp:6
const char * message
Definition: Exception.h:49
double speed_x
Definition: test_pid.cpp:11
#define ROS_INFO(...)
ros::Subscriber speedSubscriber_
Definition: test_pid.cpp:87
void connect(std::string port)
#define ROS_DEBUG_STREAM(args)
#define ROS_INFO_STREAM(args)
unsigned char data[MAX_MSG_LENGTH]
Definition: serial.h:62
void publishRawData()
Definition: test_pid.cpp:15
#define ROS_ERROR_STREAM(args)
static Ptr requestData(double timeout)
Definition: core_wrapper.h:98
#define ROS_ERROR(...)


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