LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
self_object.h
Go to the documentation of this file.
1// -*-c++-*-
2
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa AKIYAMA
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
31
32#ifndef RCSC_PLAYER_SELF_OBJECT_H
33#define RCSC_PLAYER_SELF_OBJECT_H
34
38
40#include <rcsc/geom/vector_2d.h>
41#include <rcsc/game_time.h>
42#include <rcsc/types.h>
43
44namespace rcsc {
45
46class BodySensor;
47class ActionEffector;
48class BallObject;
49
52 : public AbstractPlayerObject {
53private:
55 static int S_pos_count_thr;
57 static int S_vel_count_thr;
59 static int S_face_count_thr;
60
62 GameTime M_time;
64 GameTime M_sense_body_time;
65
66
67 // status on field
68 Vector2D M_pos_error;
69 Vector2D M_pos_prev;
70
71 Vector2D M_vel_error;
72
73 AngleDeg M_neck;
74 double M_face_error;
75
76 ViewWidth M_view_width;
77 ViewQuality M_view_quality;
78
79 double M_focus_dist;
80 AngleDeg M_focus_dir;
81
82 StaminaModel M_stamina;
83
84 // some action effect
85 GameTime M_last_catch_time;
86
87 int M_tackle_expires;
88 int M_charged_expires;
89
90 int M_arm_movable;
91 int M_arm_expires;
92 Vector2D M_pointto_rpos;
93 Vector2D M_pointto_pos;
94 GameTime M_last_pointto_time;
95
96 SideID M_attentionto_side;
97 int M_attentionto_unum;
98
100 Vector2D M_last_move;
102 Vector2D M_last_moves[4];
103
104 bool M_collision_estimated;
105 bool M_collides_with_none;
106 bool M_collides_with_ball;
107 bool M_collides_with_player;
108 bool M_collides_with_post;
109
110 // status values for action
111 bool M_kickable;
112 double M_kick_rate;
113 double M_catch_probability;
114 double M_tackle_probability;
115 double M_foul_probability;
116
118 SelfObject( const SelfObject & self ) = delete;
120 SelfObject & operator=( const SelfObject & self ) = delete;
121
122public:
123
131 ~SelfObject() = default;
132
139 static
140 void set_count_thr( const int pos_thr,
141 const int vel_thr,
142 const int face_thr );
143
152 void init( const SideID side,
153 const int unum,
154 const bool goalie );
155
160 virtual
161 bool isSelf() const
162 {
163 return true;
164 }
165
170 virtual
171 void setPlayerType( const int type );
172
177 const PlayerType & playerType() const
178 {
179 return *M_player_type;
180 }
181
186 bool posValid() const;
187
192 bool velValid() const;
193
198 bool faceValid() const;
199
200
205 const Vector2D & posError() const
206 {
207 return M_pos_error;
208 }
209
214 const Vector2D & posPrev() const
215 {
216 return M_pos_prev;
217 }
218
223 double speed() const
224 {
225 return M_vel.r();
226 }
227
232 const Vector2D & velError() const
233 {
234 return M_vel_error;
235 }
236
241 const AngleDeg & neck() const
242 {
243 return M_neck;
244 }
245
250 const double & faceError() const
251 {
252 return M_face_error;
253 }
254
259 const ViewWidth & viewWidth() const
260 {
261 return M_view_width;
262 }
263
268 const ViewQuality & viewQuality() const
269 {
270 return M_view_quality;
271 }
272
277 double focusDist() const
278 {
279 return M_focus_dist;
280 }
281
288 const AngleDeg & focusDir() const
289 {
290 return M_focus_dir;
291 }
292
298
303 const GameTime & catchTime() const
304 {
305 return M_last_catch_time;
306 }
307
312 int tackleExpires() const
313 {
314 return M_tackle_expires;
315 }
316
317 int chargedExpires() const
318 {
319 return M_charged_expires;
320 }
321
326 bool isFrozen() const
327 {
328 return M_tackle_expires > 0
329 || M_charged_expires > 0;
330 }
331
336 bool isTackling() const
337 {
338 return M_tackle_expires > 0;
339 }
340
345 int armMovable() const
346 {
347 return M_arm_movable;
348 }
349
354 int armExpires() const
355 {
356 return M_arm_expires;
357 }
358
363 const Vector2D & pointtoPos() const
364 {
365 return M_pointto_pos;
366 }
367
372 const GameTime & pointtoTime() const
373 {
374 return M_last_pointto_time;
375 }
376
382 {
383 return M_attentionto_side;
384 }
385
390 int attentiontoUnum() const
391 {
392 return M_attentionto_unum;
393 }
394
400 {
401 return M_stamina;
402 }
403
408 double stamina() const
409 {
410 return M_stamina.stamina();
411 }
412
417 double staminaCapacity() const
418 {
419 return M_stamina.capacity();
420 }
421
426 double effort() const
427 {
428 return M_stamina.effort();
429 }
430
435 double recovery() const
436 {
437 return M_stamina.recovery();
438 }
439
445 {
446 return M_collision_estimated;
447 }
448
454 {
455 return M_collides_with_none
456 || M_collides_with_ball
457 || M_collides_with_player
458 || M_collides_with_post;
459 }
460
465 bool collidesWithNone() const
466 {
467 return M_collides_with_none;
468 }
469
474 bool collidesWithBall() const
475 {
476 return M_collides_with_ball;
477 }
478
484 {
485 return M_collides_with_player;
486 }
487
492 bool collidesWithPost() const
493 {
494 return M_collides_with_post;
495 }
496
501 const Vector2D & lastMove() const
502 {
503 return M_last_move;
504 }
505
510 const Vector2D & lastMove( const int i ) const
511 {
512 if ( i < 0 || 2 < i ) return M_last_moves[3];
513 return M_last_moves[i];
514 }
515
520 bool isKickable() const
521 {
522 return M_kickable;
523 }
524
529 double kickRate() const
530 {
531 return M_kick_rate;
532 }
533
538 double dashRate() const
539 {
540 return effort() * playerType().dashPowerRate();
541 }
542
547 double catchProbability() const
548 {
549 return M_catch_probability;
550 }
551
556 double tackleProbability() const
557 {
558 return M_tackle_probability;
559 }
560
565 double foulProbability() const
566 {
567 return M_foul_probability;
568 }
569
570
572
578 void update( const ActionEffector & act,
579 const GameTime & current );
580
581private:
587 void updateWindEffect();
588
589public:
596 void updateAfterSenseBody( const BodySensor & sense,
597 const ActionEffector & act,
598 const GameTime & current );
599
607 const ActionEffector & act,
608 const GameTime & current );
609
619 const Vector2D & pos_err,
620 const double & face,
621 const double & face_err,
622 const GameTime & current );
623
630 const Vector2D & pos_error );
631
638 void updateAngleBySee( const double & face,
639 const double & face_err,
640 const GameTime & current );
641
650 void updateVelDirAfterSee( const BodySensor & sense,
651 const GameTime & current );
652
659 void updateBallInfo( const BallObject & ball );
660
670 void updateKickableState( const BallObject & ball,
671 const int self_reach_cycle,
672 const int teammate_reach_cycle,
673 const int opponent_reach_cycle );
674
676 // used for direct update
677
685 void setViewMode( const ViewWidth & w,
686 const ViewQuality & q )
687 {
688 M_view_width = w;
689 M_view_quality = q;
690 }
691
699 void setPointto( const Vector2D & point,
700 const GameTime & done_time )
701 {
702 M_pointto_pos = point;
703 M_last_pointto_time = done_time;
704 if ( pos().isValid() )
705 {
706 M_pointto_angle = ( point - pos() ).th();
707 M_pointto_count = 0;
708 }
709 }
710
719 const int unum )
720 {
721 M_attentionto_side = side;
722 M_attentionto_unum = unum;
723 }
724
726 // utilities
727
733 double getSafetyDashPower( const double & dash_power ) const
734 {
735 return staminaModel().getSafetyDashPower( playerType(), dash_power );
736 }
737
738};
739
740}
741
742#endif
abstract player object class Header File
abstact player object class
Definition: abstract_player_object.h:52
const Vector2D & pos() const
get global position
Definition: abstract_player_object.h:265
bool goalie() const
get goalie flag
Definition: abstract_player_object.h:238
Vector2D M_vel
velocity
Definition: abstract_player_object.h:79
const PlayerType * M_player_type
player type reference
Definition: abstract_player_object.h:67
AngleDeg M_pointto_angle
global pointing angle
Definition: abstract_player_object.h:90
int M_pointto_count
time count since the last pointto observation
Definition: abstract_player_object.h:91
int unum() const
get player's uniform number
Definition: abstract_player_object.h:220
SideID side() const
get team side id
Definition: abstract_player_object.h:211
const AngleDeg & face() const
get global neck angle
Definition: abstract_player_object.h:373
manages action effect, command counter
Definition: action_effector.h:56
degree wrapper class
Definition: angle_deg.h:45
observed ball object class
Definition: ball_object.h:61
sense_body info holder
Definition: body_sensor.h:47
game time object
Definition: game_time.h:43
heterogeneous player parametor class
Definition: player_type.h:50
double dashPowerRate() const
get the player_type parameter
Definition: player_type.h:229
self object class
Definition: self_object.h:52
bool collidesWithNone() const
get a certain collistion status with no objects
Definition: self_object.h:465
const Vector2D & lastMove(const int i) const
get last 3 move vectors
Definition: self_object.h:510
double effort() const
get current effort value
Definition: self_object.h:426
bool collidesWithPost() const
get a certain collistion status with posts
Definition: self_object.h:492
double foulProbability() const
get estimated foul success probability
Definition: self_object.h:565
const Vector2D & posError() const
get estimated error of agent's global position
Definition: self_object.h:205
bool collisionEstimated() const
get estimated collistion status
Definition: self_object.h:444
const GameTime & pointtoTime() const
get pointto action performed time
Definition: self_object.h:372
SideID attentiontoSide() const
get current attentioned player's side
Definition: self_object.h:381
const Vector2D & pointtoPos() const
get estimated pointing point
Definition: self_object.h:363
double catchProbability() const
get estimated catch success probability
Definition: self_object.h:547
bool faceValid() const
verify angle accuracy
virtual bool isSelf() const
check if this player is self or not
Definition: self_object.h:161
double tackleProbability() const
get estimated tackle success probability
Definition: self_object.h:556
bool isTackling() const
check if player is tackling or not.
Definition: self_object.h:336
void updateBallInfo(const BallObject &ball)
update ball related status
double speed() const
get estimated speed
Definition: self_object.h:223
SelfObject()
constructor. just initialize member variables
void updateByCollision(const Vector2D &pos, const Vector2D &pos_error)
apply collision effect
void init(const SideID side, const int unum, const bool goalie)
set uniform number and goalie flag.
bool posValid() const
velify global position accuracy
bool hasSensedCollision() const
get a flag whether agent has a certain collistion info
Definition: self_object.h:453
bool collidesWithPlayer() const
get a certain collistion status with players
Definition: self_object.h:483
const double & faceError() const
get estimated error about angle
Definition: self_object.h:250
void updateVelDirAfterSee(const BodySensor &sense, const GameTime &current)
adjust velocity direction using observed facing angle and sensed speed
void updateAfterFullstate(const FullstateSensor::PlayerT &my_state, const ActionEffector &act, const GameTime &current)
update status using fullstate info
bool isKickable() const
get ball kickable status
Definition: self_object.h:520
int attentiontoUnum() const
get current attentioned player's uniform number
Definition: self_object.h:390
bool collidesWithBall() const
get a certain collistion status with ball
Definition: self_object.h:474
double kickRate() const
get current estimated kick power rate
Definition: self_object.h:529
const Vector2D & posPrev() const
get global position at previous cycle
Definition: self_object.h:214
bool velValid() const
verify velocity accuracy
const PlayerType & playerType() const
get player type parameter
Definition: self_object.h:177
const AngleDeg & neck() const
get estimated neck angle relative to body angle
Definition: self_object.h:241
int armMovable() const
get arm movable count. if this value equals 0, agent can perform pointto command.
Definition: self_object.h:345
const Vector2D & lastMove() const
get last move vector (transformation from previous to current)
Definition: self_object.h:501
void setPointto(const Vector2D &point, const GameTime &done_time)
set pointto effect
Definition: self_object.h:699
const Vector2D & velError() const
get estimated error of velocity
Definition: self_object.h:232
const ViewWidth & viewWidth() const
get current view width
Definition: self_object.h:259
int tackleExpires() const
get tackle expire count
Definition: self_object.h:312
void setAttentionto(const SideID side, const int unum)
set attentionto effect
Definition: self_object.h:718
double dashRate() const
get current dash power rate
Definition: self_object.h:538
static void set_count_thr(const int pos_thr, const int vel_thr, const int face_thr)
set accuracy count threshold values.
const ViewQuality & viewQuality() const
get current view quality
Definition: self_object.h:268
~SelfObject()=default
destructor. nothing to do
int armExpires() const
get am expires count. if this value equals 0, agent is not pointing anywhere.
Definition: self_object.h:354
Vector2D focusPoint() const
get the estimated focus point according to the self localization result
void updateAngleBySee(const double &face, const double &face_err, const GameTime &current)
update status using see info. but only angle.
double focusDist() const
get the focus distance updated by the sense_body message
Definition: self_object.h:277
virtual void setPlayerType(const int type)
update player type id
const GameTime & catchTime() const
get time when the last catch command is performed
Definition: self_object.h:303
double recovery() const
get current estimated recovery value
Definition: self_object.h:435
const AngleDeg & focusDir() const
get the focus direction updated by the sense_body message
Definition: self_object.h:288
void updateAfterSenseBody(const BodySensor &sense, const ActionEffector &act, const GameTime &current)
update status using sense_body info
double staminaCapacity() const
get current stamina capacity value
Definition: self_object.h:417
void updatePosBySee(const Vector2D &pos, const Vector2D &pos_err, const double &face, const double &face_err, const GameTime &current)
update status using see info
void setViewMode(const ViewWidth &w, const ViewQuality &q)
set view mode
Definition: self_object.h:685
void update(const ActionEffector &act, const GameTime &current)
update status only using internal info
double stamina() const
get current stamina value
Definition: self_object.h:408
void updateKickableState(const BallObject &ball, const int self_reach_cycle, const int teammate_reach_cycle, const int opponent_reach_cycle)
update ball kickable state
bool isFrozen() const
check if body is freezed by tackle effect
Definition: self_object.h:326
double getSafetyDashPower(const double &dash_power) const
get dash power to save recovery decay.
Definition: self_object.h:733
const StaminaModel & staminaModel() const
get current stamina model.
Definition: self_object.h:399
stamina management class
Definition: stamina_model.h:44
double capacity() const
get the current remained stamina capacity
Definition: stamina_model.h:103
double getSafetyDashPower(const PlayerType &player_type, const double dash_power, const double stamina_buffer=1.0) const
get dash power to save recovery
double recovery() const
get current recovery value
Definition: stamina_model.h:85
double effort() const
get current effort value
Definition: stamina_model.h:94
double stamina() const
get current stamina value
Definition: stamina_model.h:76
2D point vector class
Definition: vector_2d.h:46
double r() const
get the length of vector.
Definition: vector_2d.h:146
view quality data class
Definition: view_mode.h:216
view width data class
Definition: view_mode.h:43
fullstate info sensor Header File
game time depending on RCSSServer2D Header File
player's stamina model Header File
fullstate player info
Definition: fullstate_sensor.h:64
the type definition set for the RCSSServer2D
SideID
side type definition
Definition: types.h:47
2d vector class Header File.
player view mode data classes Header File