Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: updated bunker robot interface #66

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions include/ugv_sdk/details/interface/bunker_interface.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/*
* bunker_interface.hpp
*
* Created on: Jul 14, 2021 23:04
* Description:
*
* Copyright (c) 2021 Ruixiang Du (rdu)
/**
* @file bunker_interface.hpp
* @brief Bunker robot common interface
* @date 06-01-2025
*
* @copyright Copyright (c) 2025 Weston Robot Pte. Ltd.
*/

#ifndef BUNKER_INTERFACE_HPP
#define BUNKER_INTERFACE_HPP

Expand Down Expand Up @@ -34,6 +32,12 @@ struct BunkerActuatorState {
ActuatorStateMessageV1 actuator_state[2];
};

struct BunkerCommonSensorState {
SdkTimePoint time_stamp;

BmsBasicMessage bms_basic_state;
};

struct BunkerInterface {
virtual ~BunkerInterface() = default;

Expand All @@ -42,6 +46,7 @@ struct BunkerInterface {
// get robot state
virtual BunkerCoreState GetRobotState() = 0;
virtual BunkerActuatorState GetActuatorState() = 0;
virtual BunkerCommonSensorState GetCommonSensorState() = 0;
};
} // namespace westonrobot

Expand Down
18 changes: 17 additions & 1 deletion include/ugv_sdk/details/robot_base/bunker_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace westonrobot {
template <typename ParserType>
class BunkerBase : public AgilexBase<ParserType>, public BunkerInterface {
public:
BunkerBase() : AgilexBase<ParserType>(){};
BunkerBase() : AgilexBase<ParserType>() {};
~BunkerBase() = default;

// set up connection
Expand Down Expand Up @@ -60,6 +60,10 @@ class BunkerBase : public AgilexBase<ParserType>, public BunkerInterface {
}
return bunker_actuator;
}

BunkerCommonSensorState GetCommonSensorState() override {
return BunkerCommonSensorState();
}
};
} // namespace westonrobot

Expand All @@ -69,6 +73,18 @@ class BunkerBase : public AgilexBase<ParserType>, public BunkerInterface {
namespace westonrobot {
using BunkerBaseV1 = BunkerBase<BunkerProtocolV1Parser>;
using BunkerBaseV2 = BunkerBase<ProtocolV2Parser>;
using BunkerPro = BunkerBase<ProtocolV2Parser>;

class BunkerMini : public BunkerBase<ProtocolV2Parser> {
BunkerCommonSensorState GetCommonSensorState() override {
auto sensor = AgilexBase<ProtocolV2Parser>::GetCommonSensorStateMsgGroup();

BunkerCommonSensorState bunker_sensor;
bunker_sensor.time_stamp = sensor.time_stamp;
bunker_sensor.bms_basic_state = sensor.bms_basic_state;
return bunker_sensor;
}
};
} // namespace westonrobot

#endif /* BUNKER_BASE_HPP */
12 changes: 9 additions & 3 deletions include/ugv_sdk/mobile_robot/bunker_robot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@
namespace westonrobot {
class BunkerRobot : public RobotCommonInterface, public BunkerInterface {
public:
BunkerRobot(ProtocolVersion protocol = ProtocolVersion::AGX_V2);
enum class Variant {
kBunkerV1 = 0,
kBunkerV2,
kBunkerPro,
kBunkerMini,
};
BunkerRobot(Variant variant);
~BunkerRobot();

bool Connect(std::string can_name) override;

std::string RequestVersion(int timeout_sec = 3) override;

void EnableCommandedMode() override;
std::string RequestVersion(int timeout_sec = 3) override;

void SetMotionCommand(double linear_vel, double angular_vel) override;

Expand All @@ -36,6 +41,7 @@ class BunkerRobot : public RobotCommonInterface, public BunkerInterface {
// get robot state
BunkerCoreState GetRobotState() override;
BunkerActuatorState GetActuatorState() override;
BunkerCommonSensorState GetCommonSensorState() override;

private:
RobotCommonInterface* robot_;
Expand Down
4 changes: 2 additions & 2 deletions sample/bunker_demo/bunker_robot_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ int main(int argc, char **argv) {
std::unique_ptr<BunkerRobot> bunker;
if (protocol_version == "v1") {
bunker =
std::unique_ptr<BunkerRobot>(new BunkerRobot(ProtocolVersion::AGX_V1));
std::unique_ptr<BunkerRobot>(new BunkerRobot(BunkerRobot::Variant::kBunkerV1));
} else if (protocol_version == "v2") {
bunker =
std::unique_ptr<BunkerRobot>(new BunkerRobot(ProtocolVersion::AGX_V2));
std::unique_ptr<BunkerRobot>(new BunkerRobot(BunkerRobot::Variant::kBunkerV2));
} else {
std::cout << "Error: invalid protocol version string" << std::endl;
return -1;
Expand Down
16 changes: 13 additions & 3 deletions src/mobile_robot/bunker_robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
#include "ugv_sdk/details/robot_base/bunker_base.hpp"

namespace westonrobot {
BunkerRobot::BunkerRobot(ProtocolVersion protocol) {
if (protocol == ProtocolVersion::AGX_V1) {
BunkerRobot::BunkerRobot(Variant variant) {
if (variant == Variant::kBunkerV1) {
robot_ = new BunkerBaseV1();
} else if (protocol == ProtocolVersion::AGX_V2) {
} else if (variant == Variant::kBunkerV2) {
robot_ = new BunkerBaseV2();
} else if (variant == Variant::kBunkerPro) {
robot_ = new BunkerPro();
} else if (variant == Variant::kBunkerMini) {
robot_ = new BunkerMini();
}
}

Expand Down Expand Up @@ -53,4 +57,10 @@ BunkerActuatorState BunkerRobot::GetActuatorState() {
auto bunker = dynamic_cast<BunkerInterface*>(robot_);
return bunker->GetActuatorState();
}

BunkerCommonSensorState BunkerRobot::GetCommonSensorState() {
auto bunker = dynamic_cast<BunkerInterface*>(robot_);
return bunker->GetCommonSensorState();
}

} // namespace westonrobot