Hello,
one question:
When I load a simple component (based on the HelloWorld example)
than it is in the state "Stopped" and not - as I would expect -
in the Pre-Operational.
Why is that so?
I configure the component in the configureHook(), but this is not
called when I load the component.
I would to avoid that start() can be called without the component
being configured.
What is the suggested way to achieve that?
Regards:
Uwe Fechner
Code:
#include "SensorTask-component.hpp"
#include <rtt/Component.hp
#include <iostream>
#include <iomani
using namespace std;
SensorTask::SensorTask(std::string const& name) : TaskContext(name){
m_zeroMQLink = new ZeroMQLink();
cout << "SensorTask constructed !" << endl;
}
bool SensorTask::configureHook(){
// bind the ZeroMQ link to a port
QString sensor_output = "tcp://*:5575";
if (!m_zeroMQLink->bind(sensor_output)) {
cout << "SensorTask configured succesfully on: " << sensor_output.toStdString();
return true;
} else {
return false;
}
}
bool SensorTask::startHook(){
if (isConfigured()) {
m_zeroMQLink->start();
cout << "SensorTask started. !" << endl;
return true;
} else {
cout << "Warning: Configure SensorTask before starting !" << endl;
return false;
}
}
void SensorTask::updateHook(){
// double time = Utils::timeInSec();
// cout << setiosflags(ios::fixed) << setprecision(2) << "SensorTask executes updateHook at: " <<
time << endl;
}
void SensorTask::stopHook() {
cout << "SensorTask executes stopping !" << endl;
}
void SensorTask::cleanupHook() {
delete m_zeroMQLink;
cout << "SensorTask cleaning up !" << endl;
}
/*
* Using this macro, only one component may live
* in one library *and* you may *not* link this library
* with another component library. Use
* ORO_CREATE_COMPONENT_TYPE()
* ORO_LIST_COMPONENT_TYPE(SensorTask)
* In case you want to link with another library that
* already contains components.
*
* If you have put your component class
* in a namespace, don't forget to add it here too:
*/
ORO_CREATE_COMPONENT(SensorTask)
Component lifecycle
2012/10/20 Uwe Fechner <u [dot] fechner [..] ...>
> Hello,
>
> one question:
>
> When I load a simple component (based on the HelloWorld example)
> than it is in the state "Stopped" and not - as I would expect -
> in the Pre-Operational.
>
> Why is that so?
>
> I configure the component in the configureHook(), but this is not
> called when I load the component.
>
> I would to avoid that start() can be called without the component
> being configured.
>
> What is the suggested way to achieve that?
>
> Regards:
>
> Uwe Fechner
>
> Code:
>
> #include "SensorTask-component.hpp"
> #include <rtt/Component.hp
> #include <iostream>
> #include <iomani
>
> using namespace std;
>
> SensorTask::SensorTask(std::string const& name) : TaskContext(name){
> m_zeroMQLink = new ZeroMQLink();
> cout << "SensorTask constructed !" << endl;
> }
>
>
To indicate that your component must be configured, you have to call
TaskContext construtor with the PreOperational state:
SensorTask::SensorTask(std::string const& name) : TaskContext(name,
PreOperational) {
> bool SensorTask::configureHook(){
> // bind the ZeroMQ link to a port
> QString sensor_output = "tcp://*:5575";
> if (!m_zeroMQLink->bind(sensor_output)) {
> cout << "SensorTask configured succesfully on: " <<
> sensor_output.toStdString();
> return true;
> } else {
> return false;
> }
> }
>
> bool SensorTask::startHook(){
> if (isConfigured()) {
> m_zeroMQLink->start();
> cout << "SensorTask started. !" << endl;
> return true;
> } else {
> cout << "Warning: Configure SensorTask before starting !" << endl;
> return false;
> }
> }
>
> void SensorTask::updateHook(){
> // double time = Utils::timeInSec();
> // cout << setiosflags(ios::fixed) << setprecision(2) << "SensorTask
> executes updateHook at: " <<
> time << endl;
> }
>
> void SensorTask::stopHook() {
> cout << "SensorTask executes stopping !" << endl;
> }
>
> void SensorTask::cleanupHook() {
> delete m_zeroMQLink;
> cout << "SensorTask cleaning up !" << endl;
> }
>
> /*
> * Using this macro, only one component may live
> * in one library *and* you may *not* link this library
> * with another component library. Use
> * ORO_CREATE_COMPONENT_TYPE()
> * ORO_LIST_COMPONENT_TYPE(SensorTask)
> * In case you want to link with another library that
> * already contains components.
> *
> * If you have put your component class
> * in a namespace, don't forget to add it here too:
> */
> ORO_CREATE_COMPONENT(SensorTask)
>
> --
> Orocos-Users mailing list
> Orocos-Users [..] ...
> http://lists.mech.kuleuven.be/mailman/listinfo/orocos-users
>