Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include "roch_base/roch_hardware.h"
00003
00004 #include <boost/assign/list_of.hpp>
00005 #include <float.h>
00006 #define polling_timeout_ 20
00007 using namespace std;
00008 namespace
00009 {
00010 const uint8_t LEFT = 0, RIGHT = 1;
00011 };
00012 double speed_x;
00013 double speed_z;
00014 void publishRawData()
00015 {
00016
00017 std::ostringstream ostream;
00018 sawyer::base_data::RawData data =sawyer::Transport::instance().getdata();
00019 ostream << " { " ;
00020 ostream << std::setfill('0') << std::uppercase;
00021 for (unsigned int i=0; i < data.length; i++)
00022 ostream << std::hex << std::setw(2) << static_cast<unsigned int>(data.data[i]) << " " << std::dec;
00023 ostream << "}";
00024 std_msgs::StringPtr msg(new std_msgs::String);
00025 msg->data = ostream.str();
00026 ROS_INFO("reveive command:%s",msg->data.c_str());
00027 }
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,ang_vel,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 #if 1
00060 core::Channel<sawyer::DataEncoders>::Ptr enc = core::Channel<sawyer::DataEncoders>::requestData(
00061 polling_timeout_);
00062 publishRawData();
00063
00064 if (enc)
00065 {
00066
00067
00068
00069 ROS_INFO("encoder[0].distance.x:%.2lf ,encoder[1].distance.x:%.2lf . ",enc->getTravel(LEFT),enc->getTravel(RIGHT));
00070
00071 }
00072 else
00073 {
00074 ROS_ERROR("Could not get encoder data to calibrate travel offset");
00075 }
00076 #endif
00077 core::Channel<sawyer::DataEncodersRaw>::Ptr encoderraw = core::Channel<sawyer::DataEncodersRaw>::requestData(
00078 polling_timeout_);
00079 if(encoderraw){
00080 ROS_INFO("encoder[0].clicks:%.2d ,encoder[1].clicks:%.2d . ",encoderraw->getTicks(LEFT),encoderraw->getTicks(RIGHT));
00081 }else{
00082 ROS_ERROR("Could not get encoder raw data to calibrate travel offset");
00083 }
00084 }
00085 ros::Subscriber speedSubscriber_;
00086 int main(int argc, char** argv){
00087 ros::init(argc,argv,"test_encoder");
00088 std::string port = "/dev/roch";
00089 core::connect(port);
00090
00091 ros::NodeHandle nh;
00092 speedSubscriber_ = nh.subscribe("/twist_mux/keyboard_teleop/cmd_vel",100000,&speedCallBack);
00093
00094 ROS_INFO("begin send requestData");
00095
00096 ros::spin();
00097 return 0;
00098 }