Control Libraries 7.4.0
Loading...
Searching...
No Matches
VelocityImpedance.cpp
1#include "controllers/impedance/VelocityImpedance.hpp"
2
3#include "controllers/exceptions/NotImplementedException.hpp"
4#include "state_representation/space/joint/JointState.hpp"
5#include "state_representation/space/joint/JointPositions.hpp"
6#include "state_representation/space/joint/JointVelocities.hpp"
7#include "state_representation/space/cartesian/CartesianState.hpp"
8#include "state_representation/space/cartesian/CartesianPose.hpp"
9#include "state_representation/space/cartesian/CartesianTwist.hpp"
10
11using namespace state_representation;
12
13namespace controllers::impedance {
14
15template<class S>
18 "compute_command(desired_state, feedback_state) not implemented for this input class");
19}
20
21template<>
23 const CartesianState& desired_state, const CartesianState& feedback_state
24) {
25 using namespace std::chrono_literals;
26 // compute the displacement by multiplying the desired twist by the unit time period and add it to the current pose
27 CartesianPose desired_pose = 1s * static_cast<CartesianTwist>(desired_state);
28 // set this as the new desired_state keeping the rest of the state values
29 CartesianState integrated_desired_state = desired_state;
30 integrated_desired_state.set_pose(desired_pose.data());
31 // only keep velocity feedback
32 CartesianTwist feedback_twist(feedback_state);
33 // compute the impedance control law normally
34 return this->Impedance<CartesianState>::compute_command(integrated_desired_state, feedback_twist);
35}
36
37template<>
39 const JointState& desired_state, const JointState& feedback_state
40) {
41
42 using namespace std::chrono_literals;
43 // compute the displacement by multiplying the desired velocities by the unit time period and add it to the current positions
44 JointPositions desired_positions = 1s * static_cast<JointVelocities>(desired_state);
45 // set this displacement as the positions of the desired_state
46 JointState integrated_desired_state = desired_state;
47 integrated_desired_state.set_positions(desired_positions.data());
48 // only keep velocity feedback
49 JointVelocities feedback_velocities(feedback_state);
50 // compute the impedance control law normally
51 return this->Impedance<JointState>::compute_command(integrated_desired_state, feedback_velocities);
52}
53}// namespace controllers
S compute_command(const S &command_state, const S &feedback_state) override
Compute the command output based on the commanded state and a feedback state To be redefined based on...
Definition Impedance.cpp:12
S compute_command(const S &desired_state, const S &feedback_state) override
Compute the force (task space) or torque (joint space) command based on the input state of the system...
Class to define Cartesian pose in Cartesian space as 3D position and quaternion based orientation.
Eigen::VectorXd data() const override
Returns the pose data as an Eigen vector.
Class to represent a state in Cartesian space.
void set_pose(const Eigen::Vector3d &position, const Eigen::Quaterniond &orientation)
Setter of the pose from both position and orientation.
Class to define twist in Cartesian space as 3D linear and angular velocity vectors.
Class to define positions of the joints.
Eigen::VectorXd data() const override
Returns the positions data as an Eigen vector.
Class to define a state in joint space.
void set_positions(const Eigen::VectorXd &positions)
Setter of the positions attribute.
Class to define velocities of the joints.
Core state variables and objects.