Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added handler for inverse kinematics special case joint request #240

Merged
merged 66 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
f99d5ae
Added special case for inverse kinematics
Geeoon May 9, 2023
8e97608
Reformat
Geeoon May 16, 2023
e0170e8
Added special case for inverse kinematics
Geeoon May 9, 2023
d5ed1a5
Reformat
Geeoon May 16, 2023
a1d88f7
Added ik global
Geeoon May 16, 2023
03e9c08
Merge branch 'inverse-kinematics-requests' of https://github.com/husk…
Geeoon May 16, 2023
df5d3ba
Renamed arm IK global. made type atomic as well
Geeoon May 17, 2023
b9a89ac
Added armIKEnabled handler and validater
Geeoon May 17, 2023
60d5cd4
Added case for when armIK global is enabled/disabled
Geeoon May 17, 2023
2b75bbe
Fixed build error
Geeoon May 17, 2023
650afcd
Fixed formatting error
Geeoon May 17, 2023
e982ddb
Removed redundant code
Geeoon May 19, 2023
23a3ad6
Set armIKEnabled to false on e stop and connect
Geeoon May 19, 2023
d835d89
Fixed build error
Geeoon May 19, 2023
dc89f9f
Merge remote-tracking branch 'origin' into inverse-kinematics-requests
Geeoon May 20, 2023
ab142c5
Proper namespace for validateKey
Geeoon May 20, 2023
63820f6
Added special case for inverse kinematics
Geeoon May 9, 2023
f1a7df4
Reformat
Geeoon May 16, 2023
4397e15
Added ik global
Geeoon May 16, 2023
4722f2a
Renamed arm IK global. made type atomic as well
Geeoon May 17, 2023
f9082f3
Added armIKEnabled handler and validater
Geeoon May 17, 2023
012e19b
Added case for when armIK global is enabled/disabled
Geeoon May 17, 2023
0741dee
Fixed build error
Geeoon May 17, 2023
3b36cc8
Fixed formatting error
Geeoon May 17, 2023
4a014c0
Removed redundant code
Geeoon May 19, 2023
be99adf
Set armIKEnabled to false on e stop and connect
Geeoon May 19, 2023
320540c
Fixed build error
Geeoon May 19, 2023
885fa66
Proper namespace for validateKey
Geeoon May 20, 2023
c23918b
Merge branch 'inverse-kinematics-requests' of https://github.com/husk…
Geeoon May 22, 2023
389960e
Added special case for inverse kinematics
Geeoon May 9, 2023
d3f9ee8
Reformat
Geeoon May 16, 2023
49bffe0
Added ik global
Geeoon May 16, 2023
3ac206c
Renamed arm IK global. made type atomic as well
Geeoon May 17, 2023
d3fd8c5
Added armIKEnabled handler and validater
Geeoon May 17, 2023
70bf96a
Added case for when armIK global is enabled/disabled
Geeoon May 17, 2023
b0a4ff3
Fixed build error
Geeoon May 17, 2023
f220de6
Fixed formatting error
Geeoon May 17, 2023
93ed75b
Removed redundant code
Geeoon May 19, 2023
edb6b2d
Set armIKEnabled to false on e stop and connect
Geeoon May 19, 2023
3e6dc42
Fixed build error
Geeoon May 19, 2023
23fb7df
Proper namespace for validateKey
Geeoon May 20, 2023
7ac3c1a
Added armIKEnabled handler and validater
Geeoon May 17, 2023
8a36a39
Added case for when armIK global is enabled/disabled
Geeoon May 17, 2023
f0892ed
Fixed build error
Geeoon May 17, 2023
387f9a4
Fixed formatting error
Geeoon May 17, 2023
72ac754
Removed redundant code
Geeoon May 19, 2023
0ecf91b
Proper namespace for validateKey
Geeoon May 20, 2023
6e52f8d
rebase
Geeoon Jun 1, 2023
c1ada24
removed old bool for arm ik enabled
Geeoon Jun 1, 2023
bbb925f
Set setpoint to current ee position on ik enable
Geeoon Jun 1, 2023
86eeb8c
Reformat and crash on no valid data
Geeoon Jun 2, 2023
dbe102a
Reformat
Geeoon Jun 2, 2023
7f3311d
Added updateArmThread
Geeoon Jun 2, 2023
2c22390
Reformat
Geeoon Jun 2, 2023
09d7df7
fix more things
Geeoon Jun 2, 2023
7eeaede
Added scalar to velocity set
Geeoon Jun 3, 2023
e78986a
Addressed some PR comments
Geeoon Jun 3, 2023
350087a
Reformat
Geeoon Jun 3, 2023
a16b9de
Addressed PR comments
Geeoon Jun 3, 2023
1c0355f
Reformat
Geeoon Jun 3, 2023
b012e30
Merge remote-tracking branch 'origin' into inverse-kinematics-requests
Geeoon Jun 3, 2023
9ee7d0a
Addressed PR comments
Geeoon Jun 3, 2023
0a0e67a
fix formatting
abhaybd Jun 4, 2023
d71ae6a
Addressed PR comments
Geeoon Jun 4, 2023
6354a89
Merge remote-tracking branch 'origin' into inverse-kinematics-requests
Geeoon Jun 4, 2023
25cd2f6
Reformat
Geeoon Jun 4, 2023
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
35 changes: 22 additions & 13 deletions src/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,9 @@ namespace video {
constexpr int H264_RF_CONSTANT = 40;
} // namespace video

// Arm inverse kinematics
namespace arm {

constexpr double MAX_EE_VEL = 0.3; // m/s
constexpr double IK_SOLVER_THRESH = 0.001;

constexpr int IK_SOLVER_MAX_ITER = 50;

/**
* A map that pairs each of the joints to its corresponding motor.
*/
constexpr frozen::unordered_map<robot::types::jointid_t, robot::types::motorid_t, 7>
JOINT_MOTOR_MAP{{robot::types::jointid_t::armBase, robot::types::motorid_t::armBase},
{robot::types::jointid_t::shoulder, robot::types::motorid_t::shoulder},
Expand All @@ -149,21 +144,35 @@ constexpr frozen::unordered_map<robot::types::jointid_t, robot::types::motorid_t
{robot::types::jointid_t::activeSuspension,
robot::types::motorid_t::activeSuspension}};

// Arm inverse kinematics
namespace arm {

/**
* Maximum commanded end-effector velocity, in m/s
*/
constexpr double MAX_EE_VEL = 0.3;
constexpr double IK_SOLVER_THRESH = 0.001;

constexpr int IK_SOLVER_MAX_ITER = 50;

/**
* The joints corresponding to the motors used for IK in the arm. The ordering in this array is
* the canonical ordering of these joints for IK purposes.
*/
constexpr std::array<robot::types::jointid_t, 2> IK_MOTOR_JOINTS = {
robot::types::jointid_t::shoulder, robot::types::jointid_t::elbow};

/**
* The motors used in IK. The ordering in this array is the canonical ordering of these motors
* for IK purposes.
* The motors used in IK. The i-th element in this array corresponds to the joint in the i-th
* element of `IK_MOTOR_JOINTS`
*/
constexpr std::array<robot::types::motorid_t, 2> IK_MOTORS = []() constexpr {
constexpr std::array<robot::types::motorid_t, 2> IK_MOTORS = ([]() constexpr {
std::array<robot::types::motorid_t, IK_MOTOR_JOINTS.size()> ret{};
for (size_t i = 0; i < IK_MOTOR_JOINTS.size(); i++) {
ret[i] = JOINT_MOTOR_MAP.at(IK_MOTOR_JOINTS[i]);
}
return ret;
}
();
})();

/**
* Map from motor ids to min and max joint limits in millidegrees
Expand Down
2 changes: 1 addition & 1 deletion src/network/MissionControlProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ void MissionControlProtocol::handleDriveRequest(const json& j) {

void MissionControlProtocol::handleSetArmIKEnabled(const json& j) {
bool enabled = j["enabled"];
Globals::armIKEnabled = enabled;
if (enabled) {
Globals::armIKEnabled = false;
if (_arm_ik_repeat_thread.joinable()) {
Expand All @@ -148,6 +147,7 @@ void MissionControlProtocol::handleSetArmIKEnabled(const json& j) {
_arm_ik_repeat_thread =
std::thread(&MissionControlProtocol::updateArmIKRepeatTask, this);
} else {
Globals::armIKEnabled = false;
if (_arm_ik_repeat_thread.joinable()) {
_arm_ik_repeat_thread.join();
}
Expand Down
19 changes: 9 additions & 10 deletions src/world_interface/kinematic_common_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void setJointPower(robot::types::jointid_t joint, double power) {

void setJointPos(robot::types::jointid_t joint, int32_t targetPos) {
using robot::types::jointid_t;
if (Constants::arm::JOINT_MOTOR_MAP.find(joint) != Constants::arm::JOINT_MOTOR_MAP.end()) {
setMotorPos(Constants::arm::JOINT_MOTOR_MAP.at(joint), targetPos);
if (Constants::JOINT_MOTOR_MAP.find(joint) != Constants::JOINT_MOTOR_MAP.end()) {
setMotorPos(Constants::JOINT_MOTOR_MAP.at(joint), targetPos);
}
// FIXME: need to do some extra control (probably implementing our own PID control) for the
// differential position, since the potentiometers are giving us joint position instead of
Expand All @@ -126,8 +126,8 @@ void setJointPos(robot::types::jointid_t joint, int32_t targetPos) {
}
}
types::DataPoint<int32_t> getJointPos(robot::types::jointid_t joint) {
if (Constants::arm::JOINT_MOTOR_MAP.find(joint) != Constants::arm::JOINT_MOTOR_MAP.end()) {
return getMotorPos(Constants::arm::JOINT_MOTOR_MAP.at(joint));
if (Constants::JOINT_MOTOR_MAP.find(joint) != Constants::JOINT_MOTOR_MAP.end()) {
return getMotorPos(Constants::JOINT_MOTOR_MAP.at(joint));
}
// FIXME: need to do some extra work for differential - we will have to figure out which
// motor boards the potentiometers are plugged into and query those for "motor position"
Expand Down Expand Up @@ -162,12 +162,11 @@ double getJointPowerValue(types::jointid_t joint) {

void setJointMotorPower(robot::types::jointid_t joint, double power) {
using robot::types::jointid_t;
if (Constants::arm::JOINT_MOTOR_MAP.find(joint) != Constants::arm::JOINT_MOTOR_MAP.end()) {
// TODO: check if associated motor is in IK_MOTORS, don't check specifically these ones
if (!Globals::armIKEnabled ||
!std::find(Constants::arm::IK_MOTOR_JOINTS.begin(),
Constants::arm::IK_MOTOR_JOINTS.end(), joint)) {
setMotorPower(Constants::arm::JOINT_MOTOR_MAP.at(joint), power);
if (Constants::JOINT_MOTOR_MAP.find(joint) != Constants::JOINT_MOTOR_MAP.end()) {
bool isIKMotor = std::find(Constants::arm::IK_MOTOR_JOINTS.begin(),
Constants::arm::IK_MOTOR_JOINTS.end(), joint);
Geeoon marked this conversation as resolved.
Show resolved Hide resolved
if (!Globals::armIKEnabled || !isIKMotor) {
setMotorPower(Constants::JOINT_MOTOR_MAP.at(joint), power);
}
} else if (joint == jointid_t::ikForward || joint == jointid_t::ikUp) {
if (Globals::armIKEnabled) {
Expand Down