Skip to content

Commit

Permalink
refactor: Change AccelerationFunctionIndex to AccelerationType
Browse files Browse the repository at this point in the history
  • Loading branch information
2b-t committed Nov 19, 2023
1 parent 1f26489 commit 698db7b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
12 changes: 6 additions & 6 deletions bindings/myactuator_rmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "myactuator_rmd/actuator_state/acceleration_function_index.hpp"
#include "myactuator_rmd/actuator_state/acceleration_type.hpp"
#include "myactuator_rmd/actuator_state/baud_rate.hpp"
#include "myactuator_rmd/actuator_state/control_mode.hpp"
#include "myactuator_rmd/actuator_state/error_code.hpp"
Expand Down Expand Up @@ -71,11 +71,11 @@ PYBIND11_MODULE(myactuator_rmd_py, m) {
pybind11::register_exception<myactuator_rmd::ValueRangeException>(m, "ValueRangeException");

auto m_actuator_state = m.def_submodule("actuator_state", "Submodule for actuator state structures");
pybind11::enum_<myactuator_rmd::AccelerationFunctionIndex>(m_actuator_state, "AccelerationFunctionIndex")
.value("POSITION_PLANNING_ACCELERATION", myactuator_rmd::AccelerationFunctionIndex::POSITION_PLANNING_ACCELERATION)
.value("POSITION_PLANNING_DECELERATION", myactuator_rmd::AccelerationFunctionIndex::POSITION_PLANNING_DECELERATION)
.value("VELOCITY_PLANNING_ACCELERATION", myactuator_rmd::AccelerationFunctionIndex::VELOCITY_PLANNING_ACCELERATION)
.value("VELOCITY_PLANNING_DECELERATION", myactuator_rmd::AccelerationFunctionIndex::VELOCITY_PLANNING_DECELERATION);
pybind11::enum_<myactuator_rmd::AccelerationType>(m_actuator_state, "AccelerationType")
.value("POSITION_PLANNING_ACCELERATION", myactuator_rmd::AccelerationType::POSITION_PLANNING_ACCELERATION)
.value("POSITION_PLANNING_DECELERATION", myactuator_rmd::AccelerationType::POSITION_PLANNING_DECELERATION)
.value("VELOCITY_PLANNING_ACCELERATION", myactuator_rmd::AccelerationType::VELOCITY_PLANNING_ACCELERATION)
.value("VELOCITY_PLANNING_DECELERATION", myactuator_rmd::AccelerationType::VELOCITY_PLANNING_DECELERATION);
pybind11::enum_<myactuator_rmd::BaudRate>(m_actuator_state, "BaudRate")
.value("KBPS500", myactuator_rmd::BaudRate::KBPS500)
.value("MBPS1", myactuator_rmd::BaudRate::MBPS1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
/**
* \file acceleration_function_index.hpp
* \file acceleration_type.hpp
* \mainpage
* Index of the acceleration/deceleration types
* \author
* Tobit Flatscher (github.com/2b-t)
*/

#ifndef MYACTUATOR_RMD__ACCELERATION_FUNCTION_INDEX
#define MYACTUATOR_RMD__ACCELERATION_FUNCTION_INDEX
#ifndef MYACTUATOR_RMD__ACCELERATION_TYPE
#define MYACTUATOR_RMD__ACCELERATION_TYPE
#pragma once

#include <cstdint>


namespace myactuator_rmd {

/**\enum AccelerationFunctionIndex
/**\enum AccelerationType
* \brief
* Strongly typed enum for the different acceleration (from initial to maximum speed)/
* deceleration (from maximum speed to stop) types
*/
enum class AccelerationFunctionIndex: std::uint8_t {
enum class AccelerationType: std::uint8_t {
POSITION_PLANNING_ACCELERATION = 0x00,
POSITION_PLANNING_DECELERATION = 0x01,
VELOCITY_PLANNING_ACCELERATION = 0x02,
Expand All @@ -29,4 +29,4 @@ namespace myactuator_rmd {

}

#endif // MYACTUATOR_RMD__ACCELERATION_FUNCTION_INDEX
#endif // MYACTUATOR_RMD__ACCELERATION_TYPE
4 changes: 2 additions & 2 deletions include/myactuator_rmd/driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <cstdint>
#include <string>

#include "myactuator_rmd/actuator_state/acceleration_function_index.hpp"
#include "myactuator_rmd/actuator_state/acceleration_type.hpp"
#include "myactuator_rmd/actuator_state/baud_rate.hpp"
#include "myactuator_rmd/actuator_state/control_mode.hpp"
#include "myactuator_rmd/actuator_state/feedback.hpp"
Expand Down Expand Up @@ -294,7 +294,7 @@ namespace myactuator_rmd {
* \param[in] mode
* The mode of the desired acceleration/deceleration to be set
*/
void setAcceleration(std::uint32_t const acceleration, AccelerationFunctionIndex const mode);
void setAcceleration(std::uint32_t const acceleration, AccelerationType const mode);

/**\fn setBaudRate
* \brief
Expand Down
6 changes: 3 additions & 3 deletions include/myactuator_rmd/protocol/requests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <cstdint>

#include "myactuator_rmd/actuator_state/baud_rate.hpp"
#include "myactuator_rmd/actuator_state/acceleration_function_index.hpp"
#include "myactuator_rmd/actuator_state/acceleration_type.hpp"
#include "myactuator_rmd/actuator_state/gains.hpp"
#include "myactuator_rmd/protocol/command_type.hpp"
#include "myactuator_rmd/protocol/single_motor_message.hpp"
Expand Down Expand Up @@ -121,7 +121,7 @@ namespace myactuator_rmd {
* \param[in] mode
* The mode of the desired acceleration/deceleration to be set
*/
SetAccelerationRequest(std::uint32_t const acceleration, AccelerationFunctionIndex const mode);
SetAccelerationRequest(std::uint32_t const acceleration, AccelerationType const mode);
SetAccelerationRequest() = delete;
SetAccelerationRequest(SetAccelerationRequest const&) = default;
SetAccelerationRequest& operator = (SetAccelerationRequest const&) = default;
Expand All @@ -147,7 +147,7 @@ namespace myactuator_rmd {
* The acceleration mode
*/
[[nodiscard]]
AccelerationFunctionIndex getMode() const noexcept;
AccelerationType getMode() const noexcept;
};

/**\class SetBaudRateRequest
Expand Down
2 changes: 1 addition & 1 deletion src/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace myactuator_rmd {
return response.getStatus();
}

void Driver::setAcceleration(std::uint32_t const acceleration, AccelerationFunctionIndex const mode) {
void Driver::setAcceleration(std::uint32_t const acceleration, AccelerationType const mode) {
SetAccelerationRequest const request {acceleration, mode};
[[maybe_unused]] auto const response {sendRecv<SetAccelerationResponse>(request)};
return;
Expand Down
12 changes: 6 additions & 6 deletions src/protocol/requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>

#include "myactuator_rmd/actuator_state/baud_rate.hpp"
#include "myactuator_rmd/actuator_state/acceleration_function_index.hpp"
#include "myactuator_rmd/actuator_state/acceleration_type.hpp"
#include "myactuator_rmd/protocol/single_motor_message.hpp"
#include "myactuator_rmd/exceptions.hpp"

Expand Down Expand Up @@ -34,13 +34,13 @@ namespace myactuator_rmd {
return static_cast<std::uint16_t>(getAs<std::uint8_t>(7));
}

SetAccelerationRequest::SetAccelerationRequest(std::uint32_t const acceleration, AccelerationFunctionIndex const mode)
SetAccelerationRequest::SetAccelerationRequest(std::uint32_t const acceleration, AccelerationType const mode)
: SingleMotorRequest{} {
if ((acceleration < 100) || (acceleration > 60000)) {
throw ValueRangeException("Acceleration value '" + std::to_string(acceleration) + "' out of range [100, 60000]");
}
auto const acceleration_function_index {static_cast<std::uint8_t>(mode)};
setAt(acceleration_function_index, 1);
auto const acceleration_type {static_cast<std::uint8_t>(mode)};
setAt(acceleration_type, 1);
setAt(acceleration, 4);
return;
}
Expand All @@ -49,8 +49,8 @@ namespace myactuator_rmd {
return getAs<std::uint32_t>(4);
}

AccelerationFunctionIndex SetAccelerationRequest::getMode() const noexcept {
return static_cast<AccelerationFunctionIndex>(getAs<std::uint8_t>(1));
AccelerationType SetAccelerationRequest::getMode() const noexcept {
return static_cast<AccelerationType>(getAs<std::uint8_t>(1));
}

SetBaudRateRequest::SetBaudRateRequest(BaudRate const baud_rate)
Expand Down
18 changes: 9 additions & 9 deletions test/protocol/requests_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <gtest/gtest.h>

#include "myactuator_rmd/actuator_state/acceleration_function_index.hpp"
#include "myactuator_rmd/actuator_state/acceleration_type.hpp"
#include "myactuator_rmd/actuator_state/baud_rate.hpp"
#include "myactuator_rmd/actuator_state/gains.hpp"
#include "myactuator_rmd/protocol/requests.hpp"
Expand Down Expand Up @@ -41,33 +41,33 @@ namespace myactuator_rmd {
TEST(SetPositionPlanningAccelerationRequestTest, parsing) {
myactuator_rmd::SetAccelerationRequest const request {{0x43, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00}};
std::uint32_t const acceleration {request.getAcceleration()};
AccelerationFunctionIndex const mode {request.getMode()};
AccelerationType const mode {request.getMode()};
EXPECT_EQ(acceleration, 10000);
EXPECT_EQ(mode, AccelerationFunctionIndex::POSITION_PLANNING_ACCELERATION);
EXPECT_EQ(mode, AccelerationType::POSITION_PLANNING_ACCELERATION);
}

TEST(SetPositionPlanningDecelerationRequestTest, parsing) {
myactuator_rmd::SetAccelerationRequest const request {{0x43, 0x01, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00}};
std::uint32_t const acceleration {request.getAcceleration()};
AccelerationFunctionIndex const mode {request.getMode()};
AccelerationType const mode {request.getMode()};
EXPECT_EQ(acceleration, 10000);
EXPECT_EQ(mode, AccelerationFunctionIndex::POSITION_PLANNING_DECELERATION);
EXPECT_EQ(mode, AccelerationType::POSITION_PLANNING_DECELERATION);
}

TEST(SetVelocityPlanningAccelerationRequestTest, parsing) {
myactuator_rmd::SetAccelerationRequest const request {{0x43, 0x02, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00}};
std::uint32_t const acceleration {request.getAcceleration()};
AccelerationFunctionIndex const mode {request.getMode()};
AccelerationType const mode {request.getMode()};
EXPECT_EQ(acceleration, 10000);
EXPECT_EQ(mode, AccelerationFunctionIndex::VELOCITY_PLANNING_ACCELERATION);
EXPECT_EQ(mode, AccelerationType::VELOCITY_PLANNING_ACCELERATION);
}

TEST(SetVelocityPlanningDecelerationRequestTest, parsing) {
myactuator_rmd::SetAccelerationRequest const request {{0x43, 0x03, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00}};
std::uint32_t const acceleration {request.getAcceleration()};
AccelerationFunctionIndex const mode {request.getMode()};
AccelerationType const mode {request.getMode()};
EXPECT_EQ(acceleration, 10000);
EXPECT_EQ(mode, AccelerationFunctionIndex::VELOCITY_PLANNING_DECELERATION);
EXPECT_EQ(mode, AccelerationType::VELOCITY_PLANNING_DECELERATION);
}

TEST(SetControllerGainsPersistentlyRequestTest, parsing) {
Expand Down

0 comments on commit 698db7b

Please sign in to comment.