Skip to content
This repository was archived by the owner on Dec 1, 2020. It is now read-only.

Commit f20c072

Browse files
authored
Merge pull request #184 from project-march/fix/refactor-hardware-builder
Refactor hardware builder
2 parents dad4180 + 5f06f8a commit f20c072

20 files changed

+487
-525
lines changed

doc.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

march_hardware_builder/CMakeLists.txt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ roslint_cpp(${lintfiles})
2929
include_directories(include SYSTEM ${catkin_INCLUDE_DIRS})
3030

3131
add_library(${PROJECT_NAME}
32-
src/HardwareBuilder.cpp
32+
src/hardware_builder.cpp
3333
)
3434

3535
target_link_libraries(${PROJECT_NAME}
@@ -53,23 +53,21 @@ install(TARGETS ${PROJECT_NAME}
5353
## Add gtest based cpp test target and link libraries
5454
if (CATKIN_ENABLE_TESTING)
5555
find_package(code_coverage REQUIRED)
56-
find_package(rostest REQUIRED)
5756

5857
if(ENABLE_COVERAGE_TESTING)
5958
include(CodeCoverage)
6059
append_coverage_compiler_flags()
6160
endif()
6261

63-
add_rostest_gtest(${PROJECT_NAME}-test
64-
test/${PROJECT_NAME}.test
65-
test/TestRunner.cpp
66-
test/TestAllowedRobots.cpp
67-
test/TestHardwareBuilderCreateEncoder.cpp
68-
test/TestHardwareBuilderCreateIMotionCube.cpp
69-
test/TestHardwareBuilderCreateJoint.cpp
70-
test/TestHardwareBuilderCreatePowerDistributionBoard.cpp
62+
catkin_add_gtest(${PROJECT_NAME}_test
63+
test/test_runner.cpp
64+
test/allowed_robot_test.cpp
65+
test/encoder_builder_test.cpp
66+
test/imc_builder_test.cpp
67+
test/joint_builder_test.cpp
68+
test/pdb_builder_test.cpp
7169
)
72-
target_link_libraries(${PROJECT_NAME}-test ${catkin_LIBRARIES} ${PROJECT_NAME} gtest gmock)
70+
target_link_libraries(${PROJECT_NAME}_test ${catkin_LIBRARIES} ${PROJECT_NAME} gtest gmock)
7371

7472
if(ENABLE_COVERAGE_TESTING)
7573
set(COVERAGE_EXCLUDES "*/${PROJECT_NAME}/test*")

march_hardware_builder/include/march_hardware_builder/AllowedRobot.h

Lines changed: 0 additions & 93 deletions
This file was deleted.

march_hardware_builder/include/march_hardware_builder/HardwareBuilder.h

Lines changed: 0 additions & 81 deletions
This file was deleted.

march_hardware_builder/include/march_hardware_builder/HardwareConfigExceptions.h

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright 2019 Project March.
2+
#ifndef MARCH_HARDWARE_BUILDER_ALLOWED_ROBOT_H
3+
#define MARCH_HARDWARE_BUILDER_ALLOWED_ROBOT_H
4+
#include <iostream>
5+
#include <string>
6+
#include <ros/package.h>
7+
8+
class AllowedRobot
9+
{
10+
public:
11+
enum Value : int
12+
{
13+
march4,
14+
march3,
15+
test_joint_rotational,
16+
test_joint_linear,
17+
pdb,
18+
};
19+
20+
AllowedRobot() = default;
21+
explicit AllowedRobot(const std::string& robot_name)
22+
{
23+
if (robot_name == "march4")
24+
{
25+
this->value = march4;
26+
}
27+
else if (robot_name == "march3")
28+
{
29+
this->value = march3;
30+
}
31+
else if (robot_name == "test_joint_rotational")
32+
{
33+
this->value = test_joint_rotational;
34+
}
35+
else if (robot_name == "test_joint_linear")
36+
{
37+
this->value = test_joint_linear;
38+
}
39+
else if (robot_name == "pdb")
40+
{
41+
this->value = pdb;
42+
}
43+
else
44+
{
45+
ROS_WARN_STREAM("Unknown robot " << robot_name);
46+
this->value = AllowedRobot::test_joint_rotational;
47+
}
48+
}
49+
50+
std::string getFilePath()
51+
{
52+
std::string base_path = ros::package::getPath("march_hardware_builder");
53+
if (this->value == AllowedRobot::march4)
54+
{
55+
return base_path.append("/robots/march4.yaml");
56+
}
57+
else if (this->value == AllowedRobot::march3)
58+
{
59+
return base_path.append("/robots/march3.yaml");
60+
}
61+
else if (this->value == AllowedRobot::test_joint_rotational)
62+
{
63+
return base_path.append("/robots/test_joint_rotational.yaml");
64+
}
65+
else if (this->value == AllowedRobot::test_joint_linear)
66+
{
67+
return base_path.append("/robots/test_joint_linear.yaml");
68+
}
69+
else if (this->value == AllowedRobot::pdb)
70+
{
71+
return base_path.append("/robots/pdb.yaml");
72+
}
73+
ROS_ERROR("Robotname not implemented. Using test_joint_rotational.yaml...");
74+
return base_path.append("/robots/test_joint_rotational.yaml");
75+
}
76+
77+
constexpr AllowedRobot(Value allowed_robot) : value(allowed_robot)
78+
{
79+
}
80+
81+
bool operator==(AllowedRobot a) const
82+
{
83+
return value == a.value;
84+
}
85+
bool operator!=(AllowedRobot a) const
86+
{
87+
return value != a.value;
88+
}
89+
90+
friend std::ostream& operator<<(std::ostream& out, const AllowedRobot& c)
91+
{
92+
switch (c.value)
93+
{
94+
case march4:
95+
out << "march4";
96+
break;
97+
case march3:
98+
out << "march3";
99+
break;
100+
case test_joint_linear:
101+
out << "test_joint_linear";
102+
break;
103+
case test_joint_rotational:
104+
out << "test_joint_rotational";
105+
break;
106+
case pdb:
107+
out << "pdb";
108+
break;
109+
default:
110+
out << "(Unknown)";
111+
break;
112+
}
113+
return out;
114+
}
115+
116+
private:
117+
Value value;
118+
};
119+
120+
#endif // MARCH_HARDWARE_BUILDER_ALLOWED_ROBOT_H

0 commit comments

Comments
 (0)