agilex_types: added Agx prefix to types

This commit is contained in:
Ruixiang Du
2021-10-04 19:21:47 +08:00
parent c5faa29368
commit 636ea8fd15
15 changed files with 39 additions and 39 deletions

View File

@@ -32,8 +32,8 @@ typedef struct {
typedef struct {
bool enable_cmd_ctrl;
LightOperation front_light;
LightOperation rear_light;
AgxLightOperation front_light;
AgxLightOperation rear_light;
} LightCommandMessage;
typedef struct {
@@ -46,7 +46,7 @@ typedef struct {
// V1-only messages
typedef struct {
ControlMode control_mode;
AgxControlMode control_mode;
bool clear_all_error;
float linear;
float angular;
@@ -73,8 +73,8 @@ typedef ValueSetCommandMessageV1 ValueSetStateMessageV1;
#define SYSTEM_ERROR_STEER_ENCODER_MASK ((uint16_t)0x0080)
typedef struct {
VehicleState vehicle_state;
ControlMode control_mode;
AgxVehicleState vehicle_state;
AgxControlMode control_mode;
float battery_voltage;
uint16_t error_code;
} SystemStateMessage;
@@ -89,10 +89,10 @@ typedef struct {
typedef LightCommandMessage LightStateMessage;
typedef struct {
RcSwitchState swa;
RcSwitchState swb;
RcSwitchState swc;
RcSwitchState swd;
AgxRcSwitchState swa;
AgxRcSwitchState swb;
AgxRcSwitchState swc;
AgxRcSwitchState swd;
int8_t stick_right_v;
int8_t stick_right_h;
int8_t stick_left_v;
@@ -237,11 +237,11 @@ typedef struct {
} VersionResponseMessage;
typedef struct {
ControlMode mode;
AgxControlMode mode;
} ControlModeConfigMessage;
typedef struct {
BrakeMode mode;
AgxBrakeMode mode;
} BrakeModeConfigMessage;
typedef struct {

View File

@@ -21,37 +21,37 @@ typedef enum {
CONST_ON = 0x01,
BREATH = 0x02,
CUSTOM = 0x03
} LightMode;
} AgxLightMode;
typedef struct {
LightMode mode;
AgxLightMode mode;
uint8_t custom_value;
} LightOperation;
} AgxLightOperation;
typedef enum {
VehicleStateNormal = 0x00,
VehicleStateEStop = 0x01,
VehicleStateException = 0x02
} VehicleState;
} AgxVehicleState;
typedef enum {
// CONTROL_MODE_STANDBY = 0x00,
CONTROL_MODE_RC = 0x00,
CONTROL_MODE_CAN = 0x01,
CONTROL_MODE_UART = 0x02
} ControlMode;
} AgxControlMode;
typedef enum {
// CONTROL_MODE_STANDBY = 0x00,
BRAKE_MODE_UNLOCK = 0x00,
BRAKE_MODE_LOCK = 0x01
} BrakeMode;
} AgxBrakeMode;
typedef enum {
RC_SWITCH_UP = 0,
RC_SWITCH_MIDDLE,
RC_SWITCH_DOWN
} RcSwitchState;
} AgxRcSwitchState;
#ifdef __cplusplus
}

View File

@@ -45,8 +45,8 @@ struct RangerInterface {
virtual void SetMotionMode(uint8_t mode) = 0;
virtual void SetMotionCommand(double linear_vel, double steer_angle,
double lateral_vel, double angular_vel) = 0;
virtual void SetLightCommand(LightMode f_mode, uint8_t f_value,
LightMode r_mode, uint8_t r_value) = 0;
virtual void SetLightCommand(AgxLightMode f_mode, uint8_t f_value,
AgxLightMode r_mode, uint8_t r_value) = 0;
// get robot state
virtual RangerCoreState GetRobotState() = 0;

View File

@@ -64,7 +64,7 @@ class RobotCommonInterface {
/****** functions not available/valid to all robots ******/
// functions to be implemented by class AgilexBase
virtual void SetMotionMode(uint8_t mode){};
virtual void SetBrakedMode(BrakeMode mode){};
virtual void SetBrakedMode(AgxBrakeMode mode){};
virtual CoreStateMsgGroup GetRobotCoreStateMsgGroup() {
throw std::runtime_error(
@@ -88,8 +88,8 @@ class RobotCommonInterface {
"is supposed to be used.");
};
virtual void SendLightCommand(LightMode front_mode,
uint8_t front_custom_value, LightMode rear_mode,
virtual void SendLightCommand(AgxLightMode front_mode,
uint8_t front_custom_value, AgxLightMode rear_mode,
uint8_t rear_custom_value) {
throw std::runtime_error(
"Only a derived version of this function with actual implementation "

View File

@@ -44,8 +44,8 @@ struct ScoutInterface {
};
virtual void SetMotionCommand(double linear_vel, double angular_vel) = 0;
virtual void SetLightCommand(LightMode f_mode, uint8_t f_value,
LightMode r_mode, uint8_t r_value) = 0;
virtual void SetLightCommand(AgxLightMode f_mode, uint8_t f_value,
AgxLightMode r_mode, uint8_t r_value) = 0;
// get robot state
virtual ScoutCoreState GetRobotState() = 0;

View File

@@ -41,7 +41,7 @@ struct TracerInterface {
};
virtual void SetMotionCommand(double linear_vel, double angular_vel) = 0;
virtual void SetLightCommand(LightMode f_mode, uint8_t f_value) = 0;
virtual void SetLightCommand(AgxLightMode f_mode, uint8_t f_value) = 0;
// get robot state
virtual TracerCoreState GetRobotState() = 0;

View File

@@ -97,8 +97,8 @@ class AgilexBase : public RobotCommonInterface {
}
// one-shot light command
void SendLightCommand(LightMode front_mode, uint8_t front_custom_value,
LightMode rear_mode, uint8_t rear_custom_value) {
void SendLightCommand(AgxLightMode front_mode, uint8_t front_custom_value,
AgxLightMode rear_mode, uint8_t rear_custom_value) {
if (can_connected_) {
AgxMessage msg;
msg.type = AgxMsgLightCommand;
@@ -190,7 +190,7 @@ class AgilexBase : public RobotCommonInterface {
if (can_connected_) can_->StopService();
}
void SetBrakeMode(BrakeMode mode) {
void SetBrakeMode(AgxBrakeMode mode) {
// construct message
AgxMessage msg;
msg.type = AgxMsgBrakeModeConfig;

View File

@@ -62,11 +62,11 @@ class HunterBase : public AgilexBase<ParserType>, public HunterInterface {
}
void ActivateBrake() override {
AgilexBase<ParserType>::SetBrakeMode(BrakeMode::BRAKE_MODE_LOCK);
AgilexBase<ParserType>::SetBrakeMode(AgxBrakeMode::BRAKE_MODE_LOCK);
}
void ReleaseBrake() override {
AgilexBase<ParserType>::SetBrakeMode(BrakeMode::BRAKE_MODE_UNLOCK);
AgilexBase<ParserType>::SetBrakeMode(AgxBrakeMode::BRAKE_MODE_UNLOCK);
}
};
} // namespace westonrobot

View File

@@ -40,7 +40,7 @@ class RangerBase : public AgilexBase<ProtocolV2Parser>, public RangerInterface {
linear_vel, angular_vel, lateral_vel, steer_angle / 10.0);
}
void SetLightCommand(LightMode f_mode, uint8_t f_value, LightMode r_mode,
void SetLightCommand(AgxLightMode f_mode, uint8_t f_value, AgxLightMode r_mode,
uint8_t r_value) override {
AgilexBase<ProtocolV2Parser>::SendLightCommand(f_mode, f_value, r_mode,
r_value);

View File

@@ -40,8 +40,8 @@ class ScoutBase : public AgilexBase<ParserType>, public ScoutInterface {
0.0);
}
void SetLightCommand(LightMode f_mode, uint8_t f_value,
LightMode r_mode = LightMode::CONST_ON,
void SetLightCommand(AgxLightMode f_mode, uint8_t f_value,
AgxLightMode r_mode = AgxLightMode::CONST_ON,
uint8_t r_value = 0) override {
AgilexBase<ParserType>::SendLightCommand(f_mode, f_value, r_mode, r_value);
}

View File

@@ -42,7 +42,7 @@ class TracerBaseV2 : public AgilexBase<ProtocolV2Parser>,
0.0, 0.0);
}
void SetLightCommand(LightMode f_mode, uint8_t f_value) override {
void SetLightCommand(AgxLightMode f_mode, uint8_t f_value) override {
AgilexBase<ProtocolV2Parser>::SendLightCommand(f_mode, f_value, CONST_OFF,
0);
}

View File

@@ -28,7 +28,7 @@ class ScoutRobot : public RobotCommonInterface, public ScoutInterface {
void EnableCommandedMode() override;
void SetMotionCommand(double linear_vel, double angular_vel) override;
void SetLightCommand(LightMode f_mode, uint8_t f_value, LightMode r_mode,
void SetLightCommand(AgxLightMode f_mode, uint8_t f_value, AgxLightMode r_mode,
uint8_t r_value) override;
void DisableLightControl() override;

View File

@@ -1,160 +0,0 @@
/*
* stopwatch.hpp
*
* Created on: Jul 12, 2020 12:07
* Description:
*
* Source:
* [1] https://github.com/sailormoon/stopwatch
* [2] https://github.com/rxdu/stopwatch
*
* Copyright (c) 2019 sailormoon <http://unlicense.org>
* Copyright (c) 2020 Weston Robot Pte. Ltd.
*
* License: <http://unlicense.org>
*/
#ifndef STOPWATCH_HPP
#define STOPWATCH_HPP
#include <array>
#include <chrono>
#include <cstdint>
#include <algorithm>
#include <thread>
namespace westonrobot {
// only supported on x86 processors
#if (defined __x86_64__) || (defined __i386)
// An implementation of the 'TrivialClock' concept using the rdtscp instruction.
struct rdtscp_clock {
using rep = std::uint64_t;
using period = std::ratio<1>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<rdtscp_clock, duration>;
static time_point now() noexcept {
std::uint32_t hi, lo;
__asm__ __volatile__("rdtscp" : "=d"(hi), "=a"(lo));
return time_point(duration((static_cast<std::uint64_t>(hi) << 32) | lo));
}
};
// A timer using the specified clock.
template <class Clock = std::chrono::system_clock>
struct timer {
using time_point = typename Clock::time_point;
using duration = typename Clock::duration;
timer(const duration duration) : expiry(Clock::now() + duration) {}
timer(const time_point expiry) : expiry(expiry) {}
bool done() const { return done(Clock::now()); }
bool done(const time_point now) const { return now >= expiry; }
duration remaining() const { return remaining(Clock::now()); };
duration remaining(const time_point now) const { return expiry - now; }
const time_point expiry;
};
template <class Clock = std::chrono::system_clock>
constexpr timer<Clock> make_timer(const typename Clock::duration duration) {
return timer<Clock>(duration);
}
// Times how long it takes a function to execute using the specified clock.
template <class Clock = rdtscp_clock, class Func>
typename Clock::duration time_func(Func &&function) {
const auto start = Clock::now();
function();
return Clock::now() - start;
}
// Samples the given function N times using the specified clock.
template <std::size_t N, class Clock = rdtscp_clock, class Func>
std::array<typename Clock::duration, N> sample(Func &&function) {
std::array<typename Clock::duration, N> samples;
for (std::size_t i = 0u; i < N; ++i) {
samples[i] = time_func<Clock>(function);
}
std::sort(samples.begin(), samples.end());
return samples;
}
#endif /* __x86_64__ or __i386 */
struct StopWatch {
using Clock = std::chrono::high_resolution_clock;
using time_point = typename Clock::time_point;
using duration = typename Clock::duration;
StopWatch() { tic_point = Clock::now(); };
time_point tic_point;
void tic() { tic_point = Clock::now(); };
double toc() {
return std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() -
tic_point)
.count() /
1000000.0;
};
// toc() in different units
double stoc() {
return std::chrono::duration_cast<std::chrono::seconds>(Clock::now() -
tic_point)
.count();
};
double mtoc() {
return std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() -
tic_point)
.count();
};
double utoc() {
return std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() -
tic_point)
.count();
};
double ntoc() {
return std::chrono::duration_cast<std::chrono::nanoseconds>(Clock::now() -
tic_point)
.count();
};
};
struct Timer {
using Clock = std::chrono::high_resolution_clock;
using time_point = typename Clock::time_point;
using duration = typename Clock::duration;
Timer() { tic_point = Clock::now(); };
time_point tic_point;
void reset() { tic_point = Clock::now(); };
// you have to call reset() before calling sleep functions
void sleep_until_ms(int64_t period_ms) {
int64_t duration =
period_ms - std::chrono::duration_cast<std::chrono::milliseconds>(
Clock::now() - tic_point)
.count();
if (duration > 0)
std::this_thread::sleep_for(std::chrono::milliseconds(duration));
};
void sleep_until_us(int64_t period_us) {
int64_t duration =
period_us - std::chrono::duration_cast<std::chrono::microseconds>(
Clock::now() - tic_point)
.count();
if (duration > 0)
std::this_thread::sleep_for(std::chrono::microseconds(duration));
};
};
} // namespace westonrobot
#endif // STOPWATCH_HPP