Skip to content

Commit

Permalink
[Core] clear worlddefine & add rawpos
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-tz committed Apr 12, 2024
1 parent 2eb4c9d commit bac2ea9
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 76 deletions.
4 changes: 2 additions & 2 deletions Core/src/Algorithm/BallSpeedModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ std::tuple<double, CVector> CBallSpeedModel::predictForDist(const double dist){
auto time = (v0 - v1) / _DEC;
return {time, Utils::Polar2Vector(v1, _ballVel.dir())};
}
MobileVisionT CBallSpeedModel::poseForTime(const double time){
ObjectPoseT CBallSpeedModel::poseForTime(const double time){
this->update();
MobileVisionT predictPose;
ObjectPoseT predictPose;
auto v0 = _ballVel.mod();
auto v1 = std::max(v0 - _DEC * time, 0.0);
auto runtime = std::min(v0 / _DEC, time);
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Algorithm/BallSpeedModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CBallSpeedModel
std::tuple<double,CVector> predictForDist(const double dist); // 计算若干距离后的速度
double timeForDist(const double dist); //计算球运动若干距离的时间
CVector speedForDist(const double dist); // 计算球运动若干距离的速度
MobileVisionT poseForTime(const double time); // 计算若干帧以后的绝对位置
ObjectPoseT poseForTime(const double time); // 计算若干帧以后的绝对位置
private:
void update();
CGeoPoint _ballPos;
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Algorithm/BallStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void CBallStatus::UpdateBallStatus(const CVisionModule* pVision)

void CBallStatus::UpdateBallMoving(const CVisionModule* pVision)
{
const MobileVisionT& ball = pVision->ball(); //
const ObjectPoseT& ball = pVision->ball(); //
isNearPlayer = false;
for (int i=0; i<PARAM::Field::MAX_PLAYER*2; i++){
if (pVision->allPlayer(i).Valid() && pVision->allPlayer(i).Pos().dist(ball.Pos())< PARAM::Field::MAX_PLAYER_SIZE/2+5){
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Algorithm/ContactChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool isPointOutField(CGeoPoint pos)
}
void ContactChecker::OutFieldJudge(const CVisionModule* pVision)
{
MobileVisionT last_ball=pVision->ball(pVision->getCycle()-4);
ObjectPoseT last_ball=pVision->ball(pVision->getCycle()-4);
if (pVision->ball().Valid()&&isPointOutField(pVision->ball().Pos())){
_isBallOutField=true;
}
Expand Down
4 changes: 2 additions & 2 deletions Core/src/Algorithm/ContactChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class ContactChecker {
std::vector<PlayerVisionT> AllPlayer;
Last_Contact _last_contact;

MobileVisionT _ball;
MobileVisionT _lastball;
ObjectPoseT _ball;
ObjectPoseT _lastball;
CVector ball_direction_before;
CVector ball_direction_after;
double speed_before ;
Expand Down
2 changes: 1 addition & 1 deletion Core/src/LuaModule/ballspeedmodel.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ class CBallSpeedModel
{
double timeForDist(const double dist);
CVector speedForDist(const double dist);
MobileVisionT poseForTime(const double time);
ObjectPoseT poseForTime(const double time);
};
4 changes: 2 additions & 2 deletions Core/src/LuaModule/visionmodule.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class CVisionModule{
const PlayerVisionT& allPlayer(int num) const;
const PlayerVisionT& ourPlayer(int num) const;
const PlayerVisionT& theirPlayer(int num) const;
const MobileVisionT& ball() const;
const ObjectPoseT& ball() const;
const PlayerVisionT& ourPlayer(int cycle, int num) const;
const PlayerVisionT& theirPlayer(int cycle, int num) const;
const MobileVisionT& ball(int cycle) const;
const ObjectPoseT& ball(int cycle) const;
const ObjectPoseT& rawBall() const;
const CGeoPoint& getBallPlacementPosition() const;
const RobotRawVisionData& ourRawPlayer(int num) const;
Expand Down
15 changes: 4 additions & 11 deletions Core/src/LuaModule/worlddefine.pkg
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@ class ObjectPoseT{
double VelY() const;
void SetValid(bool v);
bool Valid() const;
};

class VisionObjectT{
const CGeoPoint& RawPos() const;
void SetRawPos(double x, double y);
void SetRawPos(const CGeoPoint& pos);
};

class MobileVisionT : public ObjectPoseT, public VisionObjectT{

};

struct PlayerPoseT : public ObjectPoseT{
PlayerPoseT();
double Dir() const;
Expand All @@ -39,12 +32,12 @@ struct PlayerPoseT : public ObjectPoseT{
};

class PlayerTypeT{
void SetType(int t);
int Type() const;
};

class PlayerVisionT : public PlayerPoseT, public VisionObjectT, public PlayerTypeT{
};

class PlayerVisionT : public PlayerPoseT {
void SetType(int t);
int Type() const;
};

struct PlayerCapabilityT{
Expand Down
2 changes: 1 addition & 1 deletion Core/src/MotionControl/DynamicsSafetySearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ bool CDynamicSafetySearch::CheckAccel (const int player, vector2f acc, const CVi
if(pVision->ball().Valid() && (_flag & PlayerStatus::DODGE_BALL)) {
vector2f pj = vector2f(pVision->ball().Pos().x(), pVision->ball().Pos().y());
vector2f vj = vector2f(pVision->ball().VelX(), pVision->ball().VelY());
const MobileVisionT& last_ball = pVision->ball(pVision->getLastCycle());
const ObjectPoseT& last_ball = pVision->ball(pVision->getLastCycle());
vector2f Aj;
Aj = (vj - vector2f(last_ball.VelX(), last_ball.VelY())) /_C;
if(CheckRobot(player, _pos, _vel, acc, -1, pj, vj, Aj, type, limitTime) == UNSAFE) {
Expand Down
4 changes: 2 additions & 2 deletions Core/src/OtherLibs/cmu/obstacle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,12 @@ void obstacles::addObs(const CVisionModule *pVision, const TaskT &task, bool dra

// ball
if(flags & PlayerStatus::DODGE_BALL) {
const MobileVisionT& ball = pVision->ball();
const ObjectPoseT& ball = pVision->ball();
add_circle(vector2f(ball.Pos().x(), ball.Pos().y()), vector2f(ball.Vel().x(), ball.Vel().y()), ballAvoidDist, 1, drawObs);
}

if(WorldModel::Instance()->CurrentRefereeMsg() == "GameStop") {
const MobileVisionT& ball = pVision->ball();
const ObjectPoseT& ball = pVision->ball();
add_circle(vector2f(ball.Pos().x(), ball.Pos().y()), vector2f(0.0f, 0.0f), 50.0f, 1, drawObs);
}

Expand Down
4 changes: 2 additions & 2 deletions Core/src/PathPlan/ObstacleNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,13 @@ void ObstaclesNew::addObs(const CVisionModule * pVision, const TaskT & task, boo

// ball
if (flags & PlayerStatus::DODGE_BALL) {
const MobileVisionT& ball = pVision->ball();
const ObjectPoseT& ball = pVision->ball();
addCircle(ball.RawPos(), ball.Vel(), ballAvoidDist, OBS_CIRCLE_NEW);
}

if (WorldModel::Instance()->CurrentRefereeMsg() == "GameStop" ||
(flags & PlayerStatus::AVOID_STOP_BALL_CIRCLE)) {
const MobileVisionT& ball = pVision->ball();
const ObjectPoseT& ball = pVision->ball();
addCircle(ball.RawPos(), CVector(0.0f, 0.0f), stopBallAvoidDist, OBS_CIRCLE_NEW);
}

Expand Down
4 changes: 2 additions & 2 deletions Core/src/Vision/BallPredictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ bool CBallPredictor::checkValid(int cycle) {
return true;
}

void CBallPredictor::setCollisionResult(int cycle, const MobileVisionT& ball) {
MobileVisionT& oldBall = _visionLogger.getVision(cycle);
void CBallPredictor::setCollisionResult(int cycle, const ObjectPoseT& ball) {
ObjectPoseT& oldBall = _visionLogger.getVision(cycle);
oldBall = ball;
_hasCollision = true;

Expand Down
8 changes: 4 additions & 4 deletions Core/src/Vision/BallPredictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const double MAX_DIST = 1000.0 / PARAM::Vision::FRAME_RATE * 4;
const int MAX_LOGS = 16;
}

class BallVisionData : public MobileVisionT {
class BallVisionData : public ObjectPoseT {
public:
BallVisionData(): cycle(-1) {}
int cycle;
Expand Down Expand Up @@ -64,10 +64,10 @@ class CBallPredictor {
BallVisionData& getData(int cycle) {
return _visionLogger.getVision(cycle);
}
const MobileVisionT& getResult(int cycle) const {
const ObjectPoseT& getResult(int cycle) const {
return _visionLogger.getVision(cycle);
}
void setCollisionResult(int cycle, const MobileVisionT& ball);
void setCollisionResult(int cycle, const ObjectPoseT& ball);
int visibility() const {
return _visibility;
}
Expand All @@ -91,7 +91,7 @@ class CBallPredictor {
bool checkValid(int cycle); // 去掉不合理的情况
private:
CBallVisionLogger _visionLogger;
MobileVisionT _ballLinePredictData[60];
ObjectPoseT _ballLinePredictData[60];
int _ballLostTime; // 看不到球的次数
int _ballInvalidMovedCycle; // 球的信息不合理的周期数
int _visibility, _activity; // 可见度和活动度
Expand Down
4 changes: 2 additions & 2 deletions Core/src/Vision/CollisionSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class CCollisionSimulator{
CCollisionSimulator() : _hasCollision(false){ }
void reset(const CGeoPoint& ballRawPos, const CVector& ballVel);
void simulate(PlayerVisionT robot, const double time); // 模拟一定时间
const MobileVisionT& ball() const { return _ball; }
const ObjectPoseT& ball() const { return _ball; }
bool hasCollision() const { return _hasCollision; }
private:
MobileVisionT _ball; // 球的信息
ObjectPoseT _ball; // 球的信息
CVector _ballRelToRobot; // 球在机器人局部坐标系中的位置
bool _hasCollision; // 是否碰撞
};
Expand Down
8 changes: 4 additions & 4 deletions Core/src/Vision/RobotPredictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CRobotPredictor::CRobotPredictor(bool isHasRotation) : _robotLostTime(0), _isHas
// _robotFilter.initialize(PARAM::File::RobotPosFilterDir + "slowMatrices.txt", PARAM::File::RobotPosFilterDir + "fastMatrices.txt");
// }
}
void CRobotPredictor::updateVision(int cycle, const VehicleInfoT& player, const MobileVisionT& ball, bool invert) {
void CRobotPredictor::updateVision(int cycle, const VehicleInfoT& player, const ObjectPoseT& ball, bool invert) {
// !!!!这里好像有问题:
// 如果是对手车也能识别朝向,就会调用updateOurVision, 但因为在该函数里取不到cmd(只有我方车才有cmd存下来), 结果就不对.
// 这里需要一个辨别我方车与对方车的方式!!
Expand Down Expand Up @@ -95,7 +95,7 @@ void CRobotPredictor::updateVision(int cycle, const VehicleInfoT& player, const
}
}

//void CRobotPredictor::updateOurVision(int cycle, const VehicleInfoT& player, const MobileVisionT& ball, bool invert, int realNum) {
//void CRobotPredictor::updateOurVision(int cycle, const VehicleInfoT& player, const ObjectPoseT& ball, bool invert, int realNum) {
// const double x = invert ? -player.pos.x : player.pos.x;
// const double y = invert ? -player.pos.y : player.pos.y;
// double dir = 0;
Expand Down Expand Up @@ -279,7 +279,7 @@ void CRobotPredictor::updateVision(int cycle, const VehicleInfoT& player, const
// predictedVision.SetType(player.type);
//}

//void CRobotPredictor::updateTheirVision(int cycle, const VehicleInfoT & player, const MobileVisionT & ball, bool invert, int realNum) {
//void CRobotPredictor::updateTheirVision(int cycle, const VehicleInfoT & player, const ObjectPoseT & ball, bool invert, int realNum) {
// const double x = invert ? -player.pos.x : player.pos.x;
// const double y = invert ? -player.pos.y : player.pos.y;
// double dir = 0;
Expand Down Expand Up @@ -435,7 +435,7 @@ bool CRobotPredictor::checkValid(int cycle, const CGeoPoint & pos) {
}
return true;
}
void CRobotPredictor::predictLost(int cycle, const MobileVisionT & ball) {
void CRobotPredictor::predictLost(int cycle, const ObjectPoseT & ball) {
//cout<<cycle<<" ";
// 图像当前帧丢车后的处理办法
if( _visionLogger.visionValid(cycle - 1)) {
Expand Down
10 changes: 5 additions & 5 deletions Core/src/Vision/RobotPredictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class CRobotPredictor {
CRobotPredictor();
CRobotPredictor (bool isHasRotaion);
void updateCommand(int cycle, const CPlayerCommand* cmd); // 更新命令
void updateVision(int cycle, const VehicleInfoT& player, const MobileVisionT& ball, bool invert); // 更新视觉信息
void updateOurVision(int cycle, const VehicleInfoT& player, const MobileVisionT& ball, bool invert, int realNum); // 更新视觉信息
void updateTheirVision(int cycle, const VehicleInfoT& player, const MobileVisionT& ball, bool invert, int realNum); // 更新视觉信息
void updateVision(int cycle, const VehicleInfoT& player, const ObjectPoseT& ball, bool invert); // 更新视觉信息
void updateOurVision(int cycle, const VehicleInfoT& player, const ObjectPoseT& ball, bool invert, int realNum); // 更新视觉信息
void updateTheirVision(int cycle, const VehicleInfoT& player, const ObjectPoseT& ball, bool invert, int realNum); // 更新视觉信息

CRobotCommandLogger& getCommandLogger() {
return _commandLogger;
Expand All @@ -50,7 +50,7 @@ class CRobotPredictor {
bool collideWithBall() const {
return _collisionSimulator.hasCollision(); // 只是单纯地考虑是否相撞与碰撞区域
}
const MobileVisionT& ballCollidedResult() const {
const ObjectPoseT& ballCollidedResult() const {
return _collisionSimulator.ball();
}
void setIsHasRotation(bool isHasRot) {
Expand All @@ -59,7 +59,7 @@ class CRobotPredictor {
protected:
// void updateRawVision(int cycle, double x, double y, double dir, bool seen);
bool checkValid(int cycle, const CGeoPoint& pos);
void predictLost(int cycle, const MobileVisionT& ball); // 预测看不到的信息
void predictLost(int cycle, const ObjectPoseT& ball); // 预测看不到的信息
private:
// FilteredObject _robotFilter; // KalmanFilter
// FilteredObject _robotRotationFilter; // 进行robot朝向滤波
Expand Down
2 changes: 1 addition & 1 deletion Core/src/Vision/VisionModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void CVisionModule::setNewVision() {
/// @brief Step 2: 进行我方和对方机器人位置预测,关注滤波器
/////////////////////////////////////////////////////////////////////////////
//【#TODO】机器人碰撞检测器清空,
const MobileVisionT& thisBall = _ballPredictor.getData(_timeCycle);
const ObjectPoseT& thisBall = _ballPredictor.getData(_timeCycle);
// 确定球员的信息是否需要反向,确保正确更新比赛双方球员的信息
for (int i = 0; i < PARAM::Field::MAX_PLAYER; ++ i) {
const VehicleInfoT& ourPlayer = _info.player[0][i];
Expand Down
4 changes: 2 additions & 2 deletions Core/src/Vision/VisionModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CVisionModule{
}
}

const MobileVisionT& ball() const {
const ObjectPoseT& ball() const {
return _ballPredictor.getResult(_timeCycle);
}

Expand All @@ -94,7 +94,7 @@ class CVisionModule{
return _theirPlayerPredictor[num].getResult(cycle);
}

const MobileVisionT& ball(int cycle) const {
const ObjectPoseT& ball(int cycle) const {
return _ballPredictor.getResult(cycle);
}

Expand Down
41 changes: 13 additions & 28 deletions Core/src/WorldModel/WorldDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/************************************************************************/
class ObjectPoseT {
public:
ObjectPoseT() : _valid(false), _pos(CGeoPoint(-9999, -9999)) { }
ObjectPoseT() : _valid(false), _pos(CGeoPoint(-9999, -9999)), _rawPos(CGeoPoint(-9999, -9999)) { }
const CGeoPoint& Pos() const {
return _pos;
}
Expand Down Expand Up @@ -67,19 +67,7 @@ class ObjectPoseT {
bool Valid() const {
return _valid;
}
private:
CGeoPoint _pos;
CVector _vel;
CVector _rawVel;
CVector _acc;
bool _valid;
};
/************************************************************************/
/* VisionObjectT */
/************************************************************************/
class VisionObjectT {
public:
VisionObjectT() : _rawPos(CGeoPoint(-9999, -9999)) { }

const CGeoPoint& RawPos() const {
return _rawPos;
}
Expand All @@ -105,16 +93,19 @@ class VisionObjectT {
_rawDir = rawdir;
}
private:
CGeoPoint _pos;
CVector _vel;
CVector _rawVel;
CVector _acc;
bool _valid;

CGeoPoint _rawPos; // 视觉的原始信息,没有经过预测
CGeoPoint _chipPredict; //挑球预测
double _rawDir;
};
/************************************************************************/
/* MobileVisionT */
/************************************************************************/
class MobileVisionT : public ObjectPoseT, public VisionObjectT {

};
// using ObjectPoseT = ObjectPoseT;

/************************************************************************/
/* 机器人姿态数据结构 */
/************************************************************************/
Expand Down Expand Up @@ -145,11 +136,11 @@ struct PlayerPoseT : public ObjectPoseT { // 目标信息
double _rawRotVel;
};
/************************************************************************/
/* PlayerTypeT */
/* PlayerVisionT */
/************************************************************************/
class PlayerTypeT {
class PlayerVisionT : public PlayerPoseT {
public:
PlayerTypeT(): _type(0) {}
PlayerVisionT() : _type(0) {}
void SetType(int t) {
_type = t;
}
Expand All @@ -159,12 +150,6 @@ class PlayerTypeT {
private:
int _type;
};
/************************************************************************/
/* PlayerVisionT */
/************************************************************************/
class PlayerVisionT : public PlayerPoseT, public VisionObjectT, public PlayerTypeT {

};

/************************************************************************/
/* 机器人能力数据结构 */
Expand Down
2 changes: 1 addition & 1 deletion Core/src/WorldModel/WorldModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CWorldModel{
const COptionModule* _pOption;
PlayerVisionT me;
PlayerVisionT he;
MobileVisionT ball;
ObjectPoseT ball;


/************************************************** WorldModel_con ***************************************************/
Expand Down
4 changes: 4 additions & 0 deletions Core/tactics/play/TestGetBall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ return {
switch = function()
local dist = (ball.pos() - player.pos("Assister")):mod()
debugEngine:gui_debug_msg(ball.pos()+Utils.Polar2Vector(300,math.pi/2),"Dist : " .. dist)
debugEngine:gui_debug_x(player.pos("Assister"), param.GREEN)
debugEngine:gui_debug_msg(player.pos("Assister"), "Pos", param.GREEN)
debugEngine:gui_debug_x(player.rawPos("Assister"), param.PURPLE)
debugEngine:gui_debug_msg(player.rawPos("Assister"), "RawPos", param.PURPLE)
end,
Assister = task.touchKick(CGeoPoint(6000,0),nil,6000,true),
-- Assister = task.stop(),
Expand Down
Loading

0 comments on commit bac2ea9

Please sign in to comment.