bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
spatial_arm.h
Go to the documentation of this file.
1#ifndef BITSIM_KINEMATICS_SPATIAL_ARM_H
2#define BITSIM_KINEMATICS_SPATIAL_ARM_H
3
4#include "bitsim/bitsim_config.h"
5
6#ifdef BITSIM_CHRONO
7
9
10#include <Eigen/Core>
11#include <chrono/core/ChFrame.h>
12#include <chrono/core/ChVector3.h>
13
14#include <array>
15#include <functional>
16#include <optional>
17#include <vector>
18
19namespace bitsim
20{
21namespace kinematics
22{
23
31{
32 real_t h0{0.3};
33 real_t l1{0.4};
34 real_t l2{0.3};
35};
36
41using SpatialJoints = std::array<real_t, 3>;
42
48std::vector<chrono::ChFrame<>> spatial_fk_all(const SpatialArm &arm, const SpatialJoints &q);
49
54chrono::ChFrame<> spatial_fk(const SpatialArm &arm, const SpatialJoints &q);
55
64std::vector<SpatialJoints> spatial_ik(const SpatialArm &arm, const chrono::ChVector3d &p_W);
65
70std::optional<SpatialJoints> spatial_ik_elbow_up(const SpatialArm &arm,
71 const chrono::ChVector3d &p_W);
72
79
85{
87 int iterations{0};
89 bool converged{false};
90};
91
97using IKObserver = std::function<void(int, const SpatialJoints &, real_t)>;
98
110IKResult numerical_ik(const SpatialArm &arm, const chrono::ChVector3d &target, SpatialJoints q0,
111 real_t damping, int max_iterations = 100, real_t tolerance = 1.0e-6,
112 real_t max_step = 0.5, const IKObserver &observer = {});
113
114} // namespace kinematics
115} // namespace bitsim
116
117#endif // BITSIM_CHRONO
118#endif // BITSIM_KINEMATICS_SPATIAL_ARM_H
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
ChFrame spatial_fk(const SpatialArm &arm, const SpatialJoints &q)
The pose of the end-effector in the world, .
Definition kinematics.cpp:121
std::array< real_t, 3 > SpatialJoints
The angles of the three joints of a SpatialArm [rad].
Definition spatial_arm.h:41
std::vector< ChFrame<> > spatial_fk_all(const SpatialArm &arm, const SpatialJoints &q)
The pose in the world of every joint frame, followed by the end-effector: .
Definition kinematics.cpp:100
std::function< void(int, const SpatialJoints &, real_t)> IKObserver
Called by numerical_ik at every iteration with the iteration, the joint angles and the error [m],...
Definition spatial_arm.h:97
RealMat3d numerical_jacobian(const SpatialArm &arm, const SpatialJoints &q)
The Jacobian of the end-effector's position by central differences. It needs only the forward kinema...
Definition kinematics.cpp:158
Definition denavit_hartenberg.h:18
std::optional< SpatialJoints > spatial_ik_elbow_up(const SpatialArm &arm, const ChVector3d &p_W)
Definition kinematics.cpp:143
std::vector< SpatialJoints > spatial_ik(const SpatialArm &arm, const ChVector3d &p_W)
Definition kinematics.cpp:126
IKResult numerical_ik(const SpatialArm &arm, const ChVector3d &target, SpatialJoints q0, real_t damping, int max_iterations, real_t tolerance, real_t max_step, const IKObserver &observer)
Definition kinematics.cpp:175
Definition dc_motor_backend_base.h:9
Eigen::Matrix3< real_t > RealMat3d
3×3 matrix of type double.
Definition bitsim_types.h:86
double real_t
real_t
Definition bitsim_types.h:20
The result of numerical_ik.
Definition spatial_arm.h:85
real_t error
the distance from the end-effector to the target [m]
Definition spatial_arm.h:88
bool converged
whether the error is below the tolerance
Definition spatial_arm.h:89
int iterations
the iterations it took
Definition spatial_arm.h:87
SpatialJoints q
the joint angles reached [rad]
Definition spatial_arm.h:86
An arm with three revolute joints. Joint 1 turns the arm about the vertical axis at height h0; joints...
Definition spatial_arm.h:31
real_t h0
the height of the shoulder above the floor [m]
Definition spatial_arm.h:32
real_t l2
the forearm [m]
Definition spatial_arm.h:34
real_t l1
the upper arm [m]
Definition spatial_arm.h:33