25 #include <alerror/alerror.h> 26 #include <alcommon/albroker.h> 27 #include <sensor_msgs/JointState.h> 30 #include <controller_manager_msgs/ControllerState.h> 33 :
AL::ALModule(broker,name),is_connected_(false)
35 setModuleDescription(
"Romeo Robot Module");
37 functionName(
"brokerDisconnected",
getName(),
"Callback when broker disconnects!");
51 const char* joint[] = {
88 joints_names_.push_back(
"Device/SubDeviceList/"+(*it)+
"/Position/Sensor/Value");
103 AL::ALValue commandAlias;
104 commandAlias.arraySetSize(2);
105 commandAlias[0] = string(
"Joints");
109 commandAlias[1][i] = string(
"Device/SubDeviceList/"+
joint_names_[i]+
"/Position/Actuator/Value");
113 dcm_proxy_->callVoid(
"createAlias",commandAlias);
116 commandAlias[0] = string(
"JointsHardness");
117 commandAlias[1].arraySetSize(number_of_joints_);
120 commandAlias[1][i] = string(
"Device/SubDeviceList/"+
joint_names_[i]+
"/Hardness/Actuator/Value");
122 dcm_proxy_->callVoid(
"createAlias",commandAlias);
125 catch(
const AL::ALError& e)
127 ROS_ERROR(
"Could not initialize dcm aliases!\n\tTrace: %s",e.what());
135 std::stringstream ss;
138 ROS_INFO(
"Romeo joints found: %s",ss.str().c_str());
147 ROS_ERROR(
"Initialization method failed!");
175 ROS_ERROR(
"Could not initialize hardware interfaces!\n\tTrace: %s",e.what());
178 ROS_INFO(
"Romeo Module initialized!");
197 catch (
const AL::ALError& e)
199 ROS_ERROR(
"Could not subscribe to brokerDisconnected!\n\tTrace: %s",e.what());
208 catch (
const AL::ALError& e)
210 ROS_ERROR(
"Failed to connect to DCM Proxy!\n\tTrace: %s",e.what());
219 catch (
const AL::ALError& e)
221 ROS_ERROR(
"Failed to connect to Memory Proxy!\n\tTrace: %s",e.what());
228 catch (
const AL::ALError& e)
230 ROS_ERROR(
"Could not create ALMotionProxy.");
243 ROS_ERROR(
"Could not load controllers!");
246 ROS_INFO(
"Controllers successfully loaded!");
258 catch (
const AL::ALError& e)
260 ROS_ERROR(
"Failed to unsubscribe from subscribed events!\n\tTrace: %s",e.what());
301 if(broker_name ==
"Romeo Driver Broker")
311 command.arraySetSize(3);
314 command[2].arraySetSize(1);
315 command[2][0].arraySetSize(2);
316 command[2][0][0] = value;
317 command[2][0][1] =
dcm_proxy_->call<
int>(
"getTime",timeOffset);
322 catch(
const AL::ALError& e)
324 ROS_ERROR(
"Could not execute DCM timed-command!\n\t%s\n\n\tTrace: %s", key.c_str(), e.what());
329 const string &type,
const string &type2)
335 command.arraySetSize(4);
339 command[3].arraySetSize(values.size());
341 for(
int i=0;i<values.size();i++)
343 command[3][i].arraySetSize(1);
344 command[3][i][0].arraySetSize(2);
345 command[3][i][0][0] = values[i];
346 command[3][i][0][1] = T+timeOffsets[i];
352 catch(
const AL::ALError& e)
354 ROS_ERROR(
"Could not execute DCM timed-command!\n\t%s\n\n\tTrace: %s", alias.c_str(), e.what());
372 memory_proxy_.subscribeToEvent(name,callback_module,
"",callback_method);
374 catch(
const AL::ALError& e)
376 ROS_ERROR(
"Could not subscribe to event '%s'.\n\tTrace: %s",name.c_str(),e.what());
381 const string &callback_method,
const string &callback_message)
385 memory_proxy_.subscribeToMicroEvent(name,callback_module,callback_message,callback_method);
387 catch(
const AL::ALError& e)
389 ROS_ERROR(
"Could not subscribe to micro-event '%s'.\n\tTrace: %s",name.c_str(),e.what());
399 catch(
const AL::ALError& e)
401 ROS_ERROR(
"Could not unsubscribe from event '%s'.\n\tTrace: %s",name.c_str(),e.what());
411 catch(
const AL::ALError& e)
413 ROS_ERROR(
"Could not unsubscribe from micro-event '%s'.\n\tTrace: %s",name.c_str(),e.what());
423 catch(
const AL::ALError& e)
425 ROS_ERROR(
"Could not raise event '%s'.\n\tTrace: %s",name.c_str(),e.what());
435 catch(
const AL::ALError& e)
437 ROS_ERROR(
"Could not raise micro-event '%s'.\n\tTrace: %s",name.c_str(),e.what());
447 catch(AL::ALError& e)
449 ROS_ERROR(
"Could not declare event '%s'.\n\tTrace: %s",name.c_str(),e.what());
503 catch(
const AL::ALError& e)
505 ROS_ERROR(
"Could not ping DCM proxy.\n\tTrace: %s",e.what());
530 catch(
const AL::ALError& e)
532 ROS_ERROR(
"Could not ping DCM proxy.\n\tTrace: %s",e.what());
557 ROS_WARN(
"This function does nothing at the moment..");
562 vector<float> jointData;
567 catch(
const AL::ALError& e)
569 ROS_ERROR(
"Could not get joint data from Romeo.\n\tTrace: %s",e.what());
573 for(
short i = 0; i<jointData.size(); i++)
584 std::vector<float> positionData;
589 for(
unsigned i = 0; i<positionData.size(); ++i)
600 bool changed =
false;
627 catch(
const AL::ALError& e)
629 ROS_ERROR(
"Could not send joint commands to Romeo.\n\tTrace: %s",e.what());
void registerInterface(T *iface)
vector< string > joint_names_
hardware_interface::JointStateInterface jnt_state_interface_
controller_manager::ControllerManager * manager_
void publishJointStateFromAlMotion()
boost::shared_ptr< AL::ALProxy > dcm_proxy_
ros::Publisher stiffness_pub_
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::string getName(void *handle)
void insertDataToMemory(const string &key, const AL::ALValue &value)
void subscribeToMicroEvent(const std::string &name, const std::string &callback_module, const std::string &callback_method, const string &callback_message="")
vector< double > joint_efforts_
void subscribeToEvent(const std::string &name, const std::string &callback_module, const std::string &callback_method)
hardware_interface::PositionJointInterface jnt_pos_interface_
void unsubscribeFromMicroEvent(const string &name, const string &callback_module)
sensor_msgs::JointState m_jointState
bool switchStiffnesses(romeo_dcm_msgs::BoolService::Request &req, romeo_dcm_msgs::BoolService::Response &res)
AL::ALMemoryProxy memory_proxy_
ROSLIB_DECL std::string command(const std::string &cmd)
void lowCommunicationLoop()
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void unsubscribeFromEvent(const string &name, const string &callback_module)
vector< double > joint_commands_
void declareEvent(const string &name)
void raiseMicroEvent(const string &name, const AL::ALValue &value)
boost::shared_ptr< AL::ALMotionProxy > m_motionProxy
std_msgs::Float32 stiffness_
void highCommunicationLoop()
vector< double > joint_angles_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Subscriber cmd_vel_sub_
void registerHandle(const JointStateHandle &handle)
void raiseEvent(const string &name, const AL::ALValue &value)
vector< double > joint_velocities_
AL::ALValue getDataFromMemory(const string &key)
JointStateHandle getHandle(const std::string &name)
bool initializeControllers(controller_manager::ControllerManager &cm)
Romeo(boost::shared_ptr< AL::ALBroker > broker, const std::string &name)
void DCMAliasTimedCommand(const string &alias, const vector< float > &values, const vector< int > &timeOffsets, const string &type="Merge", const string &type2="time-mixed")
void brokerDisconnected(const string &event_name, const string &broker_name, const string &subscriber_identifier)
bool stiffnesses_enabled_
ros::Publisher m_jointStatePub
void update(const ros::Time &time, const ros::Duration &period, bool reset_controllers=false)
bool connect(const ros::NodeHandle nh)
ros::NodeHandle node_handle_
void commandVelocity(const geometry_msgs::TwistConstPtr &msg)
void DCMTimedCommand(const string &key, const AL::ALValue &value, const int &timeOffset, const string &type="Merge")
vector< string > joints_names_