We will create a task that will pull the temperature value then send it to the BUS.
First we will create a task using the dune_create_task script. Execute the following command
DH> python programs/scripts/dune-create-task.py . DuneAuthor Tutorials/TempProd
This will create TempProd task. Open the DH>src/Tutorials/TempProd/Task.cpp and write the following code.
#include <DUNE/DUNE.hpp> namespace Tutorials { namespace TempProd { using DUNE_NAMESPACES; struct Task: public DUNE::Tasks::Periodic { // Parameters. double m_temp; Task(const std::string& name, Tasks::Context& ctx): DUNE::Tasks::Periodic(name, ctx) { param("Temperature", m_temp) .description("Temperature to produce") .defaultValue("25.0"); } void onEntityReservation(void) { inf("Starting: %s", resolveEntity(getEntityId()).c_str()); } void task(void) { IMC::Temperature temperature; temperature.setSourceEntity(getEntityId()); temperature.value = m_temp; dispatch(temperature); } }; } } DUNE_TASK
[Example2 main page] (https://github.com/LSTS/dune/wiki/Example2) [Next Section: Consumer Task] (https://github.com/LSTS/dune/wiki/ConsumerTask-ex2)
There was an error while loading. Please reload this page.