- 3.0.2 rigid body dynamics module.
JointPositionPIDController-impl.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 namespace ct {
9 namespace rbd {
10 
11 template <size_t NJOINTS>
13 {
14  throw std::runtime_error("RBD: JointPositionPIDController.h, clone() not implemented");
15 }
16 
17 template <size_t NJOINTS>
19 {
20 }
21 
22 template <size_t NJOINTS>
24  const Eigen::Matrix<double, NJOINTS, 1>& desiredPosition,
25  const Eigen::Matrix<double, NJOINTS, 1>& desiredVelocity,
26  const std::vector<PIDController::parameters_t>& parameters)
27 {
28  assert(parameters.size() == NJOINTS);
29 
30  for (size_t i = 0; i < NJOINTS; i++)
31  {
32  jointControllers_.push_back(
33  PIDController(parameters[i], PIDController::setpoint_t(desiredPosition(i), desiredVelocity(i))));
34  }
35 }
36 
37 template <size_t NJOINTS>
39  const Eigen::Matrix<double, NJOINTS, 1>& desiredPosition,
40  const Eigen::Matrix<double, NJOINTS, 1>& desiredVelocity,
41  const PIDController::parameters_t& parameters)
42 {
43  for (size_t i = 0; i < NJOINTS; i++)
44  {
45  jointControllers_.push_back(
46  PIDController(parameters, PIDController::setpoint_t(desiredPosition(i), desiredVelocity(i))));
47  }
48 }
49 
50 template <size_t NJOINTS>
52  const core::Time& t,
54 {
55  ct::rbd::JointState<NJOINTS> jstate(state);
56 
57  for (size_t i = 0; i < NJOINTS; i++)
58  {
59  control(i) = jointControllers_[i].computeControl(jstate.getPosition(i), jstate.getVelocity(i), t);
60  }
61 }
62 
63 template <size_t NJOINTS>
64 void JointPositionPIDController<NJOINTS>::setDesiredPosition(const Eigen::Matrix<double, NJOINTS, 1>& desiredPosition)
65 {
66  for (size_t i = 0; i < NJOINTS; i++)
67  {
68  jointControllers_[i].setDesiredState(desiredPosition(i));
69  }
70 }
71 
72 template <size_t NJOINTS>
73 void JointPositionPIDController<NJOINTS>::setDesiredPosition(double desiredPosition, int jointId)
74 {
75  assert(0 <= jointId && jointId < NJOINTS); // assuming first joint has index 0
76 
77  jointControllers_[jointId].setDesiredState(desiredPosition);
78 }
79 
80 template <size_t NJOINTS>
81 void JointPositionPIDController<NJOINTS>::setAllPIDGains(double kp, double ki, double kd)
82 {
83  PIDController::parameters_t parameters;
84  parameters.k_p = kp;
85  parameters.k_i = ki;
86  parameters.k_d = kd;
87 
88  for (size_t i = 0; i < NJOINTS; i++)
89  {
90  jointControllers_[i].changeParameters(parameters);
91  }
92 }
93 
94 template <size_t NJOINTS>
96 {
97  for (size_t i = 0; i < NJOINTS; i++)
98  {
99  jointControllers_[i].reset();
100  }
101 }
102 
103 
104 } // namespace rbd
105 } // namespace ct
joint state and joint velocity
Definition: JointState.h:21
virtual JointPositionPIDController< NJOINTS > * clone() const override
Definition: JointPositionPIDController-impl.h:12
A joint position controller using a PID controller for all joints.
Definition: JointPositionPIDController.h:19
void setDesiredPosition(const Eigen::Matrix< double, NJOINTS, 1 > &desiredPosition)
Definition: JointPositionPIDController-impl.h:64
void computeControl(const core::StateVector< STATE_DIM > &state, const core::Time &t, core::ControlVector< NJOINTS > &control) override
Definition: JointPositionPIDController-impl.h:51
void setAllPIDGains(double kp, double ki, double kd)
Definition: JointPositionPIDController-impl.h:81
for i
SCALAR & getVelocity(size_t i)
Definition: JointState.h:136
virtual ~JointPositionPIDController()
Definition: JointPositionPIDController-impl.h:18
JointPositionPIDController(const Eigen::Matrix< double, NJOINTS, 1 > &desiredPosition=Eigen::Matrix< double, NJOINTS, 1 >::Zero(), const Eigen::Matrix< double, NJOINTS, 1 > &desiredVelocity=Eigen::Matrix< double, NJOINTS, 1 >::Zero(), const std::vector< PIDController::parameters_t > &parameters=std::vector< PIDController::parameters_t >(NJOINTS, PIDController::parameters_t()))
Definition: JointPositionPIDController-impl.h:23
SCALAR & getPosition(size_t i)
Definition: JointState.h:81
void reset()
Definition: JointPositionPIDController-impl.h:95
double Time