⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memposition.h

📁 RoboCup 2D 仿真组冠军源代码之1998年冠军队——CMUnited98源代码
💻 H
📖 第 1 页 / 共 3 页
字号:
/* -*- Mode: C -*- *//* MemPosition.h * CMUnited98 (soccer client for Robocup98) * Peter Stone <pstone@cs.cmu.edu> * Computer Science Department * Carnegie Mellon University * Copyright (C) 1998 Peter Stone * * CMUnited-98 was created by Peter Stone, Manuela Veloso, and Patrick Riley * * You may copy and distribute this program freely as long as you retain this notice. * If you make any changes or have any comments we would appreciate a message. *//* MemPosition.C stores all the information relating to other objects on the field: * other players, the ball, markers, etc. */#ifndef _POSITION_H_#define _POSITION_H_#include "MemPlayer.h"/****************************************************************************************//****************************************************************************************//****************************************************************************************/class Object {public:  /* Methods to get the position  */  float    get_dist();  /* relative */  AngleDeg get_ang();  inline Vector get_abs_pos()    { if (!pos_valid()) my_error ("can't get_abs_pos %d",type);  return gpos; }  Vector get_rel_pos();  inline float get_x() { return get_abs_pos().x; }  inline float get_y() { return get_abs_pos().y; }  inline float pos_valid() { return ( (gconf >= min_valid_conf) ? gconf : 0 ); }    /* Methods to change the position                      */  /* Changes do NOT take effect until update() is called */  virtual void set_polar(float d, float a, Time time);  virtual void set_angle(AngleDeg a, Time time);  virtual void set_chinfo(float dist, float dir, Time time);  /* Method which processes all changes */  virtual void update();    virtual void reset ();  /* 0 confidences */  virtual void sanitize_times();    ObjType type;protected:  float max_conf;  float min_valid_conf;  Bool    seen;  Bool    seen_moving;  Time    seen_time;  /* Based on the object's current position, should it be seen? */  virtual Bool in_view_range(Time time, float angle_buffer = 0, float distance_buffer = 0);    float    dist;  /* polar */  AngleDeg ang;  Time     pdtime;  Time     patime;  inline Time ptime() { return Min(pdtime,patime); }  float  distch;  /* polar */  float  dirch;  Time   chtime;  Vector rpos;  Time   rtime;  Vector gpos;    /* global   */  Time   gtime;  float  gconf;};/****************************************************************************************//****************************************************************************************//****************************************************************************************/class StationaryObject : public Object {public:  void Initialize(MarkerType m, Vector pos, float max, float min_valid, Bool rotate);  void Initialize(SideLine  l, Vector pos, float max, float min_valid, Bool rotate);  Vector get_my_pos(AngleDeg my_ang);  AngleDeg get_my_ang();  Vector get_my_vel(AngleDeg my_ang);  int object_id;};/****************************************************************************************//****************************************************************************************//****************************************************************************************/class MobileObject : public Object {public:  virtual void Initialize(ObjType t, float max, float min_valid, float decay, float motion, float speed);  AngleDeg get_rel_heading();  Vector get_rel_vel(); /* relative direction, absolute speed */  /* Methods to get the velocity */  inline Vector get_abs_vel()  /* global   */    { if (!vel_valid()) my_error ("can't get_abs_vel %d",type); return gvel; }  inline float    get_speed()       { return get_abs_vel().mod(); }  inline AngleDeg get_abs_heading() { return get_abs_vel().dir(); }       inline float    vel_valid()       { return ( (gvconf >= min_valid_conf) ? gvconf : 0 ); }  virtual inline Bool moving()      { return vel_valid() && get_speed() != 0 ? TRUE : FALSE; }           /* Methods to change the position                      */  /* Changes do NOT take effect until update() is called */  virtual void set_heard_info (float x, float y, float conf, float dist, Time time);  virtual void set_heard_info (float x, float y, float pconf, float dx, float dy, float vconf, 			       float dist, Time time);  /* Method which processes all changes */  virtual void  update_kick(Time time) = 0; /* pure virtual function */  virtual void  estimate_pos(Time time);  void          estimate_vel(Time time);  virtual void  update(Time time);  virtual void  update_seen(Time time);  void          update_estimate(Time time);  void          update_heard(Time time);  virtual void  reset();  virtual void  forget();  virtual void  sanitize_times();  Vector        estimate_future_pos(int steps, Vector extra_vel=0.0, Vector extra_vel_per=0.0);protected:  float conf_decay;  float motion_decay;  float max_speed;  Vector gvel;    /* global   */  Time   gvtime;  float  gvconf;private:  Bool heard;  Bool heard_moving;  Vector rvel;    /* relative direction, absolute speed */  Time   rvtime;  Vector hpos;    /* heard */  Vector hvel;      Time   hptime;  Time   hvtime;  float  hpdist;  float  hvdist;  float  hpconf;  float  hvconf;};/****************************************************************************************//****************************************************************************************//****************************************************************************************/class BallObject : public MobileObject {public:  void Initialize(float max, float min_valid, float decay, float motion, float max_speed);  Bool moving();  Bool kickable(float buffer = 0.0);  Bool catchable();  float get_kick_rate(Time time);  void update_kick(Time time);  void estimate_pos(Time time);  void update(Time time);  void update_seen(Time time);          float calc_kick_rate(float dist, float ang);  float calc_kick_rate() {return calc_kick_rate(get_dist(), get_ang());}  void forget_past_kick(Time t); protected:  Bool  in_view_range(Time time, float angle_buffer = 3, float distance_buffer = .1);  private:  float effective_kick_rate;  Time  ektime;  Bool use_pos_based_vel_estimate;  Time pos_based_vel_time;    Time   last_seen_time;  Vector last_seen_pos;  /* we keep a record of the most recent kicks we try to do so that     we can estimate the velocity of the ball from subsequent positions */#define num_past_kicks (7)		  int past_kick_idx;  struct PastKick {    Time time;    Vector kick_effect;  } past_kicks[num_past_kicks];  int past_kick_inc(int i)    { return (i+1) % num_past_kicks; }  int past_kick_dec(int i)    { return ((i-1)+num_past_kicks) % num_past_kicks; }};/****************************************************************************************//****************************************************************************************//****************************************************************************************/class PlayerObject : public MobileObject {public:  void Initialize(float max, float min_valid, float decay, float motion, float max_speed);  char side;  Unum unum;  AngleDeg get_rel_face();  /* Methods to get the velocity */  inline AngleDeg get_abs_face() { return gface; }  /* global   */  inline float  face_valid() { return ( (gfconf >= min_valid_conf) ? gfconf : 0 ); }  /* Methods to change the position                      */  /* Changes do NOT take effect until update() is called */  void set_face      (AngleDeg face , Time time);  void set_heard_info_w_face (float x, float y, float pconf, float dx, float dy, float vconf, 				  AngleDeg face, float fconf, float dist, Time time);  /* Method which processes all changes */  void  update(Time time);  void  update_seen_face(Time time);  void  update_estimate(Time time);  void  update_heard(Time time);  void  reset();  void  forget();  void  sanitize_times();  /* This is a pure virtual MobileObject fn.  Shouldn't be called for playerobject */  inline void update_kick(Time time) { my_error("Can't kick players %d",time.t); }protected:  Bool  in_view_range(Time time, float angle_buffer = 3, float distance_buffer = 1);private:  Bool     seen_face;  Bool     heard_face;  AngleDeg rface;  /* relative */  Time     rftime;  AngleDeg gface;  /* global   */  float    gfconf;  Time     gftime;  AngleDeg hface;  /* heard    */  float    hfconf;  float    hfdist;  Time     hftime;};/****************************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -