Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include "roch_base/roch_hardware.h"
00003 #include <geometry_msgs/Twist.h>
00004 #include <boost/assign/list_of.hpp>
00005 #include <float.h>
00006
00007 #define polling_timeout_ 20
00008 using namespace std;
00009 double speed_x=0;
00010 double speed_z=0;
00011 namespace
00012 {
00013 const uint8_t LEFT = 0, RIGHT = 1;
00014 };
00015 void publishRawData()
00016 {
00017
00018 std::ostringstream ostream;
00019 sawyer::base_data::RawData data =sawyer::Transport::instance().getdata();
00020 ostream << " { " ;
00021 ostream << std::setfill('0') << std::uppercase;
00022 for (unsigned int i=0; i < data.length; i++)
00023 ostream << std::hex << std::setw(2) << static_cast<unsigned int>(data.data[i]) << " " << std::dec;
00024 ostream << "}";
00025 std_msgs::StringPtr msg(new std_msgs::String);
00026 msg->data = ostream.str();
00027 ROS_INFO("reveive command:%s",msg->data.c_str());
00028 }
00029 void controloverallSpeed(double lin_vel, double ang_vel, double accel_left, double accel_right)
00030 {
00031 bool success = false;
00032
00033 double acc = (accel_left + accel_right)*0.5;
00034
00035 while (!success)
00036 {
00037 try
00038 {
00039 sawyer::SetVelocity(lin_vel,speed_z,acc).send();
00040 success = true;
00041 }
00042 catch (sawyer::Exception *ex)
00043 {
00044 ROS_ERROR_STREAM("Error sending velocity setpt command: " << ex->message);
00045
00046 }
00047 }
00048 }
00049 void speedCallBack(const geometry_msgs::Twist::ConstPtr& speed){
00050
00051 cout<<"setspeed "<<speed_x<<" "<<speed_z<<endl;
00052 speed_x = speed->linear.x;
00053 speed_z = speed->angular.z;
00054
00055
00056 controloverallSpeed(speed_x, speed_z, 0, 0);
00057
00058 publishRawData();
00059 core::Channel<sawyer::DataVelocity>::Ptr overallspeed = core::Channel<sawyer::DataVelocity>::requestData(
00060 polling_timeout_);
00061 publishRawData();
00062 if (overallspeed)
00063 {
00064 ROS_DEBUG_STREAM("Received speed information (speed:" << overallspeed->getTranslational() << " Rotational:" << overallspeed->getRotational()<<" Acceleration:"<<overallspeed->getTransAccel() << ")");
00065
00066 ROS_INFO("Received speed information, speed:%.2lf, Rotational:%.2lf, Acceleration:%.2lf",overallspeed->getTranslational(),overallspeed->getRotational(),overallspeed->getTransAccel());
00067
00068 }
00069
00070 }
00071 ros::Subscriber speedSubscriber_;
00072 int main(int argc, char** argv){
00073
00074 ros::init(argc, argv, "test_speed");
00075 ros::NodeHandle nh;
00076 speedSubscriber_ = nh.subscribe("/roch_velocity_controller/cmd_vel",100000,&speedCallBack);
00077 std::string port = "/dev/ttyUSB0";
00078 core::connect(port);
00079
00080
00081
00082 ROS_INFO("begin send requestData");
00083
00084
00085 ros::spin();
00086 return 0;
00087 }