reporting/tests/main.cpp
Go to the documentation of this file.
1 #include <rtt/os/main.h>
4 
7 #include <rtt/Activity.hpp>
8 #include <rtt/Port.hpp>
9 
10 using namespace std;
11 using namespace Orocos;
12 using namespace RTT;
13 
15  : public TaskContext
16 {
21 
22 public:
23  TestTaskContext(std::string name)
24  : TaskContext(name),
25  hello("Hello", "The hello thing", "World"),
26  dwport("D2Port"),
27  drport("D1Port"),
28  input("input",3.33)
29  {
30  this->properties()->addProperty( hello );
31  this->ports()->addPort( drport );
32  this->ports()->addPort( dwport );
33  this->addAttribute( input );
34 
35  // write initial value.
36  std::vector<double> init(10, 1.0);
37  dwport.setDataSample( init );
38  this->setPeriod(0.1);
39  start();
40  }
41 
42  void updateHook() {
43  std::vector<double> init(10, input.get() );
44  dwport.write( init );
45  input.set( input.get() + 1 );
46  if (input.get() > 100 )
47  input.set( 0 );
48  }
49 };
50 
52  : public TaskContext
53 {
58 
59 public:
60  TestTaskContext2(std::string name)
61  : TaskContext(name),
62  hello("Hello", "The hello thing", "World"),
63  dwport("D1Port"),
64  drport("D2Port"),
65  input("input", 5.55)
66  {
67  this->properties()->addProperty( hello );
68  this->ports()->addPort( drport );
69  this->ports()->addPort( dwport );
70  this->addAttribute( input );
71  this->setPeriod(0.2);
72  start();
73  }
74 
75  void updateHook() {
76  dwport.write( input.get() );
77  input.set( input.get() + 1 );
78  if (input.get() > 100 )
79  input.set( 0 );
80  }
81 };
82 
83 int ORO_main( int argc, char** argv)
84 {
85  // Set log level more verbose than default,
86  // such that we can see output :
87  if ( Logger::log().getLogLevel() < Logger::Info ) {
88  Logger::log().setLogLevel( Logger::Info );
89  log(Info) << argv[0]
90  << " manually raises LogLevel to 'Info' (5). See also file 'orocos.log'."<<endlog();
91  }
92 
93  ConsoleReporting rc("Reporting");
94  TestTaskContext gtc("MyPeer");
95  TestTaskContext2 gtc2("MyPeer2");
96 
97  TestTaskContext2 gtc3("MySoloPeer");
98 
99  rc.addPeer( &gtc );
100  rc.addPeer( &gtc2 );
101  rc.addPeer( &gtc3 );
102  gtc.connectPorts( &gtc2 );
103 
104  TaskBrowser tb( &rc );
105 
106  // Reporter's activity: not real-time !
107  rc.setActivity( new Activity(ORO_SCHED_OTHER, 0, 1.0) );
108 
109  rc.getProvider<Marshalling>("marshalling")->loadProperties("reporter.cpf");
110  rc.configure();
111 
112  cout <<endl<< " This demo allows reporting of Components." << endl;
113  cout << " Use 'reportComponent(\"MyPeer\")' and/or 'reportComponent(\"MyPeer2\")'" <<endl;
114  cout << " Then invoke 'start()' and 'stop()'" <<endl;
115  cout << " Other methods (type 'this') are available as well."<<endl;
116 
117  tb.loop();
118 
119  rc.stop();
120 
121  return 0;
122 }
123 
void setDataSample(const T &sample)
OutputPort< std::vector< double > > dwport
void loop()
Call this method from ORO_main() to process keyboard input and thus startup the TaskBrowser.
Property< string > hello
This component allows a text client to browse the peers of a peer RTT::TaskContext and execute comman...
Definition: TaskBrowser.hpp:86
InputPort< double > drport
virtual bool stop()
void set(T const &t)
Attribute< double > input
T const & get() const
virtual bool configure()
bool setActivity(base::ActivityInterface *new_act)
TestTaskContext(std::string name)
printstream cout
Attribute< double > input
WriteStatus write(const T &sample)
int ORO_main(int argc, char **argv)
basic_ostreams & endl(basic_ostreams &s)
InputPort< std::vector< double > > drport
Property< string > hello
Info
virtual bool connectPorts(TaskContext *peer)
TestTaskContext2(std::string name)
OutputPort< double > dwport
#define ORO_SCHED_OTHER
virtual bool addPeer(TaskContext *peer, std::string alias="")
boost::shared_ptr< ServiceType > getProvider(const std::string &name)


ocl
Author(s): OCL Development Team
autogenerated on Mon Mar 23 2020 04:47:19