Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <labust/blueview/BVSonarRos.hpp>
00035 #include <aidnav_msgs/MBSonar.h>
00036 #include <sensor_msgs/image_encodings.h>
00037 #include <pluginlib/class_list_macros.h>
00038
00039 using namespace labust::blueview;
00040
00041 PLUGINLIB_DECLARE_CLASS(bvt_sdk,BVSonarRos,labust::blueview::BVSonarRos, nodelet::Nodelet)
00042
00043 BVSonarRos::BVSonarRos():
00044 sonar(BVFactory::makeBVSonar()),
00045 pingRate(100)
00046 {}
00047
00048 BVSonarRos::~BVSonarRos()
00049 {
00050 worker.join();
00051 };
00052
00053 void BVSonarRos::onInit()
00054 {
00055 phandle = this->getPrivateNodeHandle();
00056 nhandle = this->getNodeHandle();
00057
00058 std::string sonarType("FILE");
00059 std::string sonarAddress("swimmer.son");
00060 std::string magtopicName("bvsonar_img");
00061 std::string colortopicName("bvsonar_cimg");
00062 std::string colormap("jet");
00063 std::string colormapDir(".");
00064 int headNumber(0), soundSpeed(1475);
00065
00066 phandle.param("Type",sonarType,sonarType);
00067 phandle.param("Address",sonarAddress,sonarAddress);
00068 phandle.param("HeadNumber",headNumber,headNumber);
00069 phandle.param("MagnitudeTopicName",magtopicName,magtopicName);
00070 phandle.param("ColorTopicName",colortopicName,colortopicName);
00071 phandle.param("Colormap",colormap,colormap);
00072 phandle.param("ColormapDir",colormapDir,colormapDir);
00073 phandle.param("PingRate",pingRate,pingRate);
00074 phandle.param("SoundSpeed", soundSpeed, soundSpeed);
00075
00076
00077 sonar = BVFactory::makeBVSonar();
00078 mapper = BVFactory::makeBVColorMapper(colormapDir + "/" + colormap + ".cmap");
00079
00080 if (int error = BVTSonar_Open(sonar.get(),sonarType.c_str(),sonarAddress.c_str()))
00081 {
00082 throw std::invalid_argument(BVTError_GetString(error));
00083 }
00084 if (int error = BVTSonar_GetHead(sonar.get(),headNumber,&head))
00085 {
00086 throw std::invalid_argument(BVTError_GetString(error));
00087 }
00088
00089 BVTHead_SetSoundSpeed(head,soundSpeed);
00090
00091
00092 imageTopic = nhandle.advertise<aidnav_msgs::MBSonar>(magtopicName,1);
00093 cImageTopic = nhandle.advertise<aidnav_msgs::MBSonar>(colortopicName,1);
00094
00095
00096 server.setCallback(boost::bind(&BVSonarRos::dynrec, this, _1, _2));
00097
00098 worker=boost::thread(boost::bind(&BVSonarRos::run,this));
00099 }
00100
00101 void BVSonarRos::dynrec(bvt_sdk::BVSonarConfig& config, uint32_t level)
00102 {
00103 this->config = config;
00104 }
00105
00106 void BVSonarRos::run()
00107 {
00108 this->runFileAcquisition();
00109 }
00110
00111 void BVSonarRos::runFileAcquisition()
00112 {
00113 size_t pingNum = BVTHead_GetPingCount(head);
00114 size_t counter = 0;
00115 ros::Rate loop_rate(pingRate);
00116 BVTHead_SetImageRes(head,BVTHEAD_RES_HIGH);
00117 BVTHead_SetImageType(head,BVTHEAD_IMAGE_RTHETA);
00118 this->config.double_param = BVTHead_GetMaximumRange(head);
00119 server.setConfigMax(config);
00120 this->config.double_param = BVTHead_GetStopRange(head);
00121 server.setConfigDefault(this->config);
00122 while (nhandle.ok())
00123 {
00124 BVTHead_SetRange(head,0,this->config.double_param);
00125 BVPingPtr ping(BVFactory::getBVPing(head,counter));
00126
00127 BVMagImagePtr image(BVFactory::getBVMagImage(ping));
00128 BVColorImagePtr cimage(BVFactory::getBVColorImage(image,mapper));
00129
00130
00131 aidnav_msgs::MBSonarPtr msg(new aidnav_msgs::MBSonar());
00132 msg->image.height = BVTMagImage_GetHeight(image.get());
00133 msg->image.width = BVTMagImage_GetWidth(image.get());
00134 msg->image.encoding = sensor_msgs::image_encodings::MONO16;
00135 msg->image.step = 2*msg->image.width;
00136 msg->image.is_bigendian = 0;
00137 msg->range_res = BVTMagImage_GetRangeResolution(image.get());
00138 msg->origin.z = 0;
00139 msg->origin.x = BVTMagImage_GetWidth(image.get())/2;
00140 msg->origin.y = BVTMagImage_GetOriginRow(image.get());
00141
00142 unsigned char* datap = reinterpret_cast<unsigned char*>(BVTMagImage_GetBits(image.get()));
00143 msg->image.data.assign(datap,datap + msg->image.step*msg->image.height);
00144 imageTopic.publish(msg);
00145
00146 msg.reset(new aidnav_msgs::MBSonar());
00147 msg->image.height = BVTColorImage_GetHeight(cimage.get());
00148 msg->image.width = BVTColorImage_GetWidth(cimage.get());
00149 msg->image.encoding = sensor_msgs::image_encodings::BGRA8;
00150 msg->image.step = 4*msg->image.width;
00151 datap = reinterpret_cast<unsigned char*>(BVTColorImage_GetBits(cimage.get()));
00152 msg->image.data.assign(datap,datap + msg->image.step*msg->image.height);
00153 cImageTopic.publish(msg);
00154
00155 ++counter;
00156 counter %= pingNum;
00157
00158 ros::spinOnce();
00159 loop_rate.sleep();
00160 }
00161 }
00162
00163
00164