rosrun actionlib_msgs genaction.py
C++
1 #include <ros/ros.h>
2 #include <actionlib/server/simple_action_server.h>
3 #include <learning_actionlib/FibonacciAction.h>
4
5 class FibonacciAction
6 {
7 protected:
8
9 ros::NodeHandle nh_;
10 actionlib::SimpleActionServer<learning_actionlib::FibonacciAction> as_; // NodeHandle instance must be created before this line. Otherwise strange error occurs.
11 std::string action_name_;
12 // create messages that are used to published feedback/result
13 learning_actionlib::FibonacciFeedback feedback_;
14 learning_actionlib::FibonacciResult result_;
15
16 public:
17
18 FibonacciAction(std::string name) :
19 as_(nh_, name, boost::bind(&FibonacciAction::executeCB, this, _1), false),
20 action_name_(name)
21 {
22 as_.start();
23 }
24
25 ~FibonacciAction(void)
26 {
27 }
28
29 void executeCB(const learning_actionlib::FibonacciGoalConstPtr &goal)
30 {
31 // helper variables
32 ros::Rate r(1);
33 bool success = true;
34
35 // push_back the seeds for the fibonacci sequence
36 feedback_.sequence.clear();
37 feedback_.sequence.push_back(0);
38 feedback_.sequence.push_back(1);
39
40 // publish info to the console for the user
41 ROS_INFO("%s: Executing, creating fibonacci sequence of order %i with seeds %i, %i", action_name_.c_str(), goal->order, feedback_.sequence[0], feedback_.sequence[1]);
42
43 // start executing the action
44 for(int i=1; i<=goal->order; i++)
45 {
46 // check that preempt has not been requested by the client
47 if (as_.isPreemptRequested() || !ros::ok())
48 {
49 ROS_INFO("%s: Preempted", action_name_.c_str());
50 // set the action state to preempted
51 as_.setPreempted();
52 success = false;
53 break;
54 }
55 feedback_.sequence.push_back(feedback_.sequence[i] + feedback_.sequence[i-1]);
56 // publish the feedback
57 as_.publishFeedback(feedback_);
58 // this sleep is not necessary, the sequence is computed at 1 Hz for demonstration purposes
59 r.sleep();
60 }
61
62 if(success)
63 {
64 result_.sequence = feedback_.sequence;
65 ROS_INFO("%s: Succeeded", action_name_.c_str());
66 // set the action state to succeeded
67 as_.setSucceeded(result_);
68 }
69 }
70
71
72 };
73
74
75 int main(int argc, char** argv)
76 {
77 ros::init(argc, argv, "fibonacci");
78
79 FibonacciAction fibonacci(ros::this_node::getName());
80 ros::spin();
81
82 return 0;
83 }
Also in C++:
- Title
- dfenwick tree code c++
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- array search c++
- Category
- C++
- Title
- type id c++
- Category
- C++
- Title
- knapsack
- Category
- C++
- Title
- leveling system c++
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- cout console
- Category
- C++
- Title
- how to output text in c++
- Category
- C++
- Title
- class in c++
- Category
- C++
- Title
- memset
- Category
- C++
- Title
- what is difffrence between s.length() and s.size()
- Category
- C++
- Title
- 1d fixed length arrays c++
- Category
- C++
- Title
- program to know if a number is prime
- Category
- C++
- Title
- c++ stack
- Category
- C++
- Title
- passing reference in c++
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- dfs in c++
- Category
- C++
- Title
- 2927260.eps 2927262.jpg 2927263.ai License free.txt License premium.txt
- Category
- C++
- Title
- c++ string to integer without stoi
- Category
- C++
- Title
- c++ compiler for sublime text
- Category
- C++
- Title
- c++ convert const char* to LPCWSTR
- Category
- C++
- Title
- set lower bound c++
- Category
- C++
- Title
- c++ transform
- Category
- C++
- Title
- queue stl c++
- Category
- C++
- Title
- minimum swaps to sort an array
- Category
- C++
- Title
- how to run c++ file mingw cmd
- Category
- C++
- Title
- calling by reference and pointers c++
- Category
- C++
- Title
- primos menores que
- Category
- C++
- Title
- accumulate in cpp
- Category
- C++
- Title
- c++ for loop
- Category
- C++
- Title
- c++ throw exception
- Category
- C++
- Title
- clear console c++
- Category
- C++
- Title
- converting char to int in c++
- Category
- C++
- Title
- what is meaning of 64 bit integer in c++
- Category
- C++
- Title
- c++ show time elapsed
- Category
- C++
- Title
- c++ argv
- Category
- C++
- Title
- flushing output in c++
- Category
- C++
- Title
- file objects in c++
- Category
- C++
- Title
- sub string of vector c++
- Category
- C++
- Title
- c++ for loop syntax
- Category
- C++
- Title
- c++ not greater than
- Category
- C++
- Title
- capitalize first letter c++
- Category
- C++
- Title
- body parser
- Category
- C++
- Title
- declaring 2d vector in c++
- Category
- C++
- Title
- how to create a vector in c++
- Category
- C++
- Title
- if vector contains value c++
- Category
- C++
- Title
- int random string generator c++
- Category
- C++
- Title
- stringstream in c++ with delimiter
- Category
- C++
- Title
- how to modulo 10^9+7
- Category
- C++
- Title
- solve linear equations geeksforgeeks
- Category
- C++
- Title
- mingw32/bin/ld.exe: C:\Users\mfrom\AppData\Local\Temp\ccSKcRks.o:PizzaPi.cpp:(.text$_ZN5PizzaC2Ev[__ZN5PizzaC2Ev]+0xa): undefined reference to `vtable for Pizza' collect2.exe: error: ld returned 1 exit status
- Category
- C++
- Title
- how to sort vector in c++
- Category
- C++
- Title
- c++ reset stream
- Category
- C++
- Title
- range based for loop c++ with reference
- Category
- C++
- Title
- how to check datatype of a variable in c++
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- how to remove maximum number of characters in c++ cin,ignore
- Category
- C++
- Title
- c++ append to list
- Category
- C++
- Title
- c++ char print align
- Category
- C++
- Title
- how use global variables instead of local in c++
- Category
- C++
- Title
- how initilaize deffult value to c++ class
- Category
- C++
- Title
- phph date
- Category
- C++
- Title
- compile c++ linux
- Category
- C++
- Title
- assegnare valori in c++
- Category
- C++
- Title
- c++ method name
- Category
- C++
- Title
- string input
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- error: invalid use of template-name without an argument list
- Category
- C++
- Title
- how to sort an array according to another array c++
- Category
- C++
- Title
- varint index
- Category
- C++
- Title
- error: ‘memset’ was not declared in this scope in cpp
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- min coin change problem dp
- Category
- C++
- Title
- sum of two numbers c++
- Category
- C++
- Title
- time function c++
- Category
- C++
- Title
- c++ constructor
- Category
- C++
- Title
- cs1955 unity vector3
- Category
- C++
- Title
- C++ user input
- Category
- C++
- Title
- do while loop c++
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- binary search stl in c++
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- runtime array size c++
- Category
- C++
- Title
- pbds in c++
- Category
- C++
- Title
- graph using djacency matrix c++
- Category
- C++
- Title
- git branch in my bash prompt
- Category
- C++
- Title
- primeros numeors primos menores que
- Category
- C++
- Title
- how to get the largest number in a c++ array
- Category
- C++
- Title
- new keyword in cpp
- Category
- C++
- Title
- built in function in c++ for binary to decimal
- Category
- C++
- Title
- max element in array c++ stl
- Category
- C++
- Title
- variadic templates
- Category
- C++
- Title
- how to use wasd c++
- Category
- C++
- Title
- c++ declare variable
- Category
- C++
- Title
- how can make string value in cpp
- Category
- C++
- Title
- c++ delet from memory
- Category
- C++