Robotics-- an open-source module for easier joint kinematics [0.1.2]

I’ve started work on a module which allows the construction and manipulation of objects with an arbitrary number of joints and an end effector. Though it’s still by all means a work in progress, I’ve managed to create a function which automates the process of moving a target towards an end effector. In publishing it here, I intend to expose it so that you guys can give feedback as to what I can fix, and what I can add to this library.

The neat thing about this is that the only thing that the front-end user needs to do is specify the weld CFrames, with the option of setting constraints on ranges of motion. Thus, if you have a rudimentary understanding of welds, then you can most certainly use this module. You can see it in action at this link: http://www.roblox.com/Jointed-automatic-robot-arm-WIP-place?id=178795382

It seems quite advanced, but aside from the module itself, the code needed to carry that out was rather minimal:

[code]local Robotics = require(game.ServerScriptService.Robotics);

– making the arm
local bin = script.Parent;
local eff = bin.effector;
local w0 = Robotics.MakeWeld(bin.Base, bin.Joint0, );
local w1 = Robotics.MakeWeld(bin.Arm2, eff, );
local joint0 = Robotics.MakeBallJoint(bin.Joint0, bin.Arm0, <weld/joint arguments>);
local joint1 = Robotics.MakeHingeJoint(bin.Arm0, bin.Arm1, <weld/joint arguments>);
local joint2 = Robotics.MakePivotJoint(bin.Arm1, bin.Arm2, <weld/joint arguments>);
local MachineArm = Robotics.MakeChain(eff, joint0, joint1, joint2);[/code]

Now, in order to move my end effector to a given position, I need only a simple loop, along with a few extra lines of code:

while (eff.Position-target).magnitude>1 and running do local e = eff.Position; local delta = target-e; local dt = wait(); local de = delta.unit*dt*10; local params, t = MachineArm.GuessParamOffset(de); local args0, args1, args2 = params[1], params[2], params[3]; MachineArm.joints[1].ShiftSwing(args0[1], args0[3]); MachineArm.joints[1].ShiftTwist(args0[2]); MachineArm.joints[2].ShiftFlex(args1[1]); MachineArm.joints[3].ShiftFlex(args2[1]); MachineArm.joints[3].ShiftTurn(args2[2]) MachineArm.Update(); end

The result:

The mathematics behind this are a bit involved, but fortunately most of the really hard stuff is taken care of by the module. The current API is somewhat limited, but I plan to add many more interesting features in the future, including pre-programmed routines and additional joint types. As of now, the module supports hinge, pivot, and ball joints.
To assemble an object with multiple joints, you need only create the joints and weld an effector to the last one, then call Robotics.MakeChain(effector, joint1, joint2, …). Any number of joints may be specified.

I’ve put in a decent amount of documentation on the features of this library, along with how to use them, inside the script. It also uses my matrix math module, so you’ll need to put that in your game also. Both can be found at these two links:


2 Likes

It works for the most part, but when the target when directly under the end…

Very cool! I’ll try to make use of this later.

[quote] It works for the most part, but when the target when directly under the end…

-snip- [/quote]

I’m not sure what’s going on there exactly, but there are complications that arise with the plain algorithm I’ve presented. It appears to get stuck attempting to move against the parameter constraints. However, without constraints, joints can get locked in singular configurations in which infinitely many solutions (or none at all) may exist.
I plan on adding features to help detect and troubleshoot these situations. Some ideas that come to mind include manual overriding, warning triggers, and basic AI algorithms added as a supplement to the library.

I’ve updated the OP to reflect updates in the module–also, I’ve modified the demo to have 3 joints (Ball, Hinge, Pivot) instead of two Ball joints. Much to my surprise, it appears to be much more robust and flexible; I haven’t seen it get stuck once yet.
In order to make this module more easily usable, I’ll be working on a separate RoboticsHelper library to help create, manage, and troubleshoot joints and chains. I have extensive plans for it, along with the core library.