Skip to content

Commit

Permalink
[Core] add direct_kick_no_calibration in command
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-tz committed Apr 14, 2024
1 parent 39eadcf commit d03de8f
Show file tree
Hide file tree
Showing 10 changed files with 490 additions and 465 deletions.
5 changes: 5 additions & 0 deletions Client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ else()
find_package(ZLIB)
endif()

## fmt
find_package(fmt REQUIRED)
include_directories(${fmt_INCLUDE_DIRS})
list(APPEND libs fmt::fmt)

include_directories(${ZLIB_INCLUDE_DIRS})
list(APPEND libs ${ZLIB_LIBRARIES})
## find Qt
Expand Down
741 changes: 386 additions & 355 deletions Client/src/actionmodule.cpp

Large diffs are not rendered by default.

142 changes: 71 additions & 71 deletions Client/src/actionmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,77 +13,77 @@ enum struct ProtocolType{
UDP_24L01,
Serial_24L01,
};
class Action_Serial24L01 : public QObject {
Q_OBJECT
public:
struct Config{
QString portName;
};
Action_Serial24L01(const Config& config,const __callback_type& f={},QObject *parent=nullptr);
~Action_Serial24L01();
bool start();
bool stop();
void reConfig(const Config& config);
bool sendConfigPacket(const char*,const size_t);
bool send(const char*,const size_t);
private slots:
void receiveData();
private:
Config _config;
QSerialPort serial;
const __callback_type _cb;
};
class Action_UDP24L01 : public QObject {
Q_OBJECT
public:
struct Config{
QString send_ip;
int send_port;
QString recv_ip;
int recv_port;
};
Action_UDP24L01(const Config& config,const __callback_type& f={},QObject *parent=nullptr);
~Action_UDP24L01();
bool start();
bool stop();
void reConfig(const Config& config);
bool sendConfigPacket(const char*,const size_t);
bool send(const char*,const size_t);
private slots:
void receiveData();
private:
Config _config;
QUdpSocket _sendSocket;
QUdpSocket _recvSocket;
const __callback_type _cb;
};
class ActionModule : public QObject {
Q_OBJECT
public:
ActionModule(QObject *parent = 0);
~ActionModule();
void sendLegacy(int t, const ZSS::Protocol::Robots_Command&);
bool connectRadio(int, int);
bool disconnectRadio(int);
void setSimulation(bool);
int team[PARAM::TEAMS];
void changeAddress(int team,int index);
QStringList getAllAddress();
QString getRealAddress(int team);
private slots:
void readData();
private:
void sendStartPacket(int, int);
private:
QByteArray tx;
QByteArray rx;
QUdpSocket sendSocket;
QUdpSocket receiveSocket;
ProtocolType _protocolType[PARAM::ROBOTNUM];
signals:
void receiveRobotInfo(int, int);
};
typedef Singleton<ActionModule> ZActionModule;
// class Action_Serial24L01 : public QObject {
// Q_OBJECT
// public:
// struct Config{
// QString portName;
// };
// Action_Serial24L01(const Config& config,const __callback_type& f={},QObject *parent=nullptr);
// ~Action_Serial24L01();
// bool start();
// bool stop();
// void reConfig(const Config& config);
// bool sendConfigPacket(const char*,const size_t);
// bool send(const char*,const size_t);
// private slots:
// void receiveData();
// private:
// Config _config;
// QSerialPort serial;
// const __callback_type _cb;
// };
// class Action_UDP24L01 : public QObject {
// Q_OBJECT
// public:
// struct Config{
// QString send_ip;
// int send_port;
// QString recv_ip;
// int recv_port;
// };
// Action_UDP24L01(const Config& config,const __callback_type& f={},QObject *parent=nullptr);
// ~Action_UDP24L01();
// bool start();
// bool stop();
// void reConfig(const Config& config);
// bool sendConfigPacket(const char*,const size_t);
// bool send(const char*,const size_t);
// private slots:
// void receiveData();
// private:
// Config _config;
// QUdpSocket _sendSocket;
// QUdpSocket _recvSocket;
// const __callback_type _cb;
// };
// class ActionModule : public QObject {
// Q_OBJECT
// public:
// ActionModule(QObject *parent = 0);
// ~ActionModule();
// void sendLegacy(int t, const ZSS::Protocol::Robots_Command&);
// bool connectRadio(int, int);
// bool disconnectRadio(int);
// void setSimulation(bool);
// int team[PARAM::TEAMS];
// void changeAddress(int team,int index);
// QStringList getAllAddress();
// QString getRealAddress(int team);
// private slots:
// void readData();
// private:
// void sendStartPacket(int, int);
// private:
// QByteArray tx;
// QByteArray rx;
// QUdpSocket sendSocket;
// QUdpSocket receiveSocket;
// ProtocolType _protocolType[PARAM::ROBOTNUM];
// signals:
// void receiveRobotInfo(int, int);
// };
// typedef Singleton<ActionModule> ZActionModule;

class ActionModuleSerialVersion : public QObject
{
Expand Down
20 changes: 0 additions & 20 deletions Client/src/actionmodule_nan.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion Client/src/communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void Communicator::receiveCommand(int t) {
ZSS::ZRemoteSimModule::instance()->sendSim(t, commands);
} else {
// qDebug() << "realreal!";
ZSS::ZActionModule::instance()->sendLegacy(t, commands);
// ZSS::ZActionModule::instance()->sendLegacy(t, commands);
ZSS::NActionModule::instance()->sendLegacy(commands);
}
}
Expand Down
13 changes: 7 additions & 6 deletions Client/src/interaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void Interaction::showIfEdgeTest() {
std::cout << VisionModule::instance()->showIfEdgeTest() << std::endl;
}
void Interaction::setVision(bool needStart, bool real) {
ZSS::ZActionModule::instance()->setSimulation(!real);
// ZSS::ZActionModule::instance()->setSimulation(!real);
if (needStart) {
ZSS::ZParamManager::instance()->changeParam("Alert/IsSimulation", !real);
ZCommunicator::instance()->reloadSimulation();
Expand All @@ -116,11 +116,12 @@ bool Interaction::connectRadio(bool sw, int id, int frq) {
if(sw) {
ZCommunicator::instance()->disconnectMedusa(id);
ZCommunicator::instance()->connectMedusa(id);
ZSS::ZActionModule::instance()->disconnectRadio(id);
return ZSS::ZActionModule::instance()->connectRadio(id, frq);
// ZSS::ZActionModule::instance()->disconnectRadio(id);
// return ZSS::ZActionModule::instance()->connectRadio(id, frq);
} else {
// return ZSS::ZActionModule::instance()->disconnectRadio(id);
}
return false;
}
bool Interaction::connectSim(bool sw, int id, bool color) {
if(sw) {
Expand Down Expand Up @@ -383,13 +384,13 @@ int Interaction::getFrequency(){
return ZSS::NActionModule::instance()->getFrequency();
}
void Interaction::changeAddress(int team, int index){
ZSS::ZActionModule::instance()->changeAddress(team,index);
// ZSS::ZActionModule::instance()->changeAddress(team,index);
}
QStringList Interaction::getAllAddress(){
return ZSS::ZActionModule::instance()->getAllAddress();
// return ZSS::ZActionModule::instance()->getAllAddress();
}
QString Interaction::getRealAddress(int index){
return ZSS::ZActionModule::instance()->getRealAddress(index);
// return ZSS::ZActionModule::instance()->getRealAddress(index);
};

void Interaction::updateTestScriptList(){
Expand Down
2 changes: 1 addition & 1 deletion Client/src/viewerinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public slots:
}
public:
explicit ViewerInterface(QObject *parent = Q_NULLPTR){
QObject::connect(ZSS::ZActionModule::instance(),SIGNAL(receiveRobotInfo(int,int)),this,SLOT(changeRobotInfo(int,int)));
// QObject::connect(ZSS::ZActionModule::instance(),SIGNAL(receiveRobotInfo(int,int)),this,SLOT(changeRobotInfo(int,int)));
QObject::connect(ZSS::ZSimModule::instance(),SIGNAL(receiveSimInfo(int,int)),this,SLOT(changeRobotInfo(int,int)));
}
enum Roles {
Expand Down
4 changes: 3 additions & 1 deletion Core/src/Simulator/CommandInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ void CCommandInterface::setSpeed(int num, double dribble, double vx, double vy,
commands[number].velocity_r = vr;

}
void CCommandInterface::setKick(int num, double kp, double cp) {
void CCommandInterface::setKick(int num, double kp, double cp, bool direct_kick_no_calibration, double direct_kick_power) {
int number = num;
if (number < 0 || number > PARAM::Field::MAX_PLAYER - 1) {
//std::cout << "Robot Number Error in Simulator setKick" << std::endl;
return;
}
commands[number].flat_kick = kp;
commands[number].chip_kick = cp;
commands[number].direct_kick_no_calibration = direct_kick_no_calibration;
commands[number].direct_kick_power = direct_kick_power;
}

void CCommandInterface::setNeedReport(int num, bool needReport){
Expand Down
22 changes: 12 additions & 10 deletions Core/src/Simulator/CommandInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
class QUdpSocket;

struct RobotCommand{
double velocity_x;
double velocity_y;
double velocity_r;
double flat_kick;
double chip_kick;
double dribble_spin;
bool use_dir;
bool need_report;
RobotCommand():velocity_x(0),velocity_y(0),velocity_r(0),flat_kick(0),chip_kick(0),dribble_spin(0),use_dir(false),need_report(false) {}
double velocity_x = 0;
double velocity_y = 0;
double velocity_r = 0;
double flat_kick = 0;
double chip_kick = 0;
double dribble_spin = 0;
bool use_dir = false;
bool need_report = false;
bool direct_kick_no_calibration=false;
double direct_kick_power=0;
RobotCommand() = default;
};

class CCommandInterface : public QObject
Expand All @@ -36,7 +38,7 @@ class CCommandInterface : public QObject
static CCommandInterface* instance(const COptionModule *pOption=nullptr);
static void destruct();
void setSpeed(int num, double dribble, double vx, double vy, double vr);
void setKick(int num, double kp, double cp);
void setKick(int num, double kp, double cp, bool direct_kick_no_calibration=false, double direct_kick_power=0);
void setNeedReport(int num, bool needReport);
void sendCommands();
private slots:
Expand Down
4 changes: 4 additions & 0 deletions share/proto/zss_cmd.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ message Robot_Command {

required bool use_dir = 10;
required bool need_report = 11;

// use for power calibration
optional bool direct_kick_no_calibration = 12;
optional float direct_kick_power = 13;
}

0 comments on commit d03de8f

Please sign in to comment.