Skip to content

Commit c6135a3

Browse files
committed
Merge branch 'devel'
2 parents 48f8159 + df49996 commit c6135a3

File tree

11 files changed

+469
-87
lines changed

11 files changed

+469
-87
lines changed

CITATION.cff

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors:
44
- family-names: "Woolfrey"
55
given-names: "Jon"
66
orcid: "https://orcid.org/0000-0001-5926-5669"
7-
title: "Robot Library"
8-
version: 1.0.0
9-
date-released: 2025-04-11
7+
title: "RobotLibrary"
8+
version: 2.0.0
9+
date-released: 2025-08-11
1010
url: "https://github.com/Woolfrey/software_robot_library"

Control/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

22
# List the source files for this library
3-
add_library(Control src/SerialDynamicControl.cpp
4-
src/SerialKinematicControl.cpp
5-
src/SerialLinkBase.cpp
3+
add_library(Control src/SerialLinkBase.cpp
4+
src/SerialLinkDynamics.cpp
5+
src/SerialLinkImpedance.cpp
6+
src/SerialLinkKinematics.cpp
67
)
78

89
# Specify targets to be built

Control/include/Control/DataStructures.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* @file DataStructures.h
33
* @author Jon Woolfrey
44
5-
* @date July 2025
6-
* @version 1.1
5+
* @date August 2025
6+
* @version 2.0
7+
*
78
* @brief Contains custom structs used in Control classes.
89
*
910
* @copyright (c) 2025 Jon Woolfrey
@@ -30,9 +31,8 @@ struct SerialLinkParameters
3031
{
3132
SerialLinkParameters() = default; ///< This enables default options
3233

33-
double jointPositionGain = 100.0; ///< Scales the position error feedback
34-
double jointVelocityGain = 20.0; ///< Scales the velocity error feedback
3534
double maxJointAcceleration = 5.0; ///< Limits joint acceleration
35+
3636
double minManipulability = 1e-04; ///< Threshold for singularity avoidance
3737

3838
unsigned int controlFrequency = 500; ///< Rate at which control loop operates.
@@ -50,6 +50,10 @@ struct SerialLinkParameters
5050
0.0, 0.0, 0.0, 2.0, 0.0, 0.0,
5151
0.0, 0.0, 0.0, 0.0, 2.0, 0.0,
5252
0.0, 0.0, 0.0, 0.0, 0.0, 2.0).finished(); ///< Scales twist error feedback
53+
54+
std::vector<double> jointPositionGains;
55+
56+
std::vector<double> jointVelocityGains;
5357

5458
SolverOptions<double> qpsolver = SolverOptions<double>(); ///< Parameters for the underlying QP solver
5559
};

Control/include/Control/SerialLinkBase.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
* @file SerialLinkBase.h
33
* @author Jon Woolfrey
44
5-
* @date July 2025
6-
* @version 1.1
5+
* @date August 2025
6+
* @version 2.0
7+
*
78
* @brief A base class providing a standardised interface for all serial link robot arm controllers.
89
*
910
* @details This class is designed to provide a standardised structure for all types of serial link
@@ -189,10 +190,6 @@ class SerialLinkBase : public QPSolver<double>
189190

190191
double _controlFrequency = 500.0; ///< Used in certain control calculations.
191192

192-
double _jointPositionGain = 100.0; ///< On position tracking error
193-
194-
double _jointVelocityGain = 20.0; ///< On velocity tracking error
195-
196193
double _manipulability; ///< Proximity to a singularity
197194

198195
double _maxJointAcceleration = 5.0; ///< As it says.
@@ -225,6 +222,10 @@ class SerialLinkBase : public QPSolver<double>
225222

226223
std::shared_ptr<RobotLibrary::Model::KinematicTree> _model; ///< Pointer to the underlying robot model
227224

225+
std::vector<double> _jointPositionGains = {100.0}; ///< Gains for position error of individual joints
226+
227+
std::vector<double> _jointVelocityGains = {20.0}; ///< Gains for velocity error of individual joints
228+
228229
RobotLibrary::Model::Pose _endpointPose; ///< Class denoting position and orientation of endpoint frame
229230

230231
RobotLibrary::Model::ReferenceFrame *_endpointFrame; ///< Pointer to frame controlled in underlying model

Control/include/Control/SerialDynamicControl.h renamed to Control/include/Control/SerialLinkDynamics.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
2-
* @file SerialDynamicControl.h
2+
* @file SerialLinkDynamics.h
33
* @author Jon Woolfrey
44
5-
* @date July 2025
6-
* @version 1.0
5+
* @date August 2025
6+
* @version 2.0
7+
*
78
* @brief Computes joint torques for feedback control of serial link robot arms.
89
*
910
* @details This class contains methods for performing torque control of a serial link robot arm
@@ -18,8 +19,8 @@
1819
* @see https://github.com/Woolfrey/software_simple_qp for the optimisation algorithm used in the control.
1920
*/
2021

21-
#ifndef SERIAL_DYNAMIC_CONTROL_H
22-
#define SERIAL_DYNAMIC_CONTROL_H
22+
#ifndef SERIAL_LINK_DYNAMICS_H
23+
#define SERIAL_LINK_DYNAMICS_H
2324

2425
#include <Control/SerialLinkBase.h>
2526

@@ -30,7 +31,7 @@ namespace RobotLibrary { namespace Control {
3031
/**
3132
* @brief Algorithms for velocity control of a serial link robot arm.
3233
*/
33-
class SerialDynamicControl : public SerialLinkBase
34+
class SerialLinkDynamics : public SerialLinkBase
3435
{
3536
public:
3637
/**
@@ -39,9 +40,9 @@ class SerialDynamicControl : public SerialLinkBase
3940
* @param endpointName The name of the reference frame in the KinematicTree to be controlled.
4041
* @pram parameters Control gains and algorithm parameters.
4142
*/
42-
SerialDynamicControl(std::shared_ptr<RobotLibrary::Model::KinematicTree> model,
43-
const std::string &endpointName,
44-
const RobotLibrary::Control::SerialLinkParameters &parameters = SerialLinkParameters());
43+
SerialLinkDynamics(std::shared_ptr<RobotLibrary::Model::KinematicTree> model,
44+
const std::string &endpointName,
45+
const RobotLibrary::Control::SerialLinkParameters &parameters = SerialLinkParameters());
4546

4647
/**
4748
* @brief Solve the joint torques required to move the endpoint at a given acceleration.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* @file SerialLinkImpedance.h
3+
* @author Jon Woolfrey
4+
5+
* @date August 2025
6+
* @version 1.0
7+
*
8+
* @brief Implements control laws for joint and Cartesian impedance control.
9+
*
10+
* @details This class implements dynamic-free joint and Cartesian impedance control.
11+
* It deliberately avoids the use of the robot inertia because of poor modeling in many
12+
* robot arms. The SerialLinkDynamics should be used if a more accurate model is available.
13+
*
14+
* @copyright (c) 2025 Jon Woolfrey
15+
*
16+
* @license OSCL - Free for non-commercial open-source use only.
17+
* Commercial use requires a license.
18+
*
19+
* @see https://github.com/Woolfrey/software_robot_library for more information.
20+
* @see https://github.com/Woolfrey/software_simple_qp for the optimisation algorithm used in the control.
21+
*/
22+
23+
#ifndef SERIAL_LINK_IMPEDANCE_H
24+
#define SERIAL_LINK_IMPEDANCE_H
25+
26+
#include <Control/SerialLinkBase.h>
27+
28+
#include <memory>
29+
30+
namespace RobotLibrary { namespace Control {
31+
32+
/**
33+
* @brief Algorithms for velocity control of a serial link robot arm.
34+
*/
35+
class SerialLinkImpedance : public SerialLinkBase
36+
{
37+
public:
38+
/**
39+
* @brief Constructor.
40+
* @param model A pointer to a KinematicTree object.
41+
* @param endpointName The name of the reference frame in the KinematicTree to be controlled.
42+
* @pram parameters Control gains and algorithm parameters.
43+
*/
44+
SerialLinkImpedance(std::shared_ptr<RobotLibrary::Model::KinematicTree> model,
45+
const std::string &endpointName,
46+
const RobotLibrary::Control::SerialLinkParameters &parameters = SerialLinkParameters());
47+
48+
/**
49+
* @brief Solve the joint torques required to move the endpoint at a given acceleration.
50+
* @param endpointMotion A vector containing linear & angular acceleration.
51+
* @return A vector of joint torques (nx1)
52+
*/
53+
Eigen::VectorXd
54+
resolve_endpoint_motion(const Eigen::Vector<double,6> &endPointMotion);
55+
56+
/**
57+
* @brief Compute the joint torque required to execute the specified endpoint twist (linear & angular velocity).
58+
This overrides the virtual method defined in the base class.
59+
* @param twist The desired linear & angular velocity, as a 6D vector.
60+
* @return The required joint torque.
61+
*/
62+
Eigen::VectorXd
63+
resolve_endpoint_twist(const Eigen::Vector<double,6> &twist);
64+
65+
/**
66+
* @brief Solve the joint torques required to track a Cartesian trajectory.
67+
* @param desiredPose The desired position & orientation (pose) for the endpoint.
68+
* @param desiredVel The desired linear & angular velocity (twist) for the endpoint.
69+
* @param desiredAcc The desired linear & angular acceleration for the endpoint.
70+
* @return The joint torques (nx1) required to track the trajectory.
71+
*/
72+
Eigen::VectorXd
73+
track_endpoint_trajectory(const RobotLibrary::Model::Pose &desiredPose,
74+
const Eigen::Vector<double,6> &desiredVelocity,
75+
const Eigen::Vector<double,6> &desiredAcceleration);
76+
77+
/**
78+
* @brief Solve the joint torques required to track a joint space trajectory.
79+
* @param desiredPos The desired joint position (nx1).
80+
* @param desiredVel The desired joint velocity (nx1).
81+
* @param desiredAcc The desired joint acceleration (nx1).
82+
* @return The control torque (nx1).
83+
*/
84+
Eigen::VectorXd
85+
track_joint_trajectory(const Eigen::VectorXd &desiredPosition,
86+
const Eigen::VectorXd &desiredVelocity,
87+
const Eigen::VectorXd &desiredAcceleration);
88+
89+
/**
90+
* @brief Convert a desired endpoint wrench to the required joint torques.
91+
* @param wrench A 6x1 vector of forces (3x1) and moments (3x1).
92+
* @return The joint torque (nx1).
93+
*/
94+
Eigen::VectorXd
95+
map_wrench_to_torque(const Eigen::Vector<double,6> &wrench);
96+
97+
/**
98+
* @brief Set the desired configuration for the redundancy.
99+
*/
100+
bool
101+
set_desired_configuration(const Eigen::VectorXd &configuration);
102+
103+
protected:
104+
105+
Eigen::VectorXd _desiredConfiguration; ///< For redundancy
106+
107+
/**
108+
* @brief Compute the instantaneous limits on the joint acceleration control.
109+
* It computes the minimum between joint positions, speed, and acceleration limits.
110+
* @param jointNumber The joint for which to compute the limits.
111+
* @return The upper and lower joint speed at the current time.
112+
*/
113+
RobotLibrary::Model::Limits
114+
compute_control_limits(const unsigned int &jointNumber);
115+
116+
}; // Semicolon needed after a class declaration
117+
118+
} } // namespace
119+
120+
#endif

Control/include/Control/SerialKinematicControl.h renamed to Control/include/Control/SerialLinkKinematics.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
2-
* @file SerialKinematicControl.h
2+
* @file SerialLinkKinematics.h
33
* @author Jon Woolfrey
44
5-
* @date July 2025
6-
* @version 1.1
5+
* @date August 2025
6+
* @version 2.0
7+
*
78
* @brief Computes velocity (position) feedback control for a serial link robot arm.
89
*
910
* @details This class contains methods for performing velocity control of a serial link robot arm
@@ -19,8 +20,8 @@
1920
* @see https://github.com/Woolfrey/software_simple_qp for the optimisation algorithm used in the control.
2021
*/
2122

22-
#ifndef SERIAL_KINEMATIC_CONTROL_H
23-
#define SERIAL_KINEMATIC_CONTROL_H
23+
#ifndef SERIAL_LINK_KINEMATICS_H
24+
#define SERIAL_LINK_KINEMATICS_H
2425

2526
#include <Control/SerialLinkBase.h>
2627

@@ -31,18 +32,17 @@ namespace RobotLibrary { namespace Control {
3132
/**
3233
* @brief Algorithms for velocity control of a serial link robot arm.
3334
*/
34-
class SerialKinematicControl : public SerialLinkBase
35+
class SerialLinkKinematics : public SerialLinkBase
3536
{
3637
public:
3738
/**
3839
* @brief Constructor.
3940
* @param model A pointer to a KinematicTree object.
4041
* @param endpointName The name of the reference frame in the KinematicTree to be controlled.
4142
*/
42-
SerialKinematicControl(std::shared_ptr<RobotLibrary::Model::KinematicTree> model,
43-
const std::string &endpointName,
44-
const RobotLibrary::Control::SerialLinkParameters &parameters = SerialLinkParameters())
45-
: SerialLinkBase(model, endpointName, parameters){}
43+
SerialLinkKinematics(std::shared_ptr<RobotLibrary::Model::KinematicTree> model,
44+
const std::string &endpointName,
45+
const RobotLibrary::Control::SerialLinkParameters &parameters = SerialLinkParameters());
4646

4747
/**
4848
* @brief Solve the joint velocities required to move the endpoint at a given speed.

Control/src/SerialLinkBase.cpp

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
2-
* @file SerialKinematicControl.h
2+
* @file SerialLinkBase.cpp
33
* @author Jon Woolfrey
44
5-
* @date July 2025
6-
* @version 1.1
5+
* @date August 2025
6+
* @version 2.0
7+
*
78
* @brief A base class providing a standardised interface for all serial link robot arm controllers.
89
*
910
* @details This class is designed to provide a standardised structure for all types of serial link
@@ -29,7 +30,7 @@ namespace RobotLibrary { namespace Control {
2930
SerialLinkBase::SerialLinkBase(std::shared_ptr<RobotLibrary::Model::KinematicTree> model,
3031
const std::string &endpointName,
3132
const RobotLibrary::Control::SerialLinkParameters &parameters)
32-
: QPSolver<double>(parameters.qpsolver)
33+
: QPSolver<double>(parameters.qpsolver)
3334
{
3435
_model = model; // Save model internally so we can access it later
3536

@@ -43,20 +44,43 @@ SerialLinkBase::SerialLinkBase(std::shared_ptr<RobotLibrary::Model::KinematicTre
4344
_cartesianPoseGain = parameters.cartesianPoseGain;
4445
_cartesianVelocityGain = parameters.cartesianVelocityGain;
4546
_controlFrequency = parameters.controlFrequency;
46-
_jointPositionGain = parameters.jointPositionGain;
47-
_jointVelocityGain = parameters.jointVelocityGain;
4847
_minManipulability = parameters.minManipulability;
4948
_maxJointAcceleration = parameters.maxJointAcceleration;
5049

50+
// No gains set; use default
51+
if (parameters.jointPositionGains.size() == 0
52+
and parameters.jointVelocityGains.size() == 0)
53+
{
54+
for (int i = 0; i < n; ++i)
55+
{
56+
_jointPositionGains.push_back(100.0);
57+
_jointVelocityGains.push_back( 20.0);
58+
}
59+
}
60+
// Incorrect size
61+
else if (parameters.jointPositionGains.size() != n
62+
or parameters.jointVelocityGains.size() != n)
63+
{
64+
throw std::invalid_argument("[ERROR] [SERIAL LINK BASE] Constructor: "
65+
"Joint position gain, and joint velocity gain vectors had "
66+
+ std::to_string(parameters.jointPositionGains.size()) + " and "
67+
+ std::to_string(parameters.jointVelocityGains.size()) + " elements respectively, but expected "
68+
+ std::to_string(n) + ".");
69+
}
70+
else
71+
{
72+
_jointPositionGains = parameters.jointPositionGains;
73+
_jointVelocityGains = parameters.jointVelocityGains;
74+
}
75+
5176
// Set up the QP solver
5277

5378
// Resize dimensions of inequality constraints for the QP solver: B*qdot < z, where:
5479
//
5580
// B = [ I ] z = [ qdot_max ]
5681
// [ -I ] [ -qdot_min ]
5782
// [ (dm/dq)' ] [ (m - m_min) ]
58-
59-
83+
6084
_constraintMatrix.resize(2*n+1,n);
6185
_constraintMatrix.block(0,0,n,n).setIdentity();
6286
_constraintMatrix.block(n,0,n,n) = -_constraintMatrix.block(0,0,n,n);
@@ -92,11 +116,11 @@ SerialLinkBase::set_redundant_task(const Eigen::VectorXd &task)
92116
{
93117
if (task.size() != _model->number_of_joints())
94118
{
95-
std::cerr << "[ERROR] [SERIAL LINK] set_redundant_task(): "
96-
<< "This robot model has " << _model->number_of_joints() << " joints, "
97-
<< "but you assigned a task with " << task.size() << " elements.\n";
98-
99-
return false;
119+
std::cerr << "[ERROR] [SERIAL LINK] set_redundant_task(): "
120+
<< "This robot model has " << _model->number_of_joints() << " joints, "
121+
<< "but you assigned a task with " << task.size() << " elements.\n";
122+
123+
return false;
100124
}
101125
else
102126
{

0 commit comments

Comments
 (0)