atlasmv.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
32 #ifndef _ATLASMV_H_
33 #define _ATLASMV_H_
34 
35 #define _DO_NOT_USE_OPENCV_ 0
36 #define _DO_NOT_USE_CARMEN_ 0
37 
38 //####################################################################
39 // Includes: no need to include headers from carmen modules carmen.h #
40 // already does #####################################
41 //####################################################################
42 
43 #include "c_atlasmv.h"
44 
45 #include <pthread.h>
46 #include <strings.h>
47 #include <math.h>
48 #include <queue>
49 #include <vector>
50 #include <atlasmv_base/AtlasmvLightsCommand.h>
51 #include <atlasmv_base/AtlasmvVertSignsCommand.h>
52 #include <atlasmv_base/AtlasmvMotionCommand.h>
53 #include <atlasmv_base/AtlasmvStatus.h>
54 
55 using namespace std;
56 
57 template <class cmd_type>
59 {
60  typename std::map<int,cmd_type> message_map;
61 
62  typename std::map<int,cmd_type>::iterator it;
63 
64  public:
65  void maintenance(void)
66  {
67  for(it=message_map.begin();it!=message_map.end();it++)
68  if(ros::Time::now().toSec() > (*it).second->lifetime)
69  message_map.erase(it);
70  }
71 
72  void push_msg(cmd_type msg)
73  {
74  msg->lifetime=ros::Time::now().toSec()+msg->lifetime;
75 
76  it=message_map.find(msg->priority);
77 
78  if(it==message_map.end())
79  message_map[msg->priority]=msg;
80  else
81  {
82  message_map.erase(it);
83  message_map[msg->priority]=msg;
84  }
85  }
86 
87  cmd_type top_msg(void)
88  {
89  maintenance();
90 
91  int max_priority=-1;
92  typename std::map<int,cmd_type>::iterator it_max;
93 
94  for(it=message_map.begin();it!=message_map.end();it++)
95  if((*it).second->priority > max_priority)
96  {
97  max_priority=(*it).second->priority;
98  it_max=it;
99  }
100 
101  if(message_map.size())
102  return (*it_max).second;
103 
104  cmd_type null_ptr;
105  return null_ptr;
106  }
107 };
108 
109 
110 typedef struct
111 {
113  double X,Y;
115  double V;
117  double SA;
119  double HA;
121  double L;
123  double S;
125  double R;
127 
128 //####################################################################
129 // Typedefs: required typedefs are declared here. All declared types #
130 // should have TYPE_[the name] ###############################
131 //####################################################################
132 
133 //####################################################################
134 // Prototypes: for private functions can be declared #################
135 // in atlasmv.c or preferably in atlasmv_functions.c ##
136 //####################################################################
137 int main(int argc, char **argv);
138 void atlasmv_shutdown_module(int x);
139 void atlasmv_help(bool debug);
140 // void handler_param_daemon(void);
141 // void handler_speed_gain(TYPE_des_sysparam* sys, c_atlasmv* robot, TYPE_executionflags *);
142 // void handler_motion(custom_data_t *);
143 // bool CheckBrakeToggle(void);
144 
145 double percentage2real_velocity(double percentage);
146 int increment_motion_model(t_motion_model*model,double dt);
147 int update_motion_model(t_motion_model*model,double velocity,double steering_angle);
148 int initialize_motion_model(t_motion_model*model,double X0,double Y0,double orientation,double wheelbase);
149 
150 //####################################################################
151 // Global vars: They will be in the scope of modulename.c main's #####
152 // otherwise are declared extern #####################################
153 //####################################################################
154 
155 //####################################################################
156 // Global vars: They will be in the scope of modulename.c main's #####
157 // otherwise are declared extern #####################################
158 //####################################################################
159 //mike confusion, uses a message structure to install parameters. message and parameters should not be different?
160 
161 
162 //a thread for each communication
165 pthread_mutex_t speed_mutex = PTHREAD_MUTEX_INITIALIZER;
166 pthread_mutex_t dir_mutex = PTHREAD_MUTEX_INITIALIZER;
167 pthread_mutex_t brk_mutex = PTHREAD_MUTEX_INITIALIZER;
168 pthread_mutex_t dioc_mutex = PTHREAD_MUTEX_INITIALIZER;
169 pthread_mutex_t command_mutex = PTHREAD_MUTEX_INITIALIZER;
170 pthread_mutex_t count_des_errors_mutex;
171 pthread_mutex_t speed_check_mutex;
173 pthread_mutex_t brake_check_mutex;
176 
177 
178 TYPE_atlasmv_public_params params; //this is a structure
181 
182 double speed, dir, brake;
184 
185 atlasmv_base::AtlasmvStatusPtr atlasmv_status;
186 atlasmv_base::AtlasmvMotionCommandPtr atlasmv_motion;
187 atlasmv_base::AtlasmvVertSignsCommandPtr atlasmv_vert_signs;
188 atlasmv_base::AtlasmvLightsCommandPtr atlasmv_lights;
189 
190 
191 
194 
196 
197 #endif
pthread_mutex_t command_mutex
Definition: atlasmv.h:169
void atlasmv_help(bool debug)
writes used flags for help.
Definition: atlasmv.cpp:595
double SA
Steering angle.
Definition: atlasmv.h:117
c_timer timer
Definition: atlasmv.h:179
atlasmv_base::AtlasmvLightsCommandPtr atlasmv_lights
Definition: atlasmv.h:188
int initialize_motion_model(t_motion_model *model, double X0, double Y0, double orientation, double wheelbase)
Initialize car motion model.
Definition: atlasmv.cpp:530
double S
Distance traveled.
Definition: atlasmv.h:123
pthread_mutex_t speed_mutex
Definition: atlasmv.h:165
int main(int argc, char **argv)
Definition: atlasmv.cpp:328
c_atlasmv.h file for this module. Includes, global vars, function prototypes, etc.
pthread_t servos_thread
Definition: atlasmv.h:163
class that defines everything related with the atlasmv robot interface. this class only deals with SI...
Definition: c_atlasmv.h:143
int des_iret
Definition: atlasmv.h:164
pthread_t des_thread
Definition: atlasmv.h:163
double brake
Definition: atlasmv.h:182
double percentage2real_velocity(double percentage)
pthread_t dioc_thread
Definition: atlasmv.h:163
int servos_iret
Definition: atlasmv.h:164
cmd_type top_msg(void)
Definition: atlasmv.h:87
int count_des_errors
Definition: atlasmv.h:175
pthread_mutex_t brake_check_mutex
Definition: atlasmv.h:173
double V
Linear velocity.
Definition: atlasmv.h:115
void atlasmv_shutdown_module(int x)
int brake_check
Definition: atlasmv.h:174
void maintenance(void)
Definition: atlasmv.h:65
std::map< int, cmd_type > message_map
Definition: atlasmv.h:60
int dioc_iret
Definition: atlasmv.h:164
pthread_mutex_t dir_mutex
Definition: atlasmv.h:166
TYPE_atlasmv_public_params atlasmv_details
Definition: atlasmv.h:192
c_atlasmv * atlasmv
Definition: atlasmv.h:193
atlasmv_base::AtlasmvStatusPtr atlasmv_status
Definition: atlasmv.h:185
command_queue_priority< atlasmv_base::AtlasmvMotionCommandPtr > command_queue
Definition: atlasmv.h:195
int update_motion_model(t_motion_model *model, double velocity, double steering_angle)
Updates velocity and steering variables.
Definition: atlasmv.cpp:548
atlasmv_base::AtlasmvVertSignsCommandPtr atlasmv_vert_signs
Definition: atlasmv.h:187
double Y
Definition: atlasmv.h:113
std::map< int, cmd_type >::iterator it
Definition: atlasmv.h:62
pthread_mutex_t speed_check_mutex
Definition: atlasmv.h:171
double dir
Definition: atlasmv.h:182
TYPE_atlasmv_public_params params
Definition: atlasmv.h:178
double HA
Heading angle.
Definition: atlasmv.h:119
double L
Wheelbase.
Definition: atlasmv.h:121
double speed
Definition: atlasmv.h:182
void push_msg(cmd_type msg)
Definition: atlasmv.h:72
double R
Curve radius.
Definition: atlasmv.h:125
pthread_mutex_t brk_mutex
Definition: atlasmv.h:167
pthread_mutex_t dioc_mutex
Definition: atlasmv.h:168
int speed_check
Definition: atlasmv.h:172
pthread_mutex_t count_des_errors_mutex
Definition: atlasmv.h:170
char new_command_received
Definition: atlasmv.h:183
atlasmv_base::AtlasmvMotionCommandPtr atlasmv_motion
Definition: atlasmv.h:186
Definition: timer.h:64
typedef that includes all params that define atlasmv robot
Definition: c_atlasmv.h:96
t_motion_model motion_model
Definition: atlasmv.h:180
int increment_motion_model(t_motion_model *model, double dt)
Increments motion model based on the current available information.
Definition: atlasmv.cpp:561


atlasmv_base
Author(s): David Gameiro, Jorge Almeida
autogenerated on Mon Mar 2 2015 01:31:28