8 #include <rtt/os/main.h> 10 #include <rtt/TaskContext.hpp> 11 #include <taskbrowser/TaskBrowser.hpp> 12 #include <rtt/Logger.hpp> 13 #include <rtt/Property.hpp> 14 #include <rtt/Attribute.hpp> 15 #include <rtt/OperationCaller.hpp> 16 #include <rtt/Port.hpp> 17 #include <rtt/Activity.hpp> 19 #include <ocl/OCL.hpp> 35 :
public RTT::TaskContext
90 cout <<
"Saying Hello '"<<word<<
"' in own thread." <<endl;
98 cout <<
"flag: " << flag <<endl;
99 cout <<
"the_property: "<<
property <<endl;
100 cout <<
"the_attribute: "<< attribute <<endl;
101 cout <<
"the_constant: "<< constant <<endl;
102 cout <<
"Setting 'flag' back to false."<<endl;
106 outport.write(
"Hello World!");
109 while(bufferport.read(sample) == NewData) {
110 log(Debug) <<
"Received " << sample << endlog();
119 :
RTT::TaskContext(name,PreOperational),
121 property(
"Hello Property"), flag(false),
122 attribute(
"Hello Attribute"),
123 constant(
"Hello Constant"),
125 outport(
"the_results",true),
127 bufferport(
"the_buffer_port",ConnPolicy::buffer(13,ConnPolicy::LOCK_FREE,true) )
130 this->setActivity(
new Activity(0, 0.1) );
140 this->properties()->addProperty(
"the_property", property).doc(
"A friendly property.");
142 this->addAttribute(
"flag", flag);
143 this->addAttribute(
"the_attribute", attribute);
144 this->addConstant(
"the_constant", constant);
146 this->ports()->addPort( outport );
147 this->ports()->addPort( bufferport );
149 this->addOperation(
"the_method", &HelloWorld::mymethod,
this, ClientThread ).doc(
"'the_method' Description");
151 this->addOperation(
"the_command", &HelloWorld::sayWorld,
this, OwnThread).doc(
"'the_command' Description").arg(
"the_arg",
"Use 'World' as argument to make the command succeed.");
164 #ifndef OCL_COMPONENT_ONLY 166 int ORO_main(
int argc,
char** argv)
168 RTT::Logger::In in(
"main()");
172 if ( log().getLogLevel() < RTT::Logger::Info ) {
173 log().setLogLevel( RTT::Logger::Info );
174 log(Info) << argv[0] <<
" manually raises LogLevel to 'Info' (5). See also file 'orocos.log'."<<endlog();
177 log(Info) <<
"**** Creating the 'Hello' component ****" <<endlog();
181 log(Info) <<
"**** Using the 'Hello' component ****" <<endlog();
184 log(Info) <<
"**** Reading a RTT::Property: ****" <<endlog();
185 RTT::Property<std::string> p = hello.properties()->getProperty(
"the_property");
187 log(Info) <<
" "<<p.getName() <<
" = " << p.value() <<endlog();
189 log(Info) <<
"**** Sending a RTT::OperationCaller: ****" <<endlog();
190 RTT::OperationCaller<bool(std::string)> c = hello.getOperation<bool(std::string)>(
"the_command");
192 log(Info) <<
" Sending RTT::OperationCaller : " << c.send(
"World")<<endlog();
194 log(Info) <<
"**** Calling a RTT::OperationCaller: ****" <<endlog();
195 RTT::OperationCaller<std::string(void)> m = hello.getOperation<std::string(
void)>(
"the_method");
197 log(Info) <<
" Calling RTT::OperationCaller : " << m() << endlog();
199 log(Info) <<
"**** Starting the TaskBrowser ****" <<endlog();
Every component inherits from the 'RTT::TaskContext' class.
This component allows a text client to browse the peers of a peer RTT::TaskContext and execute comman...
HelloWorld(std::string name)
This example sets the interface up in the Constructor of the component.
std::string constant
Constants are aliased, but can only be changed from the component itself.
RTT::OutputPort< std::string > outport
We publish our data through this RTT::OutputPort.
bool flag
Attribute that you can toggle to influence what is printed in updateHook()
std::string property
Properties take a name, a value and a description and are suitable for XML.
This file contains the macros and definitions to create dynamically loadable components.
RTT::InputPort< std::string > bufferport
This RTT::InputPort buffers incoming data.
std::string mymethod()
An operation we want to add to our interface.
The Orocos Component Library.
bool sayWorld(const std::string &word)
This one is executed in our own thread.
std::string attribute
Attributes are aliased to class variables.
void loop()
Call this method from ORO_main() to process keyboard input and thus startup the TaskBrowser.