def event(socket, "rotation:hand", %{"x" => x, "y" => y, "z" => z}) do
val = map(x, 0, 180, -1, 1)
Exroboarm.Client.hip(:roboarm, val, 10)
socket
end
def event(socket, "bone_directions:index_finger", %{"first" => first, "second" => second, "third" => third}) do
IO.puts "first: #{inspect first}, second: #{inspect second}, third: #{inspect third}"
Exroboarm.Client.shoulder(:roboarm, first + 90, 10)
Exroboarm.Client.elbow(:roboarm, second, 10)
Exroboarm.Client.wrist(:roboarm, (90 - third), 10)
socket
end
chan.send("rotation:hand", {x: hand.direction[0], y: hand.direction[1], z: hand.direction[2] });
chan.send("bone_directions:index_finger", {
first: bone_angle(hand.fingers[1], 1),
second: bone_angle(hand.fingers[1], 2),
third: bone_angle(hand.fingers[1], 3),
});
That's really all it took, plus some calc2-level trigonometry to get the angle between two vectors (once I figured out what the leap sdk data meant). This took maybe an hour, once I got past some basic broken stuff re: my serial driver being partially broken.