romeo_driver.cpp
Go to the documentation of this file.
1 
23 #include <iostream>
24 #include "romeo_dcm_driver/romeo.h"
25 #include <alcommon/albroker.h>
26 #include <alcommon/albrokermanager.h>
27 #include <alproxies/almotionproxy.h>
28 
29 using std::string;
30 using std::cerr;
31 using std::endl;
32 
33 int main( int argc, char** argv )
34 {
35  int pport = 9559;
36  string pip = "127.0.0.1";
37  ros::init(argc, argv, "romeo_dcm_driver");
39  ros::NodeHandle n_p("~");
40  if(!ros::master::check())
41  {
42  cerr<<"Could not contact master!\nQuitting... "<<endl;
43  return -1;
44  }
45  // A broker needs a name, an IP and a port:
46  string broker_name = "Romeo Driver Broker";
47  // FIXME: would be a good idea to look for a free port first
48  int broker_port = 54000;
49  // listen port of the broker (here an anything)
50  string broker_ip = "0.0.0.0";
51 
52  // Load Params from Parameter Server
53  n_p.param("RobotIP", pip, string("127.0.0.1"));
54  n_p.param("RobotPort", pport,9559);
55  n_p.param("DriverBrokerPort", broker_port, 54000);
56  n_p.param("DriverBrokerIP", broker_ip, string("0.0.0.0"));
57 
58  // Create your own broker
60 
61  try
62  {
63  broker = AL::ALBroker::createBroker(broker_name,broker_ip,broker_port,pip,pport,0);
64 
65  // Workaround because stiffness does not work well via DCM
67  try
68  {
69  m_motionProxy = boost::shared_ptr<AL::ALMotionProxy>(new AL::ALMotionProxy(broker));
70  }
71  catch (const AL::ALError& e)
72  {
73  ROS_ERROR("Could not create ALMotionProxy.");
74  return -1;
75  }
76  m_motionProxy->stiffnessInterpolation("LArm", 1.0f, 2.0f);
77  m_motionProxy->stiffnessInterpolation("RArm", 1.0f, 2.0f);
78 
79  //m_motionProxy->stiffnessInterpolation("Head", 1.0f, 2.0f);
80  //m_motionProxy->stiffnessInterpolation("Trunk", 1.0f, 2.0f);
81 
82  }
83 
84  catch(...)
85  {
86  ROS_ERROR("Failed to connect to Broker at %s:%d!",pip.c_str(),pport);
87  return -1;
88  }
89 
90  // Deal with ALBrokerManager singleton (add your broker into NAOqi)
91  AL::ALBrokerManager::setInstance(broker->fBrokerManager.lock());
92  AL::ALBrokerManager::getInstance()->addBroker(broker);
93 
94  // Now it's time to load your module
95  boost::shared_ptr<Romeo> romeo = AL::ALModule::createModule<Romeo>(broker, "Romeo");
96  romeo->connect(n);
97  if(!romeo->connected())
98  {
99  ROS_ERROR("Could not connect to Romeo robot!");
100  AL::ALBrokerManager::getInstance()->killAllBroker();
101  AL::ALBrokerManager::kill();
102  return -1;
103  }
104 
105  // Run the spinner in a separate thread to prevent lockups
106 
108  spinner.start();
109  if(broker->isModulePresent("Romeo"))
110  ROS_INFO("Romeo Module loaded succesfully!");
111  else
112  {
113  ROS_ERROR("Romeo Module is not loaded!");
114  return -1;
115  }
116 
117  // Run Romeo Driver Loop
118  romeo->run();
119 
120  AL::ALBrokerManager::getInstance()->killAllBroker();
121  AL::ALBrokerManager::kill();
122  spinner.stop();
123 
124  // Workaround because stiffness does not work well via DCM
125 
126  sleep(1);
127  ROS_INFO( "finished sleeping... " );
128  AL::ALProxy tempMotion("ALMotion", pip, pport);
129  tempMotion.callVoid("setStiffnesses","LArm",0.0f);
130  tempMotion.callVoid("setStiffnesses","RArm",0.0f);
131  //tempMotion.callVoid("setStiffnesses","Head",0.0f);
132  //tempMotion.callVoid("setStiffnesses","Trunk",0.0f);
133 
134 
135  ROS_INFO( "Quitting... " );
136  return 0;
137 }
int main(int argc, char **argv)
ROSCPP_DECL bool check()
f
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void spinner()
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
#define ROS_ERROR(...)


romeo_dcm_driver
Author(s): Konstantinos Chatzilygeroudis , Ha Dang
autogenerated on Sun Jul 3 2016 04:02:28