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

Map Dynamic Casting fails #390

Open
hichamhendy opened this issue Dec 14, 2022 · 0 comments
Open

Map Dynamic Casting fails #390

hichamhendy opened this issue Dec 14, 2022 · 0 comments
Labels

Comments

@hichamhendy
Copy link

I am trying to process the binary map generated from octo binary; however the dynamic casting keeps failing. The call back function as the following

`void Planner::octomapBinaryCallback(const octomap_msgs::Octomap::ConstPtr& binary_msg)

{

ROS_INFO("Message Resolution is %f", binary_msg->resolution);

std::lock_guard<std::mutex> lock(octomap_mutex); 

ros::Time current = ros::Time::now();

// Update map at a fixed rate. This is useful on setting replanning rates for the planner.

if ((current - last_wp_time_).toSec() < mapupdate_dt_) 
{
	return;
}
last_wp_time_ = ros::Time::now();
octomap::AbstractOcTree* msg_octree = octomap_msgs::msgToMap(*binary_msg);
if (tree_oct) 
{
	delete tree_oct;
}
if (msg_octree)
{
    tree_oct = dynamic_cast<octomap::OcTree*>(msg_octree);  // dynamic casting from octomap::AbstractOcTree to octomap::OcTree

	if(tree_oct == NULL)
	{
		ROS_WARN("Casting failed!I'm out");
		return;
	}
		
	else
		ROS_WARN("Resolution is %f", tree_oct->getResolution ());
}

if (tree_oct)
{
    ROS_INFO("%s: Octomap received %zu nodes, %f m of resolution", ros::this_node::getName().c_str(), tree_oct->size(), tree_oct->getResolution());
    fcl::OcTree* tree = NULL;
	tree = (new fcl::OcTree(std::shared_ptr<const octomap::OcTree>(tree_oct)));
	// Update the octree used for collision checking
	updateOctotree(std::shared_ptr<fcl::CollisionGeometry>(tree));
	replan();
	delete tree;
	tree_oct->clear();
} 
else
{
	ROS_ERROR("Error by reading OcTree from stream");
	tree_oct->clear();
} 

}`

can anybody see a problem here??

I traced the problem it lies in this critical command tree_oct = dynamic_cast<octomap::OcTree*>(msg_octree);

@hichamhendy hichamhendy changed the title Map Dynamic Casing fails Map Dynamic Casting fails Dec 14, 2022
@ahornung ahornung added the ROS label Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants