89 static const double WATTS = 1.0;
100 const std::string& type ) :
101 Model( world, parent, type ),
105 control_mode( CONTROL_VELOCITY ),
106 drive_mode( DRIVE_DIFFERENTIAL ),
107 localization_mode( LOCALIZATION_GPS ),
113 acceleration_bounds(),
127 for(
int i=0; i<3; i++ )
172 const std::string& mode_str =
175 if( mode_str ==
"diff" )
177 else if( mode_str ==
"omni" )
179 else if( mode_str ==
"car" )
182 PRINT_ERR1(
"invalid position drive mode specified: \"%s\" - should be one of: \"diff\", \"omni\" or \"car\". Using \"diff\" as default.", mode_str.c_str() );
192 PRINT_WARN1(
"the odom property is specified for model \"%s\"," 193 " but this property is no longer available." 194 " Use localization_origin instead. See the position" 195 " entry in the manual or src/model_position.c for details.",
226 const std::string& loc_str =
229 if( loc_str ==
"gps" )
231 else if( loc_str ==
"odom" )
234 PRINT_ERR2(
"unrecognized localization mode \"%s\" for model \"%s\"." 235 " Valid choices are \"gps\" and \"odom\".",
236 loc_str.c_str(), this->
Token() );
318 PRINT_ERR(
"car drive not supported in accelerartion control [to do]" );
382 PRINT_DEBUG3(
"errors: %.2f %.2f %.2f\n", x_error, y_error, a_error );
386 double max_speed_x = 0.4;
387 double max_speed_y = 0.4;
388 double max_speed_a = 1.0;
397 vel.
x = std::min( x_error, max_speed_x );
398 vel.
y = std::min( y_error, max_speed_y );
399 vel.
a = std::min( a_error, max_speed_a );
414 double close_enough = 0.02;
417 if( fabs(x_error) < close_enough && fabs(y_error) < close_enough )
421 calc.
a = std::min( a_error, max_speed_a );
422 calc.
a = std::max( a_error, -max_speed_a );
428 double goal_angle = atan2( y_error, x_error );
429 double goal_distance = hypot( y_error, x_error );
432 calc.
a = std::min( a_error, max_speed_a );
433 calc.
a = std::max( a_error, -max_speed_a );
435 PRINT_DEBUG2(
"steer errors: %.2f %.2f \n", a_error, goal_distance );
439 if( fabs(a_error) < M_PI/16 )
442 calc.
x = std::min( goal_distance, max_speed_x );
524 PRINT_ERR2(
"unknown localization mode %d for model %s\n",
529 PRINT_DEBUG3(
" READING POSITION: [ %.4f %.4f %.4f ]\n",
686 const double dx = -odom.
x * cos(da) + odom.
y * sin(da);
687 const double dy = -odom.
y * cos(da) - odom.
x * sin(da);
696 :
Visualizer(
"Position coordinates",
"show_position_coords" )
715 glEnable (GL_LINE_STIPPLE);
716 glLineStipple (3, 0xAAAA);
719 glBegin( GL_LINE_STRIP );
725 glDisable(GL_LINE_STIPPLE);
728 snprintf( label, 64,
"x:%.3f", pos->
est_pose.
x );
731 snprintf( label, 64,
"y:%.3f", pos->
est_pose.
y );
750 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
759 :
Visualizer(
"Position waypoints",
"show_position_waypoints" )
769 if( waypoints.empty() )
779 glTranslatef( 0,0,0.02 );
788 const size_t num(waypoints.size());
794 for(
size_t i(1); i<num ; i++ )
796 Pose p = waypoints[i].pose;
797 Pose o = waypoints[i-1].pose;
799 glVertex2f( p.
x, p.
y );
800 glVertex2f( o.
x, o.
y );
813 : pose(pose), color(color)
818 :
pose(x,y,z,a), color(color)
846 double dx = cos(
pose.
a) * quiver_length;
847 double dy = sin(
pose.
a) * quiver_length;
void SetTurnSpeed(double a)
virtual void PushColor(Color col)
void GoTo(double x, double y, double a)
int subs
the number of subscriptions to this model
virtual void Visualize(Model *mod, Camera *cam)
void UnMapWithChildren(unsigned int layer)
int CallCallbacks(callback_type_t type)
double max
largest value in range, initially zero
The Stage library uses its own namespace.
const std::string ReadString(int entity, const char *name, const std::string &value)
void SetSpeed(double x, double y, double a)
static const double INTEGRATION_ERROR_MAX_X
ModelPosition(World *world, Model *parent, const std::string &type)
void SetStall(bool stall)
watts_t watts
power consumed by this model
int ReadTuple(const int entity, const char *name, const unsigned int first, const unsigned int num, const char *format,...)
double min
smallest value in range, initially zero
static const double WATTS
void draw_origin(double len)
#define PRINT_DEBUG2(m, a, b)
static const double INTEGRATION_ERROR_MAX_Y
Pose & Load(Worldfile *wf, int section, const char *keyword)
Bounds velocity_bounds[4]
Stg::ModelPosition::PoseVis posevis
void DrawFootPrint(const Geom &geom)
static const double INTEGRATION_ERROR_MAX_Z
meters_t z
location in 3 axes
void SetVelocity(const Velocity &val)
void pose_inverse_shift(const Pose &pose)
double normalize(double a)
#define PRINT_DEBUG3(m, a, b, c)
usec_t sim_time
the current sim time in this world in microseconds
Pose est_pose
position estimate in local coordinates
Pose GetGlobalPose() const
bool PropertyExists(int section, const char *token)
Stg::ModelPosition::WaypointVis wpvis
double ReadLength(int entity, const char *name, double value)
Pose goal
the current velocity or pose to reach, depending on the value of control_mode
usec_t interval
time between updates in usec
void pose_shift(const Pose &pose)
void SetBlobReturn(bool val)
std::vector< Waypoint > waypoints
void AddVisualizer(Visualizer *custom_visual, bool on_by_default)
virtual void Visualize(Model *mod, Camera *cam)
Pose est_pose_error
estimated error in position estimate
LocalizationMode localization_mode
global or local mode
Velocity & Load(Worldfile *wf, int section, const char *keyword)
void draw_string(float x, float y, float z, const char *string)
Bounds acceleration_bounds[4]
Velocity GetVelocity() const
#define PRINT_DEBUG1(m, a)
#define PRINT_DEBUG4(m, a, b, c, d)
#define PRINT_ERR2(m, a, b)
Velocity integration_error
errors to apply in simple odometry model
double Constrain(double value)
void MapWithChildren(unsigned int layer)
std::set< ModelPosition * > active_velocity
Pose est_origin
global origin of the local coordinate system
radians_t a
rotation about the z axis.
static const double INTEGRATION_ERROR_MAX_A
static const double WATTS_KGMS
#define PRINT_WARN1(m, a)
void SetAcceleration(double x, double y, double a)
const char * Token() const