constraint_app
/home/jbrooksh/drc/software/perception/constraint_app/src/constraint_app/constraint_app.cpp
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <inttypes.h>
00003 #include <lcm/lcm.h>
00004 #include <iostream>
00005 
00006 #include <lcmtypes/visualization.h>
00007 
00008 #include <path_util/path_util.h>
00009 
00010 #include "constraint_app.hpp"
00011 #include <boost/shared_ptr.hpp>
00012 
00013 constraint_app::constraint_app(lcm_t* publish_lcm) :
00014   publish_lcm_(publish_lcm) 
00015 {
00016   // LCM:
00017   lcm_t* subscribe_lcm_ = publish_lcm_;
00018 
00019   drc_affordance_collection_t_subscribe(subscribe_lcm_, "AFFORDANCE_COLLECTION",
00020                                         affordance_collection_handler_aux, this);
00021 
00022   drc_affordance_track_collection_t_subscribe(subscribe_lcm_, "AFFORDANCE_TRACK_COLLECTION",
00023                                               affordance_track_collection_handler_aux, this);
00024 }
00025 
00026 void constraint_app::affordance_collection_handler(const drc_affordance_collection_t *msg)
00027 {
00028   std::cout << "got a new affordance collection" << std::endl;
00029 
00030   for (size_t i=0; i< (size_t)msg->naffs; i++) {
00031     const drc_affordance_t aff(msg->affs[i]);
00032     const std::string filename(aff.otdf_type);
00033 
00034     // load the OTDF file
00035     std::string xml_string;
00036     if ( !otdf::get_xml_string_from_file(filename, xml_string) ) {
00037       std::cerr << "unable to get_xml_string_from_file " << filename << std::endl;
00038       continue; // file extraction failed
00039     }
00040 
00041     //convert OTDF to URDF
00042     boost::shared_ptr<otdf::ModelInterface> otdf_instance(otdf::parseOTDF(xml_string));
00043     std::string urdf_xml_string(otdf::convertObjectInstanceToCompliantURDFstring(otdf_instance));
00044 
00045     // Parse KDL tree
00046     KDL::Tree tree;
00047     if ( !kdl_parser::treeFromString(urdf_xml_string,tree) ) {
00048       std::cerr << "ERROR: Failed to extract kdl tree from "  << otdf_instance->name_ 
00049                 << " otdf object instance "<< std::endl; 
00050     }
00051 
00052     std::cout << "created KDL object with " << tree.getNrOfJoints() << " joints and " 
00053               << tree.getNrOfSegments() << " segments" << std::endl;
00054     print_kdl_tree(tree, tree.getRootSegment()->second, 0);
00055   }
00056 
00057 }
00058 
00059 void constraint_app::print_kdl_tree(const KDL::Tree& tree, 
00060                                     const KDL::TreeElement& segment,
00061                                     unsigned int depth) 
00062 {
00063   for ( unsigned int i = 0; i < depth; i++ ) {
00064     std::cout << " ";
00065   }
00066   std::cout << segment.segment.getName() 
00067             << ", joint " << segment.segment.getJoint().getName() 
00068             << " of type " << segment.segment.getJoint().getTypeName()
00069             << std::endl;
00070   for ( unsigned int i = 0; i < segment.children.size(); i++ ) {
00071     print_kdl_tree(tree, segment.children[i]->second, depth+1);
00072   }
00073   
00074 }
00075 
00076 void constraint_app::affordance_track_collection_handler(const drc_affordance_track_collection_t *msg)
00077 {
00078   std::cout << "got a new track collection" << std::endl;
00079 
00080   std::cout << "sent a new (empty) estimate of joint angles" << std::endl;
00081   drc_affordance_joint_angles_t aja;
00082   aja.utime = msg->utime;
00083   aja.uid = msg->uid;
00084   drc_affordance_joint_angles_t_publish(publish_lcm_, "AFFORDANCE_JOINT_ANGLES", &aja);
00085 }
00086 
00087 int main(int argc, char ** argv)
00088 {
00089   lcm_t * lcm;
00090   lcm = lcm_create(NULL);
00091   constraint_app app(lcm);
00092 
00093   while(1)
00094     lcm_handle(lcm);
00095 
00096   lcm_destroy(lcm);
00097   return 0;
00098 }
00099 
 All Classes Files Functions Variables Typedefs