KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
psi_action.h
Go to the documentation of this file.
1 /* $Id: psi_action.h 12743 2012-07-25 23:52:02Z jguan1 $ */
2 /* {{{=========================================================================== *
3  |
4  | Copyright (c) 1994-2011 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Kyle Simek
18  * =========================================================================== }}}*/
19 
20 // vim: tabstop=4 shiftwidth=4 foldmethod=marker
21 
22 #ifndef PSI_VERSION_1_ACTION_H
23 #define PSI_VERSION_1_ACTION_H
24 
25 #include <l_cpp/l_exception.h>
26 #include <string>
27 #include <vector>
28 #include <psi_cpp/psi_units.h>
30 
31 #include <boost/function.hpp>
32 namespace kjb
33 {
34 namespace psi
35 {
36 
60 
61 // get information about an action
62 const std::string& get_name(Action_type t);
64 
65 Action_type action_name_to_type(const std::string& name);
66 
76 struct Action
77 {
78  Action() :
80  parent_index(-1)
81  {
82  }
83 
85  std::vector<double> parameters;
86 
87  // these two fields are for actions that depend on another entity's state
90 };
91 
97 {
99 
101  Action_type type_,
102  std::string name_,
103  size_t num_params_,
104  std::vector<std::string> param_names_,
105  std::vector<Unit_type> param_units_,
106  boost::function1<double, const Action&> get_duration_,
107  bool fixed_length_,
108  bool is_relative_,
109  boost::function1<bool, const Action&> validator_) :
110  type(type_),
111  name(name_),
112  num_params(num_params_),
113  param_names(param_names_),
114  param_units(param_units_),
115  get_duration(get_duration_),
116  fixed_length(fixed_length_),
117  is_relative(is_relative_),
118  validator(validator_)
119  { }
120 
121 
123  std::string name;
124  size_t num_params;
125  std::vector<std::string> param_names;
126  std::vector<Unit_type> param_units;
127 
128  boost::function1<double, const Action&> get_duration;
129 
139 
146 
147  boost::function1<bool, const Action&> validator;
148 };
149 
150 double get_action_duration(const Action& action);
151 
155 void validate(const Action& a);
156 
159 (
160  const std::vector<std::vector<double> >& points
161 );
162 
168 (
169  double duration,
170  size_t parent_type,
171  size_t parent_index,
172  double time_behind
173 )
174 {
175  Action result;
176  result.type = FOLLOW_ACTION;
177  result.parent_type = parent_type;
178  result.parent_index = parent_index;
179 
180  result.parameters.resize(2);
181  result.parameters[0] = duration;
182  result.parameters[1] = time_behind;
183  return result;
184 }
185 
186 
188 inline Action make_walk_action(double duration, double speed)
189 {
190  Action result;
191  result.type = WALK_ACTION;
192  result.parameters.resize(2);
193 
194  result.parameters[0] = duration;
195  result.parameters[1] = speed;
196 
197  return result;
198 }
199 
201 inline Action make_walk_in_arc_action
202 (
203  double duration,
204  double speed,
205  double angular_speed
206 )
207 {
208  Action result;
209  result.type = WALK_IN_ARC_ACTION;
210  result.parameters.resize(3);
211 
212  result.parameters[0] = duration;
213  result.parameters[1] = speed;
214  result.parameters[2] = angular_speed;
215 
216  return result;
217 }
218 
220 inline Action make_null_action(double duration)
221 {
222  Action result;
223  result.type = NULL_ACTION;
224  result.parameters.resize(1);
225  result.parameters[0] = duration;
226 
227  return result;
228 }
229 
230  /*----------------------------------------------------------------------*/
231  /* Utility Functions */
232  /*----------------------------------------------------------------------*/
233 
237 inline size_t get_num_waypoints(size_t param_size)
238 {
239  return (param_size - 1) / 3;
240 }
241 
243 inline size_t to_x_index(size_t i)
244 {
245  return (1 + (3 * i + 0));
246 }
247 
249 inline size_t to_z_index(size_t i)
250 {
251  return (1 + (3 * i + 1));
252 }
253 
255 inline size_t to_time_index(size_t i)
256 {
257  return (1 + (3 * i + 2));
258 }
259 
261 std::ostream& operator<<(std::ostream& ost, const Action& action);
262 
264 std::istream& operator>>(std::istream& ist, Action& action);
265 
267 Action parse_cli_action(const std::string& str);
268 
269 
270 } // namespace psi
271 } // namespace kjb
272 #endif
273 
Action_type type
Definition: psi_action.h:122
Unit_type get_units(Action_type a, size_t i)
Definition: psi_action.cpp:322
boost::function1< double, const Action & > get_duration
Definition: psi_action.h:128
bool is_relative
Definition: psi_action.h:145
Action make_follow_action(double duration, size_t parent_type, size_t parent_index, double time_behind)
Definition: psi_action.h:168
std::ostream & operator<<(std::ostream &ost, const Action &action)
serialize an action
Definition: psi_action.cpp:333
std::vector< double > parameters
Definition: psi_action.h:85
std::istream & operator>>(std::istream &ist, Action &action)
unserialize an action
Definition: psi_action.cpp:346
Unit_type
Definition: psi_units.h:30
size_t to_x_index(size_t i)
Get the x index of the i'th point.
Definition: psi_action.h:243
Definition: psi_action.h:58
Definition: psi_action.h:96
int parent_type
Definition: psi_action.h:88
Action_descriptor()
Definition: psi_action.h:98
Definition: psi_action.h:58
int parent_index
Definition: psi_action.h:89
Action_type
Definition: psi_action.h:58
size_t to_z_index(size_t i)
Get the z index of the i'th point.
Definition: psi_action.h:249
const std::string & get_name(Action_type t)
Convert Action_type to string.
Definition: psi_action.cpp:198
size_t num_params
Definition: psi_action.h:124
Action()
Definition: psi_action.h:78
std::vector< std::string > param_names
Definition: psi_action.h:125
Definition: psi_action.h:59
Action_type type
Definition: psi_action.h:84
size_t to_time_index(size_t i)
Get the time point index of the i'th point.
Definition: psi_action.h:255
Action make_walk_through_points_action(const std::vector< std::vector< double > > &points)
Construct a walk along the trajectory specified by the points.
Definition: psi_action.cpp:251
bool fixed_length
Definition: psi_action.h:138
boost::function1< bool, const Action & > validator
Definition: psi_action.h:147
Definition: psi_action.h:76
Definition: tracking_entity.h:43
std::string name
Definition: psi_action.h:123
Action parse_cli_action(const std::string &str)
read an action that is specified using command-line-interface format
Definition: psi_action.cpp:382
void validate(Action_type a)
check that action_type represents an actual descriptor.
Definition: psi_action.cpp:238
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Action make_null_action(double duration)
Construct a null action.
Definition: psi_action.h:220
Action_descriptor(Action_type type_, std::string name_, size_t num_params_, std::vector< std::string > param_names_, std::vector< Unit_type > param_units_, boost::function1< double, const Action & > get_duration_, bool fixed_length_, bool is_relative_, boost::function1< bool, const Action & > validator_)
Definition: psi_action.h:100
Support for error handling exception classes in libKJB.
Definition: psi_action.h:58
struct memorypool points
Definition: triangle.c:637
std::vector< Unit_type > param_units
Definition: psi_action.h:126
Definition: psi_action.h:58
double get_action_duration(const Action &action)
Definition: psi_action.cpp:232
Action make_walk_action(double duration, double speed)
Construct a walk action.
Definition: psi_action.h:188
Action_type action_name_to_type(const std::string &name)
Convert string to Action_type.
Definition: psi_action.cpp:212
size_t get_num_waypoints(size_t param_size)
Get the number of waypoints from the size of the parameters parameters is in size of 3*num_waypoints+...
Definition: psi_action.h:237
Action make_walk_in_arc_action(double duration, double speed, double angular_speed)
Construct a walk-in-arc action.
Definition: psi_action.h:202