Haptic Controller
Loading...
Searching...
No Matches
haptic_thumb.hpp
Go to the documentation of this file.
1#pragma once
2#include <math.h>
3#include "wiring.h"
4#include "utils/angles.hpp"
5#include <vector>
6#include "utils/helpers.hpp"
7#include "utils/matrix.hpp"
8// #include "utils/vector.hpp"
9
10// mcp_pulley = 1.17
11// idler = 0.575
12// mcp_motor = 0.333
13// cmc_plate = 2.322
14// cmc_motor = 0.472
15
16// t_0 = cmc_motor / cmc_plate = 0.2032
17// t_1 = mcp_motor / idler = 0.5791
18// t_2 = mcp_motor / idler * idler/ mcp_pulley = 0.2846
19
21static constexpr float link_0_length = 0.047625;
22static constexpr float link_0_height = 0.0392455;
23static constexpr float link_1_length = 0.060832;
24static constexpr float link_1_height = 0.039189;
25
27static constexpr float transmission_0 = 0.2032;
28static constexpr float transmission_1 = -0.5791 * transmission_0;
29static constexpr float transmission_2 = -0.2846;
30
31static constexpr float operator_origin_x = 0.0;
32static constexpr float operator_origin_y = 0.0;
33static constexpr float operator_origin_z = -0.05;
34
35// Transmission Matrix
36// [ t_0, 0 ]
37// [ ?? , t_1 ]
38
41static constexpr Limits<float> joint_0_limits{0.0, 70.0};
44static constexpr Limits<float> joint_1_limits{0.0, 80.0};
45
46static constexpr Limits<float> joint_0_soft_limits = convert_angular_units(
47 {0.0, 70.0},
50
51static constexpr Limits<float> joint_1_soft_limits = convert_angular_units(
52 {0.0, 80.0},
55
56static constexpr float joint_0_cali_offset = convert_angular_units(
59static constexpr float joint_1_cali_offset = convert_angular_units(
62
63static constexpr Limits<float> joint_0_vel_limits{-10.0, 10.0};
64static constexpr Limits<float> joint_1_vel_limits{-10.0, 10.0};
65
66static constexpr float motor_torque_limit = 5.0f; // N*m
67
71std::vector<float> forward_kinematics(std::vector<float> joint_angles)
72{
73 const auto theta_0 = joint_angles.at(0);
74 const auto theta_1 = joint_angles.at(1);
75
76 const auto x = operator_origin_x +
77 (link_0_length + link_1_length * cos(theta_1) - link_1_height * sin(theta_1)) * cos(theta_0);
78 const auto y = operator_origin_y +
79 (link_0_length + link_1_length * cos(theta_1) - link_1_height * sin(theta_1)) * sin(theta_0);
80 const auto z = operator_origin_z + link_0_height - link_1_length * sin(theta_1) - link_1_height * cos(theta_1);
81
82 return {x, y, z};
83}
84
85// /// @brief Performs inverse kinematics for the robot thumb.
86// /// @note Enforces joint coupling.
87// /// @param pos {x, y, z} in meters of the end effector.
88// /// @returns {theta_0, theta_1, theta_2} of the joints in radians required to move to the location.
89// std::vector<float> inverse_kinematics(std::vector<float> pos)
90// {
91// const auto x = pos.at(0);
92// const auto y = pos.at(1);
93// const auto z = pos.at(2);
94
95// const auto theta_0 = std::atan2(y, x);
96
97// const auto radius = x * x + y * y + z * z;
98// const auto theta_1 = std::acos(radius - link_1_length * link_1_length - link_2_length * link_2_length) /
99// ( 2 * link_1_length * link_2_length);
100
101// return {theta_0, theta_1, theta_1};
102// }
103
104std::vector<float> motors_to_joints(std::vector<float> motor_vars)
105{
106 const auto phi_0 = motor_vars.at(0);
107 const auto phi_1 = motor_vars.at(1);
108
109 const auto theta_0 = phi_0 * transmission_0;
110 const auto theta_1 = phi_0 * transmission_1 + phi_1 * transmission_2;
111
112 return {theta_0, theta_1};
113}
114
115std::vector<float> joints_to_motors(std::vector<float> joint_vars)
116{
117 const auto theta_0 = joint_vars.at(0);
118 const auto theta_1 = joint_vars.at(1);
119
120 const auto phi_0 = theta_0 / transmission_0;
121 const auto phi_1 = -transmission_1 / (transmission_0 * transmission_2) * theta_0 + theta_1 / transmission_2;
122 return {phi_0, phi_1};
123}
124
125std::vector<float> phi_to_theta(std::vector<float> motor_phis)
126{
127 auto joint_thetas = motors_to_joints(motor_phis);
128 joint_thetas.at(0) += joint_0_cali_offset;
129 joint_thetas.at(1) += joint_1_cali_offset;
130 return joint_thetas;
131}
132
133std::vector<float> theta_to_phi(std::vector<float> joint_thetas)
134{
135 joint_thetas.at(0) -= joint_0_cali_offset;
136 joint_thetas.at(1) -= joint_1_cali_offset;
138}
139
140std::vector<float> tau_to_torque(std::vector<float> joint_taus)
141{
142 const auto tau_0 = joint_taus.at(0);
143 const auto tau_1 = joint_taus.at(1);
144
145 const auto torque_0 = tau_0 * transmission_0 + tau_1 * transmission_1;
146 const auto torque_1 = tau_1 * transmission_2;
147
148 return {torque_0, torque_1};
149}
150
151std::vector<float> torque_to_tau(std::vector<float> motor_torques)
152{
153 const auto torque_0 = motor_torques.at(0);
154 const auto torque_1 = motor_torques.at(1);
155
156 const auto tau_0 = torque_0 / transmission_0 -torque_1 * transmission_1 / (transmission_0 * transmission_2);
157 const auto tau_1 = torque_1 / transmission_2;
158
159 return {tau_0, tau_1};
160}
161
163{
164 return Matrix();
165}
166
167std::vector<float> soft_limit_torques(std::vector<float> joint_thetas)
168{
169 static constexpr float discouraging_stiffness = 0.0f;
170 float joint_0_d_t = -discouraging_stiffness * joint_0_soft_limits.over_limits(joint_thetas.at(0));
171 float joint_1_d_t = -discouraging_stiffness * joint_1_soft_limits.over_limits(joint_thetas.at(1));
172
173 return {0.0, 0.0};
174}
constexpr float convert_angular_units(float ang, const AngleUnits curr_unit, const AngleUnits desr_unit)
Converts an angle from one unit to another.
Definition angles.hpp:18
@ RADIANS
Definition angles.hpp:9
@ DEGREES
Definition angles.hpp:10
Class that treats a std::vector as a matrix and implements simple operations.
Definition matrix.hpp:8
std::vector< float > motors_to_joints(std::vector< float > motor_vars)
std::vector< float > phi_to_theta(std::vector< float > motor_phis)
Matrix spatial_jacobian(std::vector< float > joint_thetas)
std::vector< float > theta_to_phi(std::vector< float > joint_thetas)
std::vector< float > torque_to_tau(std::vector< float > motor_torques)
std::vector< float > joints_to_motors(std::vector< float > joint_vars)
std::vector< float > tau_to_torque(std::vector< float > joint_taus)
std::vector< float > forward_kinematics(std::vector< float > joint_angles)
Performs forward kinematics for the robot thumb.
std::vector< float > soft_limit_torques(std::vector< float > joint_thetas)
std::vector< float > joint_thetas
Definition main.cpp:70
Limit struct to store upper and lower limits.
Definition helpers.hpp:34
T over_limits(T compare) const
Definition helpers.hpp:38