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

Commit 59f06e7

Browse files
authored
Merge pull request #263 from project-march/feature/PM-414-make-new-controller-template
Feature/pm 414 make new controller template
2 parents 0e66ef4 + a65370a commit 59f06e7

File tree

6 files changed

+130
-0
lines changed

6 files changed

+130
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
cmake_minimum_required(VERSION 2.8.3)
2+
project(march_joint_inertia_controller)
3+
4+
add_compile_options(-std=c++14 -Wall -Wextra -Werror)
5+
6+
find_package(catkin REQUIRED COMPONENTS
7+
controller_interface
8+
pluginlib
9+
roscpp
10+
)
11+
12+
catkin_package(
13+
INCLUDE_DIRS include
14+
LIBRARIES ${PROJECT_NAME}
15+
)
16+
17+
include_directories(include SYSTEM ${catkin_INCLUDE_DIRS})
18+
19+
add_library(${PROJECT_NAME} src/joint_inertia_controller.cpp)
20+
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})
21+
22+
install(DIRECTORY include/${PROJECT_NAME}/
23+
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
24+
)
25+
26+
install(TARGETS ${PROJECT_NAME}
27+
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
28+
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
29+
)
30+
31+
install(FILES controller_plugins.xml
32+
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
33+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
march:
2+
joint_inertia_controller:
3+
type: joint_inertia_controller/InertiaController
4+
joints:
5+
- left_ankle
6+
- left_hip_aa
7+
- left_hip_fe
8+
- left_knee
9+
- right_ankle
10+
- right_hip_aa
11+
- right_hip_fe
12+
- right_knee
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<library path="lib/libjoint_inertia_controller_lib">
2+
<class name="joint_inertia_controller/InertiaController"
3+
type="joint_inertia_controller::InertiaController"
4+
base_class_type="controller_interface::ControllerBase" />
5+
</library>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2020 Project March.
2+
3+
#ifndef MARCH_HARDWARE_JOINT_INERTIA_CONTROLLER_H
4+
#define MARCH_HARDWARE_JOINT_INERTIA_CONTROLLER_H
5+
6+
#include <controller_interface/controller.h>
7+
#include <hardware_interface/joint_command_interface.h>
8+
#include <pluginlib/class_list_macros.h>
9+
10+
namespace joint_inertia_controller
11+
{
12+
class InertiaController : public controller_interface::Controller<hardware_interface::PositionJointInterface>
13+
{
14+
public:
15+
bool init(hardware_interface::PositionJointInterface* hw, ros::NodeHandle& n);
16+
void update(const ros::Time& time, const ros::Duration& period);
17+
void starting(const ros::Time& time);
18+
void stopping(const ros::Time& time);
19+
20+
private:
21+
hardware_interface::JointHandle joint_;
22+
double init_pos_;
23+
};
24+
} // namespace joint_inertia_controller
25+
26+
#endif // MARCH_HARDWARE_JOINT_INERTIA_CONTROLLER_H
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<package format="2">
3+
<name>march_joint_inertia_controller</name>
4+
<version>0.0.0</version>
5+
<description>ROS controller which can be customized to operate in different circumstances. </description>
6+
7+
<maintainer email="software@projectmarch.nl">Project March</maintainer>
8+
9+
<license>TODO</license>
10+
11+
<buildtool_depend>catkin</buildtool_depend>
12+
<depend>roscpp</depend>
13+
<depend>controller_interface</depend>
14+
<depend>pluginlib</depend>
15+
16+
<export>
17+
<controller_interface plugin="${prefix}/controller_plugins.xml" />
18+
19+
</export>
20+
</package>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020 Project March.
2+
#include "march_joint_inertia_controller/joint_inertia_controller.h"
3+
#include <math.h>
4+
5+
namespace joint_inertia_controller
6+
{
7+
bool InertiaController::init(hardware_interface::PositionJointInterface* hw, ros::NodeHandle& nh)
8+
{
9+
std::string joint_name;
10+
if (!nh.getParam("joint_name", joint_name))
11+
{
12+
ROS_ERROR("No joint_name specified");
13+
return false;
14+
}
15+
joint_ = hw->getHandle(joint_name);
16+
return true;
17+
}
18+
19+
void InertiaController::starting(const ros::Time& /* time */)
20+
{
21+
init_pos_ = joint_.getPosition();
22+
}
23+
24+
void InertiaController::update(const ros::Time& /* time */, const ros::Duration& /* period */)
25+
{
26+
double dpos = init_pos_ + 10 * sin(ros::Time::now().toSec());
27+
double cpos = joint_.getPosition();
28+
joint_.setCommand(-10 * (cpos - dpos));
29+
}
30+
void InertiaController::stopping(const ros::Time& /* time */)
31+
{
32+
}
33+
} // namespace joint_inertia_controller
34+
PLUGINLIB_EXPORT_CLASS(joint_inertia_controller::InertiaController, controller_interface::ControllerBase);

0 commit comments

Comments
 (0)