Skip to content

Commit

Permalink
ranger_base: changed base class to RangerBase and updated constructor…
Browse files Browse the repository at this point in the history
… of RangerRobot class
  • Loading branch information
karthee-weston committed Oct 9, 2024
1 parent b7a0208 commit a63adad
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
35 changes: 29 additions & 6 deletions include/ugv_sdk/details/robot_base/ranger_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
#include "ugv_sdk/details/protocol_v2/protocol_v2_parser.hpp"

namespace westonrobot {
class RangerBaseV2 : public AgilexBase<ProtocolV2Parser>,
public RangerInterface {
class RangerBase : public AgilexBase<ProtocolV2Parser>, public RangerInterface {
public:
RangerBaseV2() : AgilexBase<ProtocolV2Parser>(){};
virtual ~RangerBaseV2() = default;
RangerBase() : AgilexBase<ProtocolV2Parser>() {};
virtual ~RangerBase() = default;

// set up connection
bool Connect(std::string can_name) override {
Expand Down Expand Up @@ -88,6 +87,30 @@ class RangerBaseV2 : public AgilexBase<ProtocolV2Parser>,
return ranger_actuator;
}

RangerCommonSensorState GetCommonSensorState() override {
auto common_sensor =
AgilexBase<ProtocolV2Parser>::GetCommonSensorStateMsgGroup();

RangerCommonSensorState ranger_bms;

ranger_bms.time_stamp = common_sensor.time_stamp;

ranger_bms.bms_basic_state.current = common_sensor.bms_basic_state.current;
ranger_bms.bms_basic_state.voltage =
common_sensor.bms_basic_state.voltage;
ranger_bms.bms_basic_state.battery_soc =
common_sensor.bms_basic_state.battery_soc;
ranger_bms.bms_basic_state.battery_soh =
common_sensor.bms_basic_state.battery_soh;
ranger_bms.bms_basic_state.temperature =
common_sensor.bms_basic_state.temperature;

return ranger_bms;
}
};

using RangerMiniV3Base = RangerBase;
class RangerMiniV2Base : public RangerBase {
RangerCommonSensorState GetCommonSensorState() override {
auto common_sensor =
AgilexBase<ProtocolV2Parser>::GetCommonSensorStateMsgGroup();
Expand Down Expand Up @@ -116,9 +139,9 @@ class RangerBaseV2 : public AgilexBase<ProtocolV2Parser>,
// Note: Ranger Mini V1 uses a modified AgileX V2 protocol
// Here we provide a work-around fix as no new firmware will be provided from
// AgileX to properly fix the issue.
class RangerMiniV1Base : public RangerBaseV2 {
class RangerMiniV1Base : public RangerBase {
public:
RangerMiniV1Base() : RangerBaseV2(){};
RangerMiniV1Base() : RangerBase() {};
~RangerMiniV1Base() = default;

// robot control
Expand Down
9 changes: 8 additions & 1 deletion include/ugv_sdk/mobile_robot/ranger_robot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
namespace westonrobot {
class RangerRobot : public RobotCommonInterface, public RangerInterface {
public:
RangerRobot(bool is_mini_v1);
enum class Variant {
kRangerMiniV1 = 0,
kRangerMiniV2,
kRangerMiniV3,
kRanger,
};

RangerRobot(Variant variant);
~RangerRobot();

bool Connect(std::string can_name) override;
Expand Down
10 changes: 7 additions & 3 deletions src/mobile_robot/ranger_robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
#include "ugv_sdk/details/robot_base/ranger_base.hpp"

namespace westonrobot {
RangerRobot::RangerRobot(bool is_mini_v1) {
if (is_mini_v1) {
RangerRobot::RangerRobot(Variant variant) {
if (variant == Variant::kRangerMiniV1) {
robot_ = new RangerMiniV1Base();
} else if (variant == Variant::kRangerMiniV2) {
robot_ = new RangerMiniV2Base();
} else if (variant == Variant::kRangerMiniV3) {
robot_ = new RangerMiniV3Base();
} else {
robot_ = new RangerBaseV2();
robot_ = new RangerBase();
}
}

Expand Down

0 comments on commit a63adad

Please sign in to comment.