Skip to content
Snippets Groups Projects
Commit 1ada8dde authored by Rohan Budhiraja's avatar Rohan Budhiraja
Browse files

[c++][python] Move RosRobotModel from c++ to python

parent cc6e0980
No related branches found
No related tags found
No related merge requests found
...@@ -132,7 +132,7 @@ compile_plugin(ros_joint_state) ...@@ -132,7 +132,7 @@ compile_plugin(ros_joint_state)
target_link_libraries(ros_joint_state "${DYNAMIC_GRAPH_PLUGINDIR}/dynamic.so") target_link_libraries(ros_joint_state "${DYNAMIC_GRAPH_PLUGINDIR}/dynamic.so")
compile_plugin(robot_model) #compile_plugin(robot_model)
# ros_interperter library. # ros_interperter library.
add_library(ros_interpreter src/ros_interpreter.cpp) add_library(ros_interpreter src/ros_interpreter.cpp)
......
from dynamic_graph.sot.dynamics import Dynamic
from ros_publish import RosPublish from ros_publish import RosPublish
from ros_subscribe import RosSubscribe from ros_subscribe import RosSubscribe
from ros_joint_state import RosJointState from ros_joint_state import RosJointState
from robot_model import RosRobotModel
from ros import Ros from ros import Ros
# aliases, for retro compatibility # aliases, for retro compatibility
ros_import = ros_publish
ros_export = ros_subscribe
from ros import RosPublish as RosImport from ros import RosPublish as RosImport
from ros import RosSubscribe as RosExport from ros import RosSubscribe as RosExport
import rospy
class RosRobotModel(Dynamic):
def __init__(self):
Dynamic.__init__(self)
self.namespace = "sot_controller"
self.jointsParameterName_ = "jrl_map"
def setJointsNamesParameter(self):
if self.model is not None:
parameter_name = self.namespace + "/" + jointsParameterName_
jointsName = []
for i in xrange(self.model.njoints):
jointsName.append(self.model.names[i])
rospy.set_param(parameter_name,jointsName)
return
def setNamespace(self, ns):
self.namespace = ns
return
def curConf(self):
return self.position.value
...@@ -58,13 +58,6 @@ RosRobotModel::~RosRobotModel() ...@@ -58,13 +58,6 @@ RosRobotModel::~RosRobotModel()
void RosRobotModel::loadUrdf (const std::string& filename) void RosRobotModel::loadUrdf (const std::string& filename)
{ {
// jrl::dynamics::urdf::Parser parser;
//TODO: Specific rep name. link them to the operational frames in pinocchio
// std::map<std::string, std::string>::const_iterator it = specialJoints_.begin();
// for (;it!=specialJoints_.end();++it) {
// parser.specifyREPName(it->first, it->second);
// }
rosInit (false); rosInit (false);
m_model = se3::urdf::buildModel(filename); m_model = se3::urdf::buildModel(filename);
this->m_urdfPath = filename; this->m_urdfPath = filename;
...@@ -89,13 +82,6 @@ void RosRobotModel::setNamespace (const std::string& ns) ...@@ -89,13 +82,6 @@ void RosRobotModel::setNamespace (const std::string& ns)
void RosRobotModel::loadFromParameterServer() void RosRobotModel::loadFromParameterServer()
{ {
//jrl::dynamics::urdf::Parser parser;
//TODO: Specific rep name. link them to the operational frames in pinocchio
// std::map<std::string, std::string>::const_iterator it = specialJoints_.begin();
// for (;it!=specialJoints_.end();++it) {
// parser.specifyREPName(it->first, it->second);
// }
rosInit (false); rosInit (false);
std::string robotDescription; std::string robotDescription;
ros::param::param<std::string> ("/robot_description", robotDescription, ""); ros::param::param<std::string> ("/robot_description", robotDescription, "");
...@@ -119,7 +105,8 @@ void RosRobotModel::loadFromParameterServer() ...@@ -119,7 +105,8 @@ void RosRobotModel::loadFromParameterServer()
XmlRpc::XmlRpcValue JointsNamesByRank_; XmlRpc::XmlRpcValue JointsNamesByRank_;
JointsNamesByRank_.setSize(m_model.names.size()); JointsNamesByRank_.setSize(m_model.names.size());
std::vector<std::string>::const_iterator it = m_model.names.begin()+2; //first joint is universe, second is freeflyer //first joint is universe, second is freeflyer
std::vector<std::string>::const_iterator it = m_model.names.begin()+2;
for (int i=0;it!=m_model.names.end();++it, ++i) JointsNamesByRank_[i]= (*it); for (int i=0;it!=m_model.names.end();++it, ++i) JointsNamesByRank_[i]= (*it);
nh.setParam(jointsParameterName_, JointsNamesByRank_); nh.setParam(jointsParameterName_, JointsNamesByRank_);
} }
...@@ -151,7 +138,7 @@ Vector RosRobotModel::curConf() const ...@@ -151,7 +138,7 @@ Vector RosRobotModel::curConf() const
throw std::runtime_error ("no robot loaded"); throw std::runtime_error ("no robot loaded");
else { else {
//TODO: confirm accesscopy is for asynchronous commands //TODO: confirm accesscopy is for asynchronous commands
Vector currConf = jointPositionSIN.accessCopy(); Vector currConf = jointPositionSIN.accessCopy();
for (int32_t i = 0; i < ffpose.size(); ++i) for (int32_t i = 0; i < ffpose.size(); ++i)
currConf(i) = static_cast<double>(ffpose[i]); currConf(i) = static_cast<double>(ffpose[i]);
......
...@@ -36,21 +36,21 @@ namespace dynamicgraph ...@@ -36,21 +36,21 @@ namespace dynamicgraph
} }
namespace { namespace {
void buildJointNames (sensor_msgs::JointState& jointState, se3::Model& robot_model) { void buildJointNames (sensor_msgs::JointState& jointState, se3::Model* robot_model) {
for (int i=0;i<robot_model.nbody-1;i++) { for (int i=0;i<robot_model->nbody-1;i++) {
// Ignore anchors. // Ignore anchors.
if (se3::nv(robot_model.joints[i]) != 0) { if (se3::nv(robot_model->joints[i]) != 0) {
// If we only have one dof, the dof name is the joint name. // If we only have one dof, the dof name is the joint name.
if (se3::nv(robot_model.joints[i]) == 1) { if (se3::nv(robot_model->joints[i]) == 1) {
jointState.name[i] = robot_model.names[i]; jointState.name[i] = robot_model->names[i];
} }
else { else {
// ...otherwise, the dof name is the joint name on which // ...otherwise, the dof name is the joint name on which
// the dof id is appended. // the dof id is appended.
int joint_dof = se3::nv(robot_model.joints[i]); int joint_dof = se3::nv(robot_model->joints[i]);
for(int j = 0; j<joint_dof; j++) { for(int j = 0; j<joint_dof; j++) {
boost::format fmt("%1%_%2%"); boost::format fmt("%1%_%2%");
fmt % robot_model.names[i]; fmt % robot_model->names[i];
fmt % j; fmt % j;
jointState.name[i + j] = fmt.str(); jointState.name[i + j] = fmt.str();
} }
...@@ -82,14 +82,14 @@ namespace dynamicgraph ...@@ -82,14 +82,14 @@ namespace dynamicgraph
return Value (); return Value ();
} }
se3::Model& robot_model = dynamic->m_model; se3::Model* robot_model = dynamic->m_model;
if (robot_model.nbody == 1) if (robot_model->nbody == 1)
{ {
std::cerr << "no robot in the dynamic entity" << std::endl; std::cerr << "no robot in the dynamic entity" << std::endl;
return Value (); return Value ();
} }
entity.jointState ().name.resize (robot_model.nv); entity.jointState ().name.resize (robot_model->nv);
buildJointNames (entity.jointState (), robot_model); buildJointNames (entity.jointState (), robot_model);
return Value (); return Value ();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment