Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions examples/sas_core_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,38 @@
#include <Eigen/Dense>
#include <marinholab/sas/core/sas_core.hpp>

using namespace Eigen;
using namespace marinholab::sas::core;

int main(int,char**)
{
//VectorXd concatenate(const VectorXd& a, const VectorXd& b);
VectorXd a(3); a << 1,2,3;
VectorXd b(3); b << 4,5,6;
VectorXd c(6); c << 1,2,3,4,5,6;
//Eigen::VectorXd concatenate(const Eigen::VectorXd& a, const Eigen::VectorXd& b);
Eigen::VectorXd a(3); a << 1,2,3;
Eigen::VectorXd b(3); b << 4,5,6;
Eigen::VectorXd c(6); c << 1,2,3,4,5,6;
assert((concatenate(a,b)==c));

//VectorXd concatenate(const std::vector<VectorXd>& as);
//Eigen::VectorXd concatenate(const std::vector<Eigen::VectorXd>& as);
auto as = {a,b};
assert((concatenate(as)==c));

//MatrixXd vstack(const MatrixXd& A, const MatrixXd& B);
MatrixXd A(2,2); A << 1,2,3,4;
MatrixXd B(2,2); B << 5,6,7,8;
MatrixXd C(4,2); C << A,B;
//Eigen::MatrixXd vstack(const Eigen::MatrixXd& A, const Eigen::MatrixXd& B);
Eigen::MatrixXd A(2,2); A << 1,2,3,4;
Eigen::MatrixXd B(2,2); B << 5,6,7,8;
Eigen::MatrixXd C(4,2); C << A,B;
assert((vstack(A,B)==C));

//MatrixXd block_diag(const std::vector<MatrixXd>& As);
//Eigen::MatrixXd block_diag(const std::vector<Eigen::MatrixXd>& As);
auto As = {A,B};
MatrixXd C_block_diag(4,4); C_block_diag << A,MatrixXd::Zero(2,2),MatrixXd::Zero(2,2),B;
Eigen::MatrixXd C_block_diag(4,4); C_block_diag << A,Eigen::MatrixXd::Zero(2,2),Eigen::MatrixXd::Zero(2,2),B;
assert((block_diag(As)==C_block_diag));

//std::vector<VectorXd> split(const VectorXd& a, const std::vector<int>& ns);
VectorXd a_split(10); a_split << 1,2,3,4,5,6,7,8,9,10;
//std::vector<Eigen::VectorXd> split(const Eigen::VectorXd& a, const std::vector<int>& ns);
Eigen::VectorXd a_split(10); a_split << 1,2,3,4,5,6,7,8,9,10;
std::vector<int> ns = {2,5,3};
auto split_result = split(a_split,ns);
assert((split_result[0]==(VectorXd(2)<<1,2).finished()));
assert((split_result[1]==(VectorXd(5)<<3,4,5,6,7).finished()));
assert((split_result[2]==(VectorXd(3)<<8,9,10).finished()));
assert((split_result[0]==(Eigen::VectorXd(2)<<1,2).finished()));
assert((split_result[1]==(Eigen::VectorXd(5)<<3,4,5,6,7).finished()));
assert((split_result[2]==(Eigen::VectorXd(3)<<8,9,10).finished()));

return 0;
}
4 changes: 2 additions & 2 deletions examples/sas_robot_driver_example_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int,char**)

auto configuration = marinholab::sas::core::RobotDriverExampleConfiguration();
configuration.name = "Example_Robot_123";
configuration.initial_joint_positions = VectorXd::Random(7);
configuration.initial_joint_positions = Eigen::VectorXd::Random(7);

auto robot_driver_example = marinholab::sas::core::RobotDriverExample(configuration, shutdown_signaler);

Expand All @@ -55,7 +55,7 @@ int main(int,char**)

std::cout << "Initial joint positions: " << robot_driver_example.get_joint_positions().transpose() << std::endl;

VectorXd target_joint_positions = VectorXd::Random(7);
Eigen::VectorXd target_joint_positions = Eigen::VectorXd::Random(7);
std::cout << "Target joint positions: " << target_joint_positions.transpose() << std::endl;

robot_driver_example.set_target_joint_positions(target_joint_positions);
Expand Down
13 changes: 6 additions & 7 deletions include/marinholab/sas/core/eigen3_std_conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include<Eigen/Dense>
#include<dqrobotics/DQ.h>

using namespace Eigen;
using namespace DQ_robotics;

namespace marinholab::sas::core
Expand All @@ -45,28 +44,28 @@ namespace marinholab::sas::core
* @param vectorxd Source Eigen vector.
* @return std::vector<double> containing the same elements in order.
*/
std::vector<double> vectorxd_to_std_vector_double(const VectorXd& vectorxd);
std::vector<double> vectorxd_to_std_vector_double(const Eigen::VectorXd& vectorxd);

/**
* @brief Convert an Eigen::VectorXi to a std::vector<int>.
* @param vectorxi Source Eigen integer vector.
* @return std::vector<int> containing the same elements in order.
*/
std::vector<int> vectorxi_to_std_vector_int(const VectorXi& vectorxi);
std::vector<int> vectorxi_to_std_vector_int(const Eigen::VectorXi& vectorxi);

/**
* @brief Convert a std::vector<double> to an Eigen::VectorXd.
* @param std_vector_double Source std::vector<double>.
* @return VectorXd containing the same elements.
* @return Eigen::VectorXd containing the same elements.
*/
VectorXd std_vector_double_to_vectorxd(std::vector<double> std_vector_double);
Eigen::VectorXd std_vector_double_to_vectorxd(std::vector<double> std_vector_double);

/**
* @brief Convert a std::vector<int> to an Eigen::VectorXi.
* @param std_vector_int Source std::vector<int>.
* @return VectorXi containing the same elements.
* @return Eigen::VectorXi containing the same elements.
*/
VectorXi std_vector_int_to_vectorxi(std::vector<int> std_vector_int);
Eigen::VectorXi std_vector_int_to_vectorxi(std::vector<int> std_vector_int);

/**
* @brief Convert a std::vector<double> to a DQ (dual quaternion) object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include <marinholab/sas/core/sas_robot_driver.hpp>
#include <Eigen/Dense>

using namespace Eigen;

namespace marinholab::sas::core
{
Expand All @@ -48,8 +47,8 @@ namespace marinholab::sas::core
struct RobotDriverExampleConfiguration
{
std::string name;
VectorXd initial_joint_positions;
std::tuple<VectorXd,VectorXd> joint_limits;
Eigen::VectorXd initial_joint_positions;
std::tuple<Eigen::VectorXd,Eigen::VectorXd> joint_limits;
};

/**
Expand All @@ -63,7 +62,7 @@ struct RobotDriverExampleConfiguration
{
protected:
const RobotDriverExampleConfiguration configuration_;
VectorXd joint_positions_;
Eigen::VectorXd joint_positions_;

public:
RobotDriverExample(RobotDriverExample&) = delete;
Expand All @@ -82,14 +81,14 @@ struct RobotDriverExampleConfiguration
* @brief Get the current joint positions
* @return Vector of joint positions (radians)
*/
virtual VectorXd get_joint_positions() override;
virtual Eigen::VectorXd get_joint_positions() override;

/**
* @brief Set target joint positions
* @param set_target_joint_positions_rad Target joint positions in radians
* @throws std::runtime_error if the input vector has incorrect size
*/
virtual void set_target_joint_positions(const VectorXd& set_target_joint_positions_rad) override;
virtual void set_target_joint_positions(const Eigen::VectorXd& set_target_joint_positions_rad) override;

/**
* @brief Connect the example driver (establish resources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace marinholab::sas::core::modeling
{

// The dqrobotics types this model builds on. (The Eigen types used in the
// signatures, e.g. MatrixXd/VectorXd, are injected into the global namespace
// signatures, e.g. Eigen::MatrixXd/Eigen::VectorXd, are injected into the global namespace
// by the dqrobotics headers.)
using DQ_robotics::DQ;
using DQ_robotics::DQ_SerialManipulator;
Expand Down Expand Up @@ -106,22 +106,22 @@ class SerialManipulatorSimulatorFriendly: public DQ_SerialManipulator
* @param to_ith_link Index of the terminal link.
* @return An 8 x (to_ith_link+1) dual-quaternion pose Jacobian.
*/
MatrixXd raw_pose_jacobian(const VectorXd& q_vec, const int& to_ith_link) const override;
Eigen::MatrixXd raw_pose_jacobian(const Eigen::VectorXd& q_vec, const int& to_ith_link) const override;
/**
* @brief Time derivative of the raw pose Jacobian.
* @param q Joint configuration vector.
* @param q_dot Joint velocity vector.
* @param to_ith_link Index of the terminal link.
* @return An 8 x (to_ith_link+1) Jacobian-derivative matrix.
*/
MatrixXd raw_pose_jacobian_derivative(const VectorXd& q, const VectorXd& q_dot, const int& to_ith_link) const override;
Eigen::MatrixXd raw_pose_jacobian_derivative(const Eigen::VectorXd& q, const Eigen::VectorXd& q_dot, const int& to_ith_link) const override;
/**
* @brief Raw forward kinematics of the chain up to a given link.
* @param q_vec Joint configuration vector.
* @param to_ith_link Index of the terminal link.
* @return The dual-quaternion pose of the terminal link.
*/
DQ raw_fkm(const VectorXd &q_vec, const int &to_ith_link) const override;
DQ raw_fkm(const Eigen::VectorXd &q_vec, const int &to_ith_link) const override;
};

}
13 changes: 6 additions & 7 deletions include/marinholab/sas/core/sas_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#include <Eigen/Dense>

using namespace Eigen;

namespace marinholab::sas::core
{
Expand Down Expand Up @@ -73,14 +72,14 @@ constexpr T incremental_mean(const T &current_mean, const int &current_number_of
* @param b Second vector.
* @return Concatenated vector containing all elements of a followed by b.
*/
VectorXd concatenate(const VectorXd& a, const VectorXd& b);
Eigen::VectorXd concatenate(const Eigen::VectorXd& a, const Eigen::VectorXd& b);

/**
* @brief Concatenate a list of vectors into a single vector.
* @param as Vector of vectors to concatenate in order.
* @return Concatenated vector containing the elements of each input vector in order.
*/
VectorXd concatenate(const std::vector<VectorXd>& as);
Eigen::VectorXd concatenate(const std::vector<Eigen::VectorXd>& as);

/**
* @brief Stack two matrices vertically (A above B).
Expand All @@ -89,21 +88,21 @@ VectorXd concatenate(const std::vector<VectorXd>& as);
* @return Matrix formed by stacking A on top of B. Columns must match.
* @throws std::range_error if A and B have different numbers of columns.
*/
MatrixXd vstack(const MatrixXd& A, const MatrixXd& B);
Eigen::MatrixXd vstack(const Eigen::MatrixXd& A, const Eigen::MatrixXd& B);

/**
* @brief Create a block-diagonal matrix from a list of matrices.
* @param As Vector of matrices to place on the block diagonal.
* @return Block-diagonal matrix containing the input matrices along its diagonal.
*/
MatrixXd block_diag(const std::vector<MatrixXd>& As);
Eigen::MatrixXd block_diag(const std::vector<Eigen::MatrixXd>& As);

/**
* @brief Split a vector into pieces with sizes specified by ns.
* @param a Vector to split.
* @param ns Sizes of each piece; their sum must equal a.size().
* @return Vector containing the split VectorXd pieces.
* @return Vector containing the split Eigen::VectorXd pieces.
*/
std::vector<VectorXd> split(const VectorXd& a, const std::vector<int>& ns);
std::vector<Eigen::VectorXd> split(const Eigen::VectorXd& a, const std::vector<int>& ns);

}
23 changes: 11 additions & 12 deletions include/marinholab/sas/core/sas_robot_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include <marinholab/sas/core/sas_clock.hpp>
#include <Eigen/Dense>

using namespace Eigen;

namespace marinholab::sas::core
{
Expand All @@ -61,9 +60,9 @@ class RobotDriver
protected:
std::atomic_bool* break_loops_; //Deprecated
std::shared_ptr<ShutdownSignaler> shutdown_signaler_;
std::tuple<VectorXd, VectorXd> joint_limits_;
VectorXd joint_velocities_;
VectorXd joint_torques_;
std::tuple<Eigen::VectorXd, Eigen::VectorXd> joint_limits_;
Eigen::VectorXd joint_velocities_;
Eigen::VectorXd joint_torques_;

std::unique_ptr<marinholab::sas::core::Clock> clock_;
std::unique_ptr<std::thread> watchdog_thread_;
Expand Down Expand Up @@ -111,53 +110,53 @@ class RobotDriver
* @brief Get current joint positions
* @return Vector of joint positions (radians)
*/
virtual VectorXd get_joint_positions() = 0;
virtual Eigen::VectorXd get_joint_positions() = 0;

/**
* @brief Set target joint positions
* @param set_target_joint_positions_rad Target joint positions (radians)
*/
virtual void set_target_joint_positions(const VectorXd& set_target_joint_positions_rad) = 0;
virtual void set_target_joint_positions(const Eigen::VectorXd& set_target_joint_positions_rad) = 0;

/**
* @brief Get current joint velocities
* @return Vector of joint velocities
* @throws std::runtime_error if the default implementation is called (not implemented by derived driver)
*/
virtual VectorXd get_joint_velocities();
virtual Eigen::VectorXd get_joint_velocities();

/**
* @brief Set target joint velocities
* @param set_target_joint_velocities Target joint velocities
* @throws std::runtime_error if the default implementation is called (not implemented by derived driver)
*/
virtual void set_target_joint_velocities(const VectorXd& set_target_joint_velocities);
virtual void set_target_joint_velocities(const Eigen::VectorXd& set_target_joint_velocities);

/**
* @brief Get current joint torques
* @return Vector of joint torques
* @throws std::runtime_error if the default implementation is called (not implemented by derived driver)
*/
virtual VectorXd get_joint_torques();
virtual Eigen::VectorXd get_joint_torques();

/**
* @brief Set target joint torques
* @param set_target_joint_torques Target joint torques
* @throws std::runtime_error if the default implementation is called (not implemented by derived driver)
*/
virtual void set_target_joint_torques(const VectorXd& set_target_joint_torques);
virtual void set_target_joint_torques(const Eigen::VectorXd& set_target_joint_torques);

/**
* @brief Get joint limits (min, max)
* @return Tuple of (min_limits, max_limits)
*/
virtual std::tuple<VectorXd, VectorXd> get_joint_limits();
virtual std::tuple<Eigen::VectorXd, Eigen::VectorXd> get_joint_limits();

/**
* @brief Set joint limits (min, max)
* @param joint_limits Tuple of (min_limits, max_limits)
*/
virtual void set_joint_limits(const std::tuple<VectorXd, VectorXd>& joint_limits);
virtual void set_joint_limits(const std::tuple<Eigen::VectorXd, Eigen::VectorXd>& joint_limits);

/**
* @brief Start the watchdog thread with the given period
Expand Down
8 changes: 4 additions & 4 deletions src/eigen3_std_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
namespace marinholab::sas::core
{

std::vector<double> vectorxd_to_std_vector_double(const VectorXd& vectorxd)
std::vector<double> vectorxd_to_std_vector_double(const Eigen::VectorXd& vectorxd)
{
std::vector<double> vec(vectorxd.data(), vectorxd.data() + vectorxd.rows() * vectorxd.cols());
return vec;
}

VectorXd std_vector_double_to_vectorxd(std::vector<double> std_vector_double)
Eigen::VectorXd std_vector_double_to_vectorxd(std::vector<double> std_vector_double)
{
double* ptr = &std_vector_double[0];
Eigen::Map<Eigen::VectorXd> vec(ptr,std_vector_double.size()); //We need access to the pointer here so we cannot use const ref
Expand All @@ -49,13 +49,13 @@ DQ std_vector_double_to_dq(const std::vector<double> &std_vector_double)
return DQ(std_vector_double_to_vectorxd(std_vector_double));
}

std::vector<int> vectorxi_to_std_vector_int(const VectorXi &vectorxi)
std::vector<int> vectorxi_to_std_vector_int(const Eigen::VectorXi &vectorxi)
{
std::vector<int> vec(vectorxi.data(), vectorxi.data() + vectorxi.rows() * vectorxi.cols());
return vec;
}

VectorXi std_vector_int_to_vectorxi(std::vector<int> std_vector_int)
Eigen::VectorXi std_vector_int_to_vectorxi(std::vector<int> std_vector_int)
{
int* ptr = &std_vector_int[0];
Eigen::Map<Eigen::VectorXi> vec(ptr,std_vector_int.size()); //We need access to the pointer here so we cannot use const ref
Expand Down
Loading
Loading