Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Loading...
Searching...
No Matches
PlanarArmFK.h
1#pragma once
2
3#include "../navtypes.h"
4#include "ForwardArmKinematics.h"
5
6#include <array>
7#include <initializer_list>
8#include <numeric>
9
10#include <Eigen/Core>
11
12namespace kinematics {
13
19template <unsigned int N>
20class PlanarArmFK : public ForwardArmKinematics<2, N> {
21public:
29 PlanarArmFK(const navtypes::Vectord<N>& segLens, const navtypes::Vectord<N>& jointMin,
30 const navtypes::Vectord<N>& jointMax)
31 : segLens(segLens), jointMin(jointMin), jointMax(jointMax) {}
32
33 navtypes::Vectord<N> getSegLens() const override {
34 return segLens;
35 }
36
37 bool satisfiesConstraints(const navtypes::Vectord<N>& jointPos) const override {
38 for (unsigned int i = 0; i < N; i++) {
39 if (jointPos[i] < jointMin[i] || jointPos[i] > jointMax[i]) {
40 return false;
41 }
42 }
43 return true;
44 }
45
46 navtypes::Matrixd<2, N> getJacobian(const navtypes::Vectord<N>& jointPos) const override {
48 std::array<double, N> thetaCumSum;
49 thetaCumSum[0] = jointPos[0];
50 for (unsigned int i = 1; i < N; i++) {
51 thetaCumSum[i] = jointPos[i] + thetaCumSum[i - 1];
52 }
53 for (unsigned int i = 0; i < N; i++) {
54 for (unsigned int j = i; j < N; j++) {
55 jacobian(0, i) += -segLens[j] * std::sin(thetaCumSum[j]);
56 jacobian(1, i) += segLens[j] * std::cos(thetaCumSum[j]);
57 }
58 }
59 return jacobian;
60 }
61
62 Eigen::Vector2d jointPosToEEPos(const navtypes::Vectord<N>& jointPos) const override {
63 Eigen::Vector2d eePos = Eigen::Vector2d::Zero();
64 double accumAngle = 0;
65 for (unsigned int i = 0; i < N; i++) {
66 accumAngle += jointPos[i];
67 Eigen::Vector2d segVec{std::cos(accumAngle), std::sin(accumAngle)};
68 eePos += segLens[i] * segVec;
69 }
70 return eePos;
71 }
72
73private:
74 navtypes::Vectord<N> segLens;
75 navtypes::Vectord<N> jointMin;
76 navtypes::Vectord<N> jointMax;
77};
78
79} // namespace kinematics
complex< _Tp > sin(const complex< _Tp > &)
complex< _Tp > cos(const complex< _Tp > &)
static const ConstantReturnType Zero()
A class that calculates the forward kinematics of an arm.
Definition ForwardArmKinematics.h:16
Eigen::Vector2d jointPosToEEPos(const navtypes::Vectord< N > &jointPos) const override
Given a joint position, calculate the current EE position.
Definition PlanarArmFK.h:62
navtypes::Vectord< N > getSegLens() const override
Get the segment lengths for this arm.
Definition PlanarArmFK.h:33
PlanarArmFK(const navtypes::Vectord< N > &segLens, const navtypes::Vectord< N > &jointMin, const navtypes::Vectord< N > &jointMax)
Construct a new kinematics object.
Definition PlanarArmFK.h:29
navtypes::Matrixd< 2, N > getJacobian(const navtypes::Vectord< N > &jointPos) const override
Get the jacobian matrix for the arm at the given joint angles.
Definition PlanarArmFK.h:46
bool satisfiesConstraints(const navtypes::Vectord< N > &jointPos) const override
Check if the given joint configuration is valid.
Definition PlanarArmFK.h:37