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

Peek ahead on next maneuver #172

Open
wants to merge 6 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
9 changes: 9 additions & 0 deletions src/DUNE/Maneuvers/Maneuver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ namespace DUNE
{
bind<IMC::StopManeuver>(this);
bind<IMC::PathControlState>(this);
// always consume PeekManeuver, even if inactive
bind<IMC::PeekManeuver>(this,true);
}

Maneuver::~Maneuver(void)
Expand Down Expand Up @@ -164,6 +166,13 @@ namespace DUNE
onPathControlState(pcs);
}

void
Maneuver::consume(const IMC::PeekManeuver* pman)
{
debug("Calling onPeekManeuver");
onPeekManeuver(pman);
}

void
Maneuver::signalError(const std::string& msg)
{
Expand Down
10 changes: 10 additions & 0 deletions src/DUNE/Maneuvers/Maneuver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ namespace DUNE
(void)pcs;
}

//! On Peek Maneuver
virtual void
onPeekManeuver(const IMC::PeekManeuver* pman)
{
(void)pman;
}

//! On task activation
//! Should be used only by parent class Maneuver
void
Expand Down Expand Up @@ -166,6 +173,9 @@ namespace DUNE
void
consume(const IMC::PathControlState* pcs);

void
consume(const IMC::PeekManeuver* pman);

//! Set or reconfigure control loops used by maneuver task.
//! @param mask mask identifying controllers that should be made active.
void
Expand Down
6 changes: 6 additions & 0 deletions src/Maneuver/Multiplexer/AbstractMux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ namespace Maneuver
(void)msg;
}

virtual void
onPeekManeuver(const IMC::PeekManeuver* pman)
{
(void)pman;
}

protected:
//! Pointer to task
Maneuvers::Maneuver* m_task;
Expand Down
22 changes: 20 additions & 2 deletions src/Maneuver/Multiplexer/Goto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,24 @@ namespace Maneuver
{
m_task->setControl(IMC::CL_PATH);

IMC::DesiredPath dpath = convertManeuverToPath(maneuver);
m_task->dispatch(dpath);
}

IMC::DesiredPath
convertManeuverToPath(const IMC::Goto* maneuver)
{
IMC::DesiredPath path;
path.end_lat = maneuver->lat;
path.end_lon = maneuver->lon;
path.end_z = maneuver->z;
path.end_z_units = maneuver->z_units;
path.speed = maneuver->speed;
path.speed_units = maneuver->speed_units;

m_task->dispatch(path);
return path;
}


//! On PathControlState message
//! @param[in] pcs pointer to PathControlState message
void
Expand All @@ -81,6 +88,17 @@ namespace Maneuver
m_task->signalProgress(pcs->eta);
}

void
onPeekManeuver(const IMC::PeekManeuver* pman)
{
m_task->debug("Dispatching peeked DesiredPath");
IMC::PeekDesiredPath peek_dpath;
const IMC::PlanManeuver* planman = pman->man.get();
const IMC::Goto* m = static_cast<const IMC::Goto*>(planman->data.get());
peek_dpath.dpath.set(convertManeuverToPath(m));
m_task->dispatch(peek_dpath);
}

~Goto(void)
{ }
};
Expand Down
20 changes: 20 additions & 0 deletions src/Maneuver/Multiplexer/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,26 @@ namespace Maneuver
m_maneuvers[m_type]->onPathControlState(pcs);
}

void
onPeekManeuver(const IMC::PeekManeuver* pman)
{
// figure out what maneuver pman is, and call onPeekManeuver for that maneuver
// as the maneuver type might be different from the current maneuver
const IMC::PlanManeuver* planman = pman->man.get();
const IMC::Maneuver* maneuver = planman->data.get();
MultiplexMap::const_iterator itr = m_map.find(maneuver->getId());
if (itr == m_map.end())
{
//Only warn, as the current maneuver might be supported
war(DTR("unsupported maneuver. Not peeking forward."));
return;
}

ManeuverType type = (ManeuverType)itr->second;
debug("Calling specific onPeekManeuver for %s", maneuver->getName());
m_maneuvers[type]->onPeekManeuver(pman);
}

void
onStateReport(void)
{
Expand Down
17 changes: 17 additions & 0 deletions src/Plan/Engine/Plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ namespace Plan
return loadManeuverFromId(m_last_id);
}

IMC::PlanManeuver*
Plan::peekNextManeuver(void)
{
IMC::PlanManeuver* pman = NULL;
if(m_curr_node->trans.size() > 0)
{
std::string id = m_curr_node->trans[0]->dest_man;
PlanMap::iterator itr = m_graph.find(id);

if (itr != m_graph.end())
{
pman = (&itr->second)->pman;
}
}
return pman;
}

float
Plan::updateProgress(const IMC::ManeuverControlState* mcs)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Plan/Engine/Plan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ namespace Plan
IMC::PlanManeuver*
loadNextManeuver(void);

//! Peek next maneuver message
//! @return NULL if maneuver id is invalid
IMC::PlanManeuver*
peekNextManeuver(void);

//! Get current maneuver id
//! @return current id string
inline std::string
Expand Down
8 changes: 8 additions & 0 deletions src/Plan/Engine/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,14 @@ namespace Plan
changeMode(IMC::PlanControlState::PCS_EXECUTING,
pman->maneuver_id + DTR(": executing maneuver"),
pman->maneuver_id, pman->data.get(), TYPE_INF);
IMC::PlanManeuver* next_man = m_plan->peekNextManeuver();
if(next_man != NULL)
{
IMC::PeekManeuver peek_man;
peek_man.man.set(*next_man);
dispatch(peek_man);
debug("Dispatching peek maneuver!");
}

m_plan->maneuverStarted(pman->maneuver_id);
}
Expand Down