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 an external URG for Pepper #51

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Binary file added doc/stl/Pepper_internal_USB_connector.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/stl/URG_Stay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/stl/URG_Stay_Base.stl
Binary file not shown.
Binary file added doc/stl/URG_Stay_Tower.stl
Binary file not shown.
7 changes: 7 additions & 0 deletions share/urdf/pepper.urdf
Original file line number Diff line number Diff line change
Expand Up @@ -1461,4 +1461,11 @@
<axis xyz="1.0 0 0"/>
<limit effort="3.25" lower="0" upper="0" velocity="6.28319"/>
</joint>
<link name="ExternalLaser_frame"/>
<joint name="LaserSensor/External_sensor_fixedjoint" type="fixed">
<parent link="Tibia"/>
<child link="ExternalLaser_frame"/>
<origin rpy="0 0 0" xyz="0.1579 0 -0.1073"/>
<axis xyz="0 0 0"/>
</joint>
</robot>
77 changes: 69 additions & 8 deletions src/converters/laser.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ static const char* laserMemoryKeys[] = {

LaserConverter::LaserConverter( const std::string& name, const float& frequency, const qi::SessionPtr& session ):
BaseConverter( name, frequency, session ),
p_memory_(session->service("ALMemory"))
p_memory_(session->service("ALMemory")),
has_ext_laser(false)
{
}

Expand All @@ -141,6 +142,35 @@ void LaserConverter::registerCallback( message_actions::MessageAction action, Ca

void LaserConverter::callAll( const std::vector<message_actions::MessageAction>& actions )
{
// If Pepper has an external URG
if(has_ext_laser){
qi::AnyValue anyvalues;
try{
anyvalues = p_memory_.call<qi::AnyValue>("getData", "Device/Laser/Value");
} catch (const std::exception& e) {
std::cerr << "Could not get data from external LASER sensor. " << std::endl;
}

size_t len = anyvalues.size();

msg_.header.stamp = ros::Time::now();

for( size_t i=0; i<len; i++)
{
qi::AnyReferenceVector anyrefs = anyvalues[i].asListValuePtr();
int ind = (anyrefs[1].content().toFloat() + 2.0923) / (M_PI/512.0);
msg_.ranges[ind] = anyrefs[0].content().toFloat()/1000.0;
}

for_each( message_actions::MessageAction action, actions )
{
callbacks_[action](msg_);
}

return;
}

// Normal laser sensor
static const std::vector<std::string> laser_keys_value(laserMemoryKeys, laserMemoryKeys+90);

std::vector<float> result_value;
Expand Down Expand Up @@ -212,13 +242,44 @@ void LaserConverter::callAll( const std::vector<message_actions::MessageAction>&

void LaserConverter::reset( )
{
msg_.header.frame_id = "base_footprint";
msg_.angle_min = -2.0944; // -120
msg_.angle_max = 2.0944; // +120
msg_.angle_increment = (2*2.0944) / (15+15+15+8+8); // 240 deg FoV / 61 points (blind zones inc)
msg_.range_min = 0.1; // in m
msg_.range_max = 1.5; // in m
msg_.ranges = std::vector<float>(61, -1.0f);
try{
qi::AnyValue anyvalues = p_memory_.call<qi::AnyValue>("getData", "Device/Laser/Value");
has_ext_laser = true;
} catch (const std::exception& e) {
std::cerr << "Could not get data from external LASER sensor. " << std::endl;
}

if(has_ext_laser){
try{
p_laser_ = session_->service("ALLaser");
} catch (const std::exception& e) {
std::cerr << "Could not get ALLaser. " << std::endl;
}

try{
p_laser_.call<qi::AnyValue>("setOpeningAngle", -2.0923, 2.0923);
p_laser_.call<qi::AnyValue>("setDetectingLength", 20, 5600);
p_laser_.call<qi::AnyValue>("laserON");
} catch (const std::exception& e) {
std::cerr << "Could not set laser angle. " << std::endl;
}

msg_.header.frame_id = "ExternalLaser_frame";
msg_.angle_min = -2.0923; // -120
msg_.angle_max = 2.0923; // +120
msg_.angle_increment = (2*2.0923) / 683; // 240 deg FoV / 683 points
msg_.range_min = 0.02; // in m
msg_.range_max = 5.6; // in m
msg_.ranges = std::vector<float>(1024, -1.0f);
}else{
msg_.header.frame_id = "base_footprint";
msg_.angle_min = -2.0944; // -120
msg_.angle_max = 2.0944; // +120
msg_.angle_increment = (2*2.0944) / (15+15+15+8+8); // 240 deg FoV / 61 points (blind zones inc)
msg_.range_min = 0.1; // in m
msg_.range_max = 1.5; // in m
msg_.ranges = std::vector<float>(61, -1.0f);
}
}

} //converter
Expand Down
3 changes: 3 additions & 0 deletions src/converters/laser.hpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ class LaserConverter : public BaseConverter<LaserConverter>
private:

qi::AnyObject p_memory_;
qi::AnyObject p_laser_;

std::map<message_actions::MessageAction, Callback_t> callbacks_;
sensor_msgs::LaserScan msg_;

bool has_ext_laser;
}; // class

} //publisher
Expand Down