Skip to content

Commit

Permalink
Optimize the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
GuraMumei committed Oct 22, 2023
1 parent ec229c2 commit c0d7a72
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 68 deletions.
1 change: 0 additions & 1 deletion rm_referee/include/rm_referee/referee_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "rm_referee/ui/time_change_ui.h"
#include "rm_referee/ui/flash_ui.h"


namespace rm_referee
{
class RefereeBase
Expand Down
6 changes: 4 additions & 2 deletions rm_referee/include/rm_referee/ui/flash_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class FlashUi : public UiBase
class CoverFlashUi : public FlashUi
{
public:
explicit CoverFlashUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit CoverFlashUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: FlashUi(rpc_value, base, "cover", graph_queue, character_queue){};
void updateManualCmdData(const rm_msgs::ManualToReferee::ConstPtr data, const ros::Time& last_get_data_time) override;

Expand All @@ -38,7 +39,8 @@ class CoverFlashUi : public FlashUi
class SpinFlashUi : public FlashUi
{
public:
explicit SpinFlashUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit SpinFlashUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: FlashUi(rpc_value, base, "spin", graph_queue, character_queue){};
void updateChassisCmdData(const rm_msgs::ChassisCmd::ConstPtr data, const ros::Time& last_get_data_time);

Expand Down
34 changes: 21 additions & 13 deletions rm_referee/include/rm_referee/ui/time_change_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TimeChangeUi : public UiBase
{
public:
explicit TimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, const std::string& graph_name,
std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
std::deque<Graph>* graph_queue, std::deque<Graph>* character_queue)
: UiBase(rpc_value, base, graph_queue, character_queue)
{
graph_ = new Graph(rpc_value["config"], base_, id_++);
Expand All @@ -26,7 +26,7 @@ class TimeChangeGroupUi : public GroupUiBase
{
public:
explicit TimeChangeGroupUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, const std::string& graph_name,
std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
std::deque<Graph>* graph_queue, std::deque<Graph>* character_queue)
: GroupUiBase(rpc_value, base, graph_queue, character_queue)
{
graph_name_ = graph_name;
Expand All @@ -42,7 +42,8 @@ class TimeChangeGroupUi : public GroupUiBase
class CapacitorTimeChangeUi : public TimeChangeUi
{
public:
explicit CapacitorTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit CapacitorTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TimeChangeUi(rpc_value, base, "capacitor", graph_queue, character_queue){};
void add() override;
void updateRemainCharge(const double remain_charge, const ros::Time& time);
Expand All @@ -55,7 +56,8 @@ class CapacitorTimeChangeUi : public TimeChangeUi
class EffortTimeChangeUi : public TimeChangeUi
{
public:
explicit EffortTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit EffortTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TimeChangeUi(rpc_value, base, "effort", graph_queue, character_queue){};
void updateJointStateData(const sensor_msgs::JointState::ConstPtr data, const ros::Time& time);

Expand All @@ -68,7 +70,8 @@ class EffortTimeChangeUi : public TimeChangeUi
class ProgressTimeChangeUi : public TimeChangeUi
{
public:
explicit ProgressTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit ProgressTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TimeChangeUi(rpc_value, base, "progress", graph_queue, character_queue){};
void updateEngineerUiData(const rm_msgs::EngineerUi::ConstPtr data, const ros::Time& last_get_data_time);

Expand All @@ -81,7 +84,8 @@ class ProgressTimeChangeUi : public TimeChangeUi
class DartStatusTimeChangeUi : public TimeChangeUi
{
public:
explicit DartStatusTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit DartStatusTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TimeChangeUi(rpc_value, base, "dart", graph_queue, character_queue){};
void updateDartClientCmd(const rm_msgs::DartClientCmd::ConstPtr data, const ros::Time& last_get_data_time);

Expand All @@ -93,7 +97,8 @@ class DartStatusTimeChangeUi : public TimeChangeUi
class RotationTimeChangeUi : public TimeChangeUi
{
public:
explicit RotationTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit RotationTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TimeChangeUi(rpc_value, base, "rotation", graph_queue, character_queue)
{
if (rpc_value.hasMember("data"))
Expand Down Expand Up @@ -125,7 +130,8 @@ class RotationTimeChangeUi : public TimeChangeUi
class LaneLineTimeChangeGroupUi : public TimeChangeGroupUi
{
public:
explicit LaneLineTimeChangeGroupUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit LaneLineTimeChangeGroupUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TimeChangeGroupUi(rpc_value, base, "lane_line", graph_queue, character_queue)
{
if (rpc_value.hasMember("data"))
Expand Down Expand Up @@ -171,7 +177,8 @@ class LaneLineTimeChangeGroupUi : public TimeChangeGroupUi
class BalancePitchTimeChangeGroupUi : public TimeChangeGroupUi
{
public:
explicit BalancePitchTimeChangeGroupUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit BalancePitchTimeChangeGroupUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TimeChangeGroupUi(rpc_value, base, "balance_pitch", graph_queue, character_queue)
{
XmlRpc::XmlRpcValue config;
Expand Down Expand Up @@ -232,7 +239,8 @@ class BalancePitchTimeChangeGroupUi : public TimeChangeGroupUi
class PitchAngleTimeChangeUi : public TimeChangeUi
{
public:
explicit PitchAngleTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit PitchAngleTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TimeChangeUi(rpc_value, base, "pitch", graph_queue, character_queue){};
void updateJointStateData(const sensor_msgs::JointState::ConstPtr data, const ros::Time& time);

Expand All @@ -244,9 +252,9 @@ class PitchAngleTimeChangeUi : public TimeChangeUi
class JointPositionTimeChangeUi : public TimeChangeUi
{
public:
explicit JointPositionTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue, std::deque<Graph>* character_queue,
std::string name)
: TimeChangeUi(rpc_value, base, name, graph_queue,character_queue)
explicit JointPositionTimeChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue, std::string name)
: TimeChangeUi(rpc_value, base, name, graph_queue, character_queue)
{
if (rpc_value.hasMember("data"))
{
Expand Down
26 changes: 17 additions & 9 deletions rm_referee/include/rm_referee/ui/trigger_change_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TriggerChangeGroupUi : public GroupUiBase
{
public:
explicit TriggerChangeGroupUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, const std::string& graph_name,
std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
std::deque<Graph>* graph_queue, std::deque<Graph>* character_queue)
: GroupUiBase(rpc_value, base, graph_queue, character_queue)
{
graph_name_ = graph_name;
Expand All @@ -48,7 +48,8 @@ class TriggerChangeGroupUi : public GroupUiBase
class ChassisTriggerChangeUi : public TriggerChangeUi
{
public:
explicit ChassisTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit ChassisTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TriggerChangeUi(rpc_value, base, "chassis", graph_queue, character_queue)
{
if (base.robot_id_ == rm_referee::RobotId::RED_ENGINEER || base.robot_id_ == rm_referee::RobotId::BLUE_ENGINEER)
Expand Down Expand Up @@ -79,7 +80,8 @@ class ChassisTriggerChangeUi : public TriggerChangeUi
class ShooterTriggerChangeUi : public TriggerChangeUi
{
public:
explicit ShooterTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit ShooterTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TriggerChangeUi(rpc_value, base, "shooter", graph_queue, character_queue)
{
graph_->setContent("0");
Expand All @@ -97,7 +99,8 @@ class ShooterTriggerChangeUi : public TriggerChangeUi
class GimbalTriggerChangeUi : public TriggerChangeUi
{
public:
explicit GimbalTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit GimbalTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TriggerChangeUi(rpc_value, base, "gimbal", graph_queue, character_queue)
{
graph_->setContent("0");
Expand All @@ -115,7 +118,8 @@ class GimbalTriggerChangeUi : public TriggerChangeUi
class TargetTriggerChangeUi : public TriggerChangeUi
{
public:
explicit TargetTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit TargetTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TriggerChangeUi(rpc_value, base, "target", graph_queue, character_queue)
{
graph_->setContent("armor");
Expand All @@ -137,7 +141,8 @@ class TargetTriggerChangeUi : public TriggerChangeUi
class TargetViewAngleTriggerChangeUi : public TriggerChangeUi
{
public:
explicit TargetViewAngleTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit TargetViewAngleTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TriggerChangeUi(rpc_value, base, "target_scale", graph_queue, character_queue)
{
}
Expand All @@ -152,7 +157,8 @@ class TargetViewAngleTriggerChangeUi : public TriggerChangeUi
class PolygonTriggerChangeGroupUi : public TriggerChangeGroupUi
{
public:
explicit PolygonTriggerChangeGroupUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit PolygonTriggerChangeGroupUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TriggerChangeGroupUi(rpc_value, base, "Polygon", graph_queue, character_queue)
{
ROS_ASSERT(rpc_value.hasMember("points"));
Expand Down Expand Up @@ -193,13 +199,15 @@ class PolygonTriggerChangeGroupUi : public TriggerChangeGroupUi
}
}
void update() override;
//virtual void updateConfig(uint8_t main_mode, bool main_flag, uint8_t sub_mode = 0, bool sub_flag = false){} void setContent(const std::string &content) override;
// virtual void updateConfig(uint8_t main_mode, bool main_flag, uint8_t sub_mode = 0, bool sub_flag = false){} void
// setContent(const std::string &content) override;
};

class CameraTriggerChangeUi : public TriggerChangeUi
{
public:
explicit CameraTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue, std::deque<Graph> * character_queue)
explicit CameraTriggerChangeUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue,
std::deque<Graph>* character_queue)
: TriggerChangeUi(rpc_value, base, "camera", graph_queue, character_queue)
{
if (rpc_value.hasMember("camera_name"))
Expand Down
11 changes: 7 additions & 4 deletions rm_referee/include/rm_referee/ui/ui_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace rm_referee
class UiBase
{
public:
explicit UiBase(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue = nullptr, std::deque<Graph>* character_queue = nullptr )
explicit UiBase(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue = nullptr,
std::deque<Graph>* character_queue = nullptr)
: base_(base), tf_listener_(tf_buffer_)
{
if (rpc_value.hasMember("config"))
Expand Down Expand Up @@ -73,7 +74,8 @@ class UiBase
class GroupUiBase : public UiBase
{
public:
explicit GroupUiBase(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph> * graph_queue = nullptr, std::deque<Graph> * character_queue = nullptr)
explicit GroupUiBase(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue = nullptr,
std::deque<Graph>* character_queue = nullptr)
: UiBase(rpc_value, base, graph_queue, character_queue){};
~GroupUiBase() = default;
void add() override;
Expand All @@ -98,10 +100,11 @@ class GroupUiBase : public UiBase
class FixedUi : public GroupUiBase
{
public:
explicit FixedUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue = nullptr, std::deque<Graph>* character_queue = nullptr)
explicit FixedUi(XmlRpc::XmlRpcValue& rpc_value, Base& base, std::deque<Graph>* graph_queue = nullptr,
std::deque<Graph>* character_queue = nullptr)
: GroupUiBase(rpc_value, base, graph_queue, character_queue)
{
for(int i = 0; i < static_cast<int>(rpc_value.size()); i++)
for (int i = 0; i < static_cast<int>(rpc_value.size()); i++)
graph_vector_.insert(
std::pair<std::string, Graph*>(rpc_value[i]["name"], new Graph(rpc_value[i]["config"], base_, id_++)));
};
Expand Down
Loading

0 comments on commit c0d7a72

Please sign in to comment.