visualsenderplayer.cpp

来自「2009 ROBOCUP 仿真2DSERVER 源码」· C++ 代码 · 共 1,081 行 · 第 1/3 页

CPP
1,081 行
字号
VisualSenderPlayerV4::serializePlayer( const Player & player,                                       const std::string & name,                                       const double & dist,                                       const int dir,                                       const double & dist_chg,                                       const double & dir_chg ){    serializer().serializeVisualObject( transport(),                                        name,                                        dist, dir, dist_chg, dir_chg,                                        calcBodyDir( player ) );}// int// VisualSenderPlayerV4::calcBodyDir( const Player & player ) const// {//     return rad2Deg( normalize_angle( player.angleBodyCommitted()//                                      - self().angleBodyCommitted()//                                      - self().angleNeckCommitted() ) );// }/*!//===================================================================////  CLASS: VisualSensorPlayerV5////  DESC: Class for the version 5 visual protocol.  This version//        introduced head directions of players. Everything else is//        the same////===================================================================*/VisualSenderPlayerV5::VisualSenderPlayerV5( const Params & params )    : VisualSenderPlayerV4( params ){}VisualSenderPlayerV5::~VisualSenderPlayerV5(){}voidVisualSenderPlayerV5::serializePlayer( const Player & player,                                       const std::string & name,                                       const double & dist,                                       const int dir,                                       const double & dist_chg,                                       const double & dir_chg ){    serializer().serializeVisualObject( transport(),                                        name,                                        dist, dir, dist_chg, dir_chg,                                        calcBodyDir( player ),                                        calcHeadDir( player ) );}/*!//===================================================================////  CLASS: VisualSensorPlayerV6////  DESC: Class for the version 6 visual protocol.  This version//        introduced shortened names for all the objects meaning the//        name calculation must be redefined.////===================================================================*/VisualSenderPlayerV6::VisualSenderPlayerV6( const Params & params )    : VisualSenderPlayerV5( params ){}VisualSenderPlayerV6::~VisualSenderPlayerV6(){}/*!//===================================================================////  CLASS: VisualSensorPlayerV7////  DESC: Class for the version 7 visual protocol.  This version//        fixed a bug in the generation of directions in that they//        were truncated to int, rather than rounded.  This meant//        error in the direction pointed was at most times between//        -0.5 and +0.5 degrees, but occationally between -1.0 and//        +1.0 degrees and at other times exact.  With the new method//        of rounding, the error is always between -0.5 and +0.5.////===================================================================*/VisualSenderPlayerV7::VisualSenderPlayerV7( const Params & params )    : VisualSenderPlayerV6( params ){}VisualSenderPlayerV7::~VisualSenderPlayerV7(){}/*!//===================================================================////  CLASS: VisualSensorPlayerV8////  DESC: Class for the version 8 visual protocol.  This version//        introduced observation of the a new arm feature, that//        allows plays to point to different spots, however, on//        direction the arm is pointing to is visable, not the//        distance to the spot the arm is pointing to.////===================================================================*/VisualSenderPlayerV8::VisualSenderPlayerV8( const Params & params )    : VisualSenderPlayerV7( params ){}VisualSenderPlayerV8::~VisualSenderPlayerV8(){}intVisualSenderPlayerV8::calcPointDir( const Player & player ){    double dir = 0.0;    //if ( player.getArmDir( dir ) )    if ( player.arm().getRelDir( rcss::geom::Vector2D( player.pos().x, player.pos().y ),                                 player.angleBodyCommitted() + player.angleNeckCommitted(),                                 dir ) )    {        dir += player.angleNeckCommitted()            + player.angleBodyCommitted()            - self().angleBodyCommitted()            - self().angleNeckCommitted();        // add random noise        // With a normal distribution, 95% of the values are within 2        // std deviations of the mean, so if we set sigma to 1/2 our        // desired range, then 95% of values will be in that range.        // NOTE: This means that 5% of the time it will be outside        // of this range.        double sigma = self().pos().distance( player.pos() )            / self().teamTooFarLength();            //            / 60.0; // this should be replaced by the line below.            //        //        / ServerParam::instance().getTeamTooFarLength ();        sigma = std::pow( sigma, 4 ); // 4 should be parameterized        // sigma is now a range between 0 and 1.0        double min_noise_level = Deg2Rad( 2.5 ) * 0.5;        // 5.0 should be parameterized.  It is halved for the same        // reason we want sigma to be half the desired range        sigma *= M_PI - min_noise_level;        sigma += min_noise_level;        //sigma is now in a range of 2.5 to 180 degrees, dependant on        //the distance of the player.  95% of the returned random values        //will be within +- 2*sigma of dir        boost::normal_distribution<> rng( dir, sigma );        boost::variate_generator< rcss::random::DefaultRNG &,            boost::normal_distribution<> >            gen( rcss::random::DefaultRNG::instance(), rng );        return rad2Deg( normalize_angle( gen() ) );    }    else    {        return 0;    }}// void// VisualSenderPlayerV8::serializePlayer( const Player & player,//                                        const std::string & name,//                                        const double & dist,//                                        const int dir,//                                        const double & dist_chg,//                                        const double & dir_chg )// {//     if ( player.arm().isPointing() )//     {//         int point_dir = calcPointDir( player );//         serializer().serializeVisualObject( transport(),//                                             name,//                                             dist, dir,//                                             dist_chg, dir_chg,//                                             calcBodyDir( player ),//                                             calcHeadDir( player ),//                                             point_dir,//                                             player.isTackling() );//     }//     else//     {//         serializer().serializeVisualObject( transport(),//                                             name,//                                             dist, dir,//                                             dist_chg, dir_chg,//                                             calcBodyDir( player ),//                                             calcHeadDir( player ),//                                             player.isTackling() );//     }// }// void// VisualSenderPlayerV8::serializePlayer( const Player & player,//                                        const std::string & name,//                                        const double & dist,//                                        const int dir )// {//     if ( player.arm().isPointing() )//     {//         int point_dir = calcPointDir( player );//         serializer().serializeVisualObject( transport(),//                                             name,//                                             dist,//                                             dir,//                                             point_dir,//                                             player.isTackling() );//     }//     else//     {//         serializer().serializeVisualObject( transport(),//                                             name,//                                             dist,//                                             dir,//                                             player.isTackling() );//     }// }voidVisualSenderPlayerV8::serializePlayer( const Player & player,                                       const std::string & name,                                       const double & dist,                                       const int dir,                                       const double & dist_chg,                                       const double & dir_chg ){    if ( player.arm().isPointing() )    {        int point_dir = calcPointDir( player );        serializer().serializeVisualPlayer( transport(),                                            player,                                            name,                                            dist, dir,                                            dist_chg, dir_chg,                                            calcBodyDir( player ),                                            calcHeadDir( player ),                                            point_dir );    }    else    {        serializer().serializeVisualPlayer( transport(),                                            player,                                            name,                                            dist, dir,                                            dist_chg, dir_chg,                                            calcBodyDir( player ),                                            calcHeadDir( player ) );    }}voidVisualSenderPlayerV8::serializePlayer( const Player & player,                                       const std::string & name,                                       const double & dist,                                       const int dir ){    if ( player.arm().isPointing() )    {        int point_dir = calcPointDir( player );        serializer().serializeVisualPlayer( transport(),                                            player,                                            name,                                            dist,                                            dir,                                            point_dir );    }    else    {        serializer().serializeVisualPlayer( transport(),                                            player,                                            name,                                            dist,                                            dir );    }}/*!//===================================================================////  CLASS: VisualSensorPlayerV13////  DESC: Class for the version 13 visual protocol.  This version//        introduced observation of the kicking state of other players.////===================================================================*/VisualSenderPlayerV13::VisualSenderPlayerV13( const Params & params )    : VisualSenderPlayerV8( params ){}VisualSenderPlayerV13::~VisualSenderPlayerV13(){}/*!//===================================================================////  Register senders for different versions////===================================================================*/namespace visual {template< typename Sender >VisualSenderPlayer::Ptrcreate( const VisualSenderPlayer::Params & params ){    return VisualSenderPlayer::Ptr( new Sender( params ) );}RegHolder vp1 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV1 >, 1 );RegHolder vp2 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV1 >, 2 );RegHolder vp3 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV1 >, 3 );RegHolder vp4 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV4 >, 4 );RegHolder vp5 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV5 >, 5 );RegHolder vp6 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV6 >, 6 );RegHolder vp7 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV7 >, 7 );RegHolder vp8 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV8 >, 8 );RegHolder vp9 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV8 >, 9 );RegHolder vp10 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV8 >, 10 );RegHolder vp11 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV8 >, 11 );RegHolder vp12 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV8 >, 12 );RegHolder vp13 = VisualSenderPlayer::factory().autoReg( &create< VisualSenderPlayerV13 >, 13 );}}

⌨️ 快捷键说明

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