state_machine.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Author: David Gossow
30  */
31 /*
32  * state_machine.h
33  *
34  * Created on: Jul 17, 2012
35  * Author: gossow
36  */
37 
38 #ifndef INTERACTIVE_MARKERS_STATE_MACHINE_H_
39 #define INTERACTIVE_MARKERS_STATE_MACHINE_H_
40 
41 #include <ros/ros.h>
42 
43 namespace interactive_markers
44 {
45 
46 // Helper class for state management
47 template<class StateT>
49 {
50 public:
51  StateMachine( std::string name, StateT init_state );
52  StateMachine& operator=( StateT state );
53  operator StateT();
55 private:
56  StateT state_;
58  std::string name_;
59 };
60 
61 template<class StateT>
62 StateMachine<StateT>::StateMachine( std::string name, StateT init_state )
63 : state_(init_state)
64 , chg_time_(ros::Time::now())
65 , name_(name)
66 {
67 };
68 
69 template<class StateT>
71 {
72  if ( state_ != state )
73  {
74  ROS_DEBUG( "Setting state of %s to %lu", name_.c_str(), (int64_t)state );
75  state_ = state;
76  chg_time_=ros::Time::now();
77  }
78  return *this;
79 }
80 
81 template<class StateT>
83 {
84  return ros::Time::now()-chg_time_;
85 }
86 
87 template<class StateT>
89 {
90  return state_;
91 }
92 
93 }
94 
95 #endif /* STATE_MACHINE_H_ */
interactive_markers::StateMachine::chg_time_
ros::Time chg_time_
Definition: state_machine.h:57
ros
ros.h
interactive_markers::StateMachine::getDuration
ros::Duration getDuration()
Definition: state_machine.h:82
interactive_markers::StateMachine
Definition: state_machine.h:48
ROS_DEBUG
#define ROS_DEBUG(...)
interactive_markers::StateMachine::StateMachine
StateMachine(std::string name, StateT init_state)
Definition: state_machine.h:62
ros::Time
interactive_markers
Definition: message_context.h:45
interactive_markers::StateMachine::operator=
StateMachine & operator=(StateT state)
Definition: state_machine.h:70
interactive_markers::StateMachine::name_
std::string name_
Definition: state_machine.h:58
ros::Duration
interactive_markers::StateMachine::state_
StateT state_
Definition: state_machine.h:56
ros::Time::now
static Time now()


interactive_markers
Author(s): David Gossow, William Woodall
autogenerated on Fri Oct 27 2023 02:31:54