### Install kinematics.js via npm Source: https://github.com/glumb/kinematics/blob/master/README.md This command demonstrates how to install the kinematics.js library using npm, the Node.js package manager. The `--save` flag ensures that the dependency is added to your project's `package.json` file, making it a permanent dependency. ```console npm install kinematics --save ``` -------------------------------- ### Correcting Kinematic Coupling in JavaScript Source: https://github.com/glumb/kinematics/blob/master/README.md This JavaScript snippet demonstrates how to account for kinematic coupling, a scenario where the movement of one joint directly influences the angle of another. After calculating initial angles using `RobotKin.inverse`, this example shows how to manually adjust `angles[2]` based on `angles[1]` to ensure the robot's specific kinematic configuration is respected. This is crucial for accurate robot control when dealing with non-standard joint dependencies. ```JavaScript let angles = RobotKin.inverse(...pose) angles[2] += angles[1] //set angles, do stuff 🤖 ``` -------------------------------- ### Basic 6DOF Robot Kinematics Usage in JavaScript Source: https://github.com/glumb/kinematics/blob/master/README.md This JavaScript snippet illustrates the fundamental usage of the kinematics.js library. It shows how to import the Kinematics class, define a robot's geometry as an array of link vectors, instantiate the robot, and then perform both forward and inverse kinematics calculations. The forward method computes the end-effector pose from joint angles, while the inverse method calculates joint angles required to reach a specified pose. ```JavaScript const Kinematics = require('kinematics').default const geometry = [ [1, 1, 0], // V0: 1x 1y [0, 10, 0], // V1: 10y [5, 0, 0], // V2: 5x [3, 0, 0], // V3: 3x [0, -3, 0], // V4: -3y ] const RobotKin = new Kinematics(geometry) let angles = [1.57, 1.2, 0, 0.3, 2.2, 1.1] const pose = RobotKin.forward(...angles)[5] angles = RobotKin.inverse(...pose) ``` -------------------------------- ### API Reference: RobotKin Kinematics Methods Source: https://github.com/glumb/kinematics/blob/master/README.md This section details the core API methods provided by the `RobotKin` instance for performing kinematics calculations. It includes the `forward` method for computing the end-effector pose from joint angles and the `inverse` method for determining joint angles required to reach a target pose. The `inverse` method also handles cases where a pose is unreachable by returning `NaN` for out-of-reach angles. ```APIDOC RobotKin.forward(R0, R1, R2, R3, R4, R5) - Description: Calculates the end-effector pose (position and orientation) and intermediate joint coordinates from an array of 6 joint angles. - Parameters: - R0: Angle for joint 0 (number) - R1: Angle for joint 1 (number) - R2: Angle for joint 2 (number) - R3: Angle for joint 3 (number) - R4: Angle for joint 4 (number) - R5: Angle for joint 5 (number) - Returns: An array of arrays representing joint coordinates (J0-J5). The last element (J5) includes the TCP (Tool Center Point) Euler angles. Example: [ [ 0, 0, 0 ], //J0 [ 0.5, 1, -0.8 ], //J1 [ -0.2, -8.8, 0.3 ], //J2 [ 1.8, -5.6, -2.8 ], //J3 [ 3.0, -3.6, -4.7 ], //J4 [ 4.7, -1.3, -5.5, 1, 6, -2.8 ] //J5 + TCP Euler angles (X, Y, Z, A, B, C) ] RobotKin.inverse(X, Y, Z, A, B, C) - Description: Calculates the 6 joint angles required to reach a specified end-effector pose (X,Y,Z coordinates and A,B,C Euler angles). - Parameters: - X: X-coordinate of the target pose (number) - Y: Y-coordinate of the target pose (number) - Z: Z-coordinate of the target pose (number) - A: A-Euler angle (e.g., Roll) of the target pose (number) - B: B-Euler angle (e.g., Pitch) of the target pose (number) - C: C-Euler angle (e.g., Yaw) of the target pose (number) - Returns: An array of 6 joint angles. Returns `NaN` for angles that are out of reach or cannot be calculated. Example: [ 2, 1.6, 2.1, -3.5, 1, -1.5 ] // Array of angles [ 1, 2.3, 3.1, NaN, NaN, NaN ] // NaN for out of reach angles ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.