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
00035
00036
00040 #include <plugins/interactive/InteractiveObject.h>
00041
00042
00043 namespace beliefstate {
00044 InteractiveObject::InteractiveObject(std::string strName) {
00045 m_imsServer = NULL;
00046
00047 m_imMarker.header.frame_id = "/map";
00048 m_imMarker.scale = 1;
00049 m_imMarker.name = strName;
00050
00051 m_mkrMarker.type = visualization_msgs::Marker::CUBE;
00052 m_mkrMarker.scale.x = m_imMarker.scale * 0.45;
00053 m_mkrMarker.scale.y = m_imMarker.scale * 0.45;
00054 m_mkrMarker.scale.z = m_imMarker.scale * 0.45;
00055 m_mkrMarker.color.r = 0.5;
00056 m_mkrMarker.color.g = 0.5;
00057 m_mkrMarker.color.b = 0.5;
00058 m_mkrMarker.color.a = 1.0;
00059 }
00060
00061 InteractiveObject::~InteractiveObject() {
00062 }
00063
00064 void InteractiveObject::setSize(float fWidth, float fDepth, float fHeight) {
00065 m_mkrMarker.scale.x = m_imMarker.scale * fWidth;
00066 m_mkrMarker.scale.y = m_imMarker.scale * fDepth;
00067 m_mkrMarker.scale.z = m_imMarker.scale * fHeight;
00068
00069 this->insertIntoServer(m_imsServer);
00070 }
00071
00072 void InteractiveObject::setPose(std::string strFixedFrame, geometry_msgs::Pose posPose) {
00073 m_imMarker.header.frame_id = strFixedFrame;
00074 m_imMarker.pose = posPose;
00075
00076 this->insertIntoServer(m_imsServer);
00077 }
00078
00079 void InteractiveObject::setPose(geometry_msgs::Pose posPose) {
00080 this->setPose(m_imMarker.header.frame_id, posPose);
00081 }
00082
00083 void InteractiveObject::setMarker(visualization_msgs::Marker mkrMarker) {
00084 m_mkrMarker = mkrMarker;
00085
00086 this->insertIntoServer(m_imsServer);
00087 }
00088
00089 void InteractiveObject::clickCallback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback) {
00090 interactive_markers::MenuHandler::EntryHandle entHandle = feedback->menu_entry_id;
00091
00092 bool bFound = false;
00093 InteractiveMenuEntry imeEntry;
00094
00095 for(InteractiveMenuEntry imeEntry : m_lstMenuEntries) {
00096 if(imeEntry.unMenuEntryID == entHandle) {
00097 imeEntry = imeEntry;
00098 bFound = true;
00099
00100 break;
00101 }
00102 }
00103
00104 if(bFound) {
00105
00106 InteractiveObjectCallbackResult iocrResult;
00107 iocrResult.strObject = feedback->marker_name;
00108 iocrResult.strCommand = imeEntry.strIdentifier;
00109 iocrResult.strParameter = imeEntry.strParameter;
00110
00111 m_mtxCallbackResults.lock();
00112 m_lstCallbackResults.push_back(iocrResult);
00113 m_mtxCallbackResults.unlock();
00114 }
00115 }
00116
00117 bool InteractiveObject::insertIntoServer(interactive_markers::InteractiveMarkerServer* imsServer) {
00118 if(ros::ok()) {
00119 if(imsServer) {
00120 m_imcControl.interaction_mode = visualization_msgs::InteractiveMarkerControl::BUTTON;
00121 m_imcControl.always_visible = true;
00122
00123 m_imcControl.markers.clear();
00124 m_imcControl.markers.push_back(m_mkrMarker);
00125
00126 m_imMarker.controls.clear();
00127 m_imMarker.controls.push_back(m_imcControl);
00128
00129 imsServer->insert(m_imMarker);
00130 m_mhMenu.apply(*imsServer, m_imMarker.name);
00131 imsServer->applyChanges();
00132
00133 m_imsServer = imsServer;
00134
00135 return true;
00136 }
00137 }
00138
00139 return false;
00140 }
00141
00142 bool InteractiveObject::removeFromServer() {
00143 if(ros::ok()) {
00144 if(m_imsServer) {
00145 m_imsServer->erase(m_imMarker.name);
00146 m_imsServer->applyChanges();
00147
00148 return true;
00149 }
00150 }
00151
00152 return false;
00153 }
00154
00155 std::string InteractiveObject::name() {
00156 return m_imMarker.name;
00157 }
00158
00159 void InteractiveObject::addMenuEntry(std::string strLabel, std::string strIdentifier, std::string strParameter) {
00160 InteractiveMenuEntry imeEntry;
00161 imeEntry.strLabel = strLabel;
00162 imeEntry.strIdentifier = strIdentifier;
00163 imeEntry.strParameter = strParameter;
00164
00165 interactive_markers::MenuHandler::EntryHandle entEntry = m_mhMenu.insert(strLabel, boost::bind(&InteractiveObject::clickCallback, this, _1));
00166 m_mhMenu.setCheckState(entEntry, interactive_markers::MenuHandler::NO_CHECKBOX);
00167
00168 imeEntry.unMenuEntryID = entEntry;
00169
00170 m_lstMenuEntries.push_back(imeEntry);
00171
00172 if(m_imsServer) {
00173 this->insertIntoServer(m_imsServer);
00174 }
00175 }
00176
00177 void InteractiveObject::clearMenuEntries() {
00178 interactive_markers::MenuHandler mhMenu;
00179
00180 m_lstMenuEntries.clear();
00181 m_mhMenu = mhMenu;
00182
00183 if(m_imsServer) {
00184 this->insertIntoServer(m_imsServer);
00185 }
00186 }
00187
00188 void InteractiveObject::removeMenuEntry(std::string strIdentifier, std::string strParameter) {
00189 interactive_markers::MenuHandler mhMenu;
00190
00191 for(std::list<InteractiveMenuEntry>::iterator itIME = m_lstMenuEntries.begin();
00192 itIME != m_lstMenuEntries.end();
00193 itIME++) {
00194 if((*itIME).strIdentifier == strIdentifier && (*itIME).strParameter == strParameter) {
00195 m_lstMenuEntries.erase(itIME);
00196
00197 break;
00198 }
00199 }
00200
00201 for(InteractiveMenuEntry imeEntry : m_lstMenuEntries) {
00202 interactive_markers::MenuHandler::EntryHandle entEntry = m_mhMenu.insert(imeEntry.strLabel, boost::bind(&InteractiveObject::clickCallback, this, _1));
00203 m_mhMenu.setCheckState(entEntry, interactive_markers::MenuHandler::NO_CHECKBOX);
00204 }
00205
00206 m_mhMenu = mhMenu;
00207
00208 if(m_imsServer) {
00209 this->insertIntoServer(m_imsServer);
00210 }
00211 }
00212
00213 std::list<InteractiveObjectCallbackResult> InteractiveObject::callbackResults() {
00214 std::list<InteractiveObjectCallbackResult> lstResults;
00215
00216 m_mtxCallbackResults.lock();
00217 lstResults = m_lstCallbackResults;
00218 m_lstCallbackResults.clear();
00219 m_mtxCallbackResults.unlock();
00220
00221 return lstResults;
00222 }
00223 }