Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add joint limits to the diagnostics #92

Merged
merged 2 commits into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ build*
doc/*
!doc/source/*
!doc/Doxyfile
*.pro
*.pro.user
47 changes: 44 additions & 3 deletions src/converters/diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,51 @@ DiagnosticsConverter::DiagnosticsConverter( const std::string& name, float frequ
p_body_temperature_.call<void>("setEnableNotifications", true);
}

std::vector<std::vector<float> > joint_limits;
qi::AnyValue qi_joint_limits;

// Get all the joint names
qi::AnyObject p_motion = session->service("ALMotion");
joint_names_ = p_motion.call<std::vector<std::string> >("getBodyNames", "JointActuators" );
this->p_motion_ = session->service("ALMotion");
joint_names_ = this->p_motion_.call<std::vector<std::string> >("getBodyNames", "JointActuators");

for(std::vector<std::string>::const_iterator it = joint_names_.begin(); it != joint_names_.end(); ++it) {
all_keys_.push_back(std::string("Device/SubDeviceList/") + (*it) + std::string("/Temperature/Sensor/Value"));
all_keys_.push_back(std::string("Device/SubDeviceList/") + (*it) + std::string("/Hardness/Actuator/Value"));

// Get the joint limits
joint_limits.clear();

try {
qi_joint_limits = this->p_motion_.call<qi::AnyValue>(
"getLimits",
(*it));

} catch (const std::exception &e) {
std::cerr << "Exception caught in DiagnosticsConverter: "
<< e.what()
<< std::endl;
continue;
}

try {
tools::fromAnyValueToFloatVectorVector(qi_joint_limits, joint_limits);

} catch (std::exception &e) {
std::cerr << "Error while converting the qi value corresponding to "
<< "the joint's limits : "
<< e.what()
<< std::endl;
continue;
}

this->joint_limit_map_[(*it)].push_back(
static_cast<double>(joint_limits[0][0]));
this->joint_limit_map_[(*it)].push_back(
static_cast<double>(joint_limits[0][1]));
this->joint_limit_map_[(*it)].push_back(
static_cast<double>(joint_limits[0][2]));
this->joint_limit_map_[(*it)].push_back(
static_cast<double>(joint_limits[0][3]));
}

// Get all the battery keys
Expand Down Expand Up @@ -125,6 +163,10 @@ void DiagnosticsConverter::callAll( const std::vector<message_actions::MessageAc
status.hardware_id = joint_names_[i];
status.add("Temperature", temperature);
status.add("Stiffness", stiffness);
status.add("minAngle", this->joint_limit_map_[joint_names_[i]][0]);
status.add("maxAngle", this->joint_limit_map_[joint_names_[i]][1]);
status.add("maxVelocity", this->joint_limit_map_[joint_names_[i]][2]);
status.add("maxTorque", this->joint_limit_map_[joint_names_[i]][3]);

// Define the level
if (temperature < temperature_warn_level_)
Expand Down Expand Up @@ -241,7 +283,6 @@ void DiagnosticsConverter::callAll( const std::vector<message_actions::MessageAc
else
ss << "Total Current: " << std::setw(5) << current << " Ampere (discharging)";
status.message = ss.str();

msg.status.push_back(status);
}

Expand Down
5 changes: 4 additions & 1 deletion src/converters/diagnostics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ class DiagnosticsConverter : public BaseConverter<DiagnosticsConverter>
std::vector<std::string> all_keys_;
/** Keys for the battery status */
std::vector<std::string> battery_status_keys_;

/** Map storing the joints informations */
std::map<std::string, std::vector<double> > joint_limit_map_;
/** Proxy to ALMemory */
qi::AnyObject p_memory_;
/** Proxy to ALMotion */
qi::AnyObject p_motion_;
/** Proxy to ALBodyTemperature */
qi::AnyObject p_body_temperature_;

Expand Down
39 changes: 39 additions & 0 deletions src/tools/from_any_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,44 @@ std::vector<std::string> fromAnyValueToStringVector(qi::AnyValue& value, std::ve
return result;
}


void fromAnyValueToFloatVectorVector(
qi::AnyValue &value,
std::vector< std::vector<float> > &result) {

qi::AnyReferenceVector anyrefs;

try {
anyrefs = value.asListValuePtr();

} catch (const std::exception& e) {
throw std::exception(e);
}

result.resize(anyrefs.size());

for(int i=0; i<anyrefs.size(); i++) {
qi::AnyReferenceVector anyref;

try {
anyref = anyrefs[i].asListValuePtr();

} catch (const std::exception& e) {
throw std::exception(e);
}

result[i].resize(anyref.size());

for(int j=0; j<anyref.size(); j++) {
try {
result[i][j] = anyref[j].content().toFloat();

} catch(std::runtime_error& e) {
throw std::exception(e);
}
}

}
}
}
}
5 changes: 4 additions & 1 deletion src/tools/from_any_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ std::vector<std::string> fromAnyValueToStringVector(qi::AnyValue& value, std::ve

std::vector<float> fromAnyValueToFloatVector(qi::AnyValue& value, std::vector<float>& result);

}
void fromAnyValueToFloatVectorVector(
qi::AnyValue &value,
std::vector< std::vector<float> > &result);

}
}

#endif // FROM_ANY_VALUE_HPP