autoware_ai_planning icon indicating copy to clipboard operation
autoware_ai_planning copied to clipboard

what does the following fuction do?

Open zoumaguanxin opened this issue 4 years ago • 6 comments

https://github.com/Autoware-AI/core_planning/blob/15f68b38a99809a2d0a58ee5bdcdc9d60a2f7045/op_local_planner/nodes/op_trajectory_generator/op_trajectory_generator_core.cpp#L163

In this fuction,

if(msg->lanes.size() > 0)
	{
		bool bOldGlobalPath = m_GlobalPaths.size() == msg->lanes.size();

		m_GlobalPaths.clear();

		for(unsigned int i = 0 ; i < msg->lanes.size(); i++)
		{
			PlannerHNS::ROSHelpers::ConvertFromAutowareLaneToLocalLane(msg->lanes.at(i), m_temp_path);

			PlannerHNS::PlanningHelpers::CalcAngleAndCost(m_temp_path);
			m_GlobalPaths.push_back(m_temp_path);

			if(bOldGlobalPath)
			{
				bOldGlobalPath = PlannerHNS::PlanningHelpers::CompareTrajectories(m_temp_path, m_GlobalPaths.at(i));
			}
		}

		if(!bOldGlobalPath)
		{
			bWayGlobalPath = true;
			std::cout << "Received New Global Path Generator ! " << std::endl;
		}
		else
		{
			m_GlobalPaths.clear();
		}
	}

The varibale bOldGlobalPath never be true, so that this function is equal to

if(msg->lanes.size() > 0)
	{
		bool bOldGlobalPath = m_GlobalPaths.size() == msg->lanes.size();
		m_GlobalPaths.clear();
		for(unsigned int i = 0 ; i < msg->lanes.size(); i++)
		{
			PlannerHNS::ROSHelpers::ConvertFromAutowareLaneToLocalLane(msg->lanes.at(i), m_temp_path);

			PlannerHNS::PlanningHelpers::CalcAngleAndCost(m_temp_path);
			m_GlobalPaths.push_back(m_temp_path);
		}
		bWayGlobalPath = true;
		std::cout << "Received New Global Path Generator ! " << std::endl;		
	}

Is it right?

zoumaguanxin avatar Dec 10 '20 03:12 zoumaguanxin

This is part of OpenPlanner. @hatem-darweesh would you mind taking a look?

maximus5684 avatar Dec 10 '20 05:12 maximus5684

No that is not true. In next line. bOldGlobalPath = PlannerHNS::PlanningHelpers::CompareTrajectories(m_temp_path, m_GlobalPaths.at(i)); it could be true or false depending on the similarity between the newly received global paths and the previously received ones.

hatem-darweesh avatar Dec 13 '20 06:12 hatem-darweesh

No that is not true. In next line. bOldGlobalPath = PlannerHNS::PlanningHelpers::CompareTrajectories(m_temp_path, m_GlobalPaths.at(i)); it could be true or false depending on the similarity between the newly received global paths and the previously received ones.

m_GlobalPaths is always cleared, and then the m_tem_path is pushed back into it. So CompareTrajectories(m_temp_path, m_GlobalPaths.at(i)) will return true.

zoumaguanxin avatar Dec 15 '20 01:12 zoumaguanxin

bOldGlobalPath is true when the condition m_GlobalPaths.size() == msg->lanes.size() true. But, when bOldGlobalPath is true, the CompareTrajectories(m_temp_path, m_GlobalPaths.at(i)) doesn't work as your expectation, it always returns true. Then the m_GlobalPaths will be cleared. When next message arriving,bOldGlobalPath must be false.

zoumaguanxin avatar Dec 15 '20 02:12 zoumaguanxin

Taking a second look, you are right. one solution is: use local variable for the global path import, than compare to the previous global path. then if they match do nothing, if not copy the local global path to the m_GlobalPaths. Thank you.

hatem-darweesh avatar Dec 15 '20 05:12 hatem-darweesh

Would one of you mind submitting a pull request?

JWhitleyWork avatar Dec 15 '20 05:12 JWhitleyWork