25 const double &controller_freq):
26 controller_freq_(controller_freq)
32 catch (
const std::exception& e)
34 ROS_ERROR(
"DCM: Failed to connect to DCM Proxy!\n\tTrace: %s", e.what());
38 bool DCM::init(
const std::vector <std::string> &joints)
57 int joints_nbr = joints.size();
62 commands_[0] = qi::AnyValue(qi::AnyReference::from(
"jointActuator"),
false,
false);
63 commands_[1] = qi::AnyValue(qi::AnyReference::from(
"ClearAll"),
false,
false);
64 commands_[2] = qi::AnyValue(qi::AnyReference::from(
"time-mixed"),
false,
false);
69 for(
int i=0; i<joints_nbr; ++i)
73 commands_values_[i][0][2] = qi::AnyValue(qi::AnyReference::from(0),
false,
false);
82 std::vector <qi::AnyValue> commandAlias;
83 commandAlias.reserve(2);
84 commandAlias.resize(2);
85 commandAlias[0] = qi::AnyValue(qi::AnyReference::from(
"jointActuator"),
false,
false);
88 std::vector <qi::AnyValue> commandAlias_keys;
89 commandAlias_keys.resize(joints.size());
90 for(
int i=0; i<joints.size(); ++i)
92 std::string key =
"Device/SubDeviceList/" + joints.at(i) +
"/Position/Actuator/Value";
93 commandAlias_keys[i] = qi::AnyValue(qi::AnyReference::from(key),
false,
false);
95 commandAlias[1] = qi::AnyValue(qi::AnyReference::from(commandAlias_keys),
false,
false);
97 qi::AnyValue commandAlias_qi(qi::AnyReference::from(commandAlias),
false,
false);
102 dcm_proxy_.call<
void>(
"createAlias", commandAlias_qi);
104 catch(
const std::exception& e)
106 ROS_ERROR(
"DCM: Could not create alias for jonts positions!\n\tTrace: %s", e.what());
115 std::vector <qi::AnyValue> commandAlias;
116 commandAlias.reserve(2);
117 commandAlias.resize(2);
118 commandAlias[0] = qi::AnyValue(qi::AnyReference::from(
"jointStiffness"),
false,
false);
121 std::vector <qi::AnyValue> commandAlias_keys;
122 for(
int i=0; i<joints.size(); ++i)
124 if((joints.at(i) ==
"RHipYawPitch")
125 || (joints.at(i).find(
"Wheel") != std::string::npos))
128 std::string key =
"Device/SubDeviceList/" + joints.at(i) +
"/Hardness/Actuator/Value";
129 commandAlias_keys.push_back(qi::AnyValue(qi::AnyReference::from(key),
false,
false));
131 commandAlias[1] = qi::AnyValue(qi::AnyReference::from(commandAlias_keys),
false,
false);
133 qi::AnyValue commandAlias_qi(qi::AnyReference::from(commandAlias),
false,
false);
138 dcm_proxy_.call<
void>(
"createAlias", commandAlias_qi);
140 catch(
const std::exception& e)
142 ROS_ERROR(
"DCM: Could not create alias for joints hardness!\n\tTrace: %s", e.what());
150 const int& timeOffset,
151 const std::string& type_update)
154 int time =
getTime(timeOffset);
157 qi::AnyValue command_qi;
160 std::vector <qi::AnyValue>
command;
162 command[0] = qi::AnyValue(qi::AnyReference::from(alias),
false,
false);
163 command[1] = qi::AnyValue(qi::AnyReference::from(type_update),
false,
false);
165 std::vector <std::vector <qi::AnyValue> > command_keys;
166 command_keys.resize(1);
167 command_keys[0].resize(2);
168 command_keys[0][0] = qi::AnyValue(qi::AnyReference::from(value),
false,
false);
169 command_keys[0][1] = qi::AnyValue(qi::AnyReference::from(time),
false,
false);
171 command[2] = qi::AnyValue(qi::AnyReference::from(command_keys),
false,
false);
172 command_qi = qi::AnyValue(qi::AnyReference::from(command),
false,
false);
174 catch(
const std::exception& e)
176 ROS_ERROR(
"DCM: Failed to convert to qi::AnyValue \n\tTrace: %s", e.what());
185 catch(
const std::exception& e)
187 ROS_ERROR(
"DCM: Failed to execute DCM timed-command! \n\tTrace: %s", e.what());
197 res =
dcm_proxy_.call<
int>(
"getTime", 0) + offset;
199 catch(
const std::exception& e)
201 ROS_ERROR(
"DCM: Failed to get time! \n\tTrace: %s", e.what());
211 qi::AnyValue commands_qi;
214 std::vector<double>::const_iterator it_comm = joint_commands.begin();
215 for(
int i=0; i<joint_commands.size(); ++i, ++it_comm)
217 commands_values_[i][0][0] = qi::AnyValue(qi::AnyReference::from(static_cast<float>(*it_comm)),
false,
false);
218 commands_values_[i][0][1] = qi::AnyValue(qi::AnyReference::from(time),
false,
false);
222 commands_qi = qi::AnyValue(qi::AnyReference::from(
commands_),
false,
false);
224 catch(
const std::exception& e)
226 ROS_ERROR(
"DCM: Failed to convert to qi::AnyValue \n\tTrace: %s", e.what());
232 dcm_proxy_.call<
void>(
"setAlias", commands_qi);
234 catch(
const std::exception& e)
236 ROS_ERROR(
"DCM: Failed to execute DCM timed-command! \n\tTrace: %s", e.what());
std::vector< std::vector< std::vector< qi::AnyValue > > > commands_values_
bool init(const std::vector< std::string > &joints)
initialize all Aliases
void writeJoints(const std::vector< double > &joint_commands)
update joints values
ROSLIB_DECL std::string command(const std::string &cmd)
DCM(const qi::SessionPtr &session, const double &controller_freq)
bool DCMAliasTimedCommand(const std::string &alias, const float &values, const int &timeOffset, const std::string &type_update="Merge")
DCM Wrapper Method.
std::vector< qi::AnyValue > commands_
void createPositionActuatorCommand(const std::vector< std::string > &joints)
initialize of DCM Motion commands
bool setStiffness(const float &stiffness)
update joints stiffness
bool createHardnessActuatorAlias(const std::vector< std::string > &joints)
create Hardness Actuator Alias
bool createPositionActuatorAlias(const std::vector< std::string > &joints)
create Position Actuator Alias
int getTime(const int &offset)
get time from the DCM proxy