Site Guide

Find your way around the Engineering Club.

Know what you need? Search for a component, concept or project.

Around the site

Start

Labs

TestingExperimental

Build

Club

LearnExperimental

Go a little deeper

Entry points to larger collections. Use Search for individual records.

Learning paths & reference

Inside PiCrawlerExperimental

Inside Inventory

PiCrawler / Movement, Frames & Inverse Kinematics

Movement, Frames & Inverse Kinematics

Local foot targets, gait phases, angle order, reachability and silent projection.

Nominal planar IK model · not a chassis measurement
Canonical PiCrawler planar IK construction for local toe target [45,45,-50] millimetres: C=33, A=48, B=78; conceptual geometry, not a measured chassis drawing.

Per-leg local geometry only. Physical X/Y directions still need inspection; commanded coordinates can be silently projected.

Coordinate conventions: do not mix leg, body and image frames

PiCrawler's current examples explicitly order legs as right front, left front, left rear, right rear. Terminal selection uses 1–4, while do_single_leg() takes indices 0–3. The leg diagrams place 2/1 at the front and 3/4 at the rear. All coordinate arrays follow that order. A program that uses UI number 1 as Python index 1 moves the left-front leg rather than the right-front leg.

Each leg has its own toe coordinate. The solver takes the horizontal radius sqrt(x²+y²), subtracts C=33 and uses the vertical coordinate z. This operationally defines a local yaw/root origin followed by a bending-plane offset. The nominal length scale is millimetres. Z becomes more negative when a planted toe is commanded farther below the body; raising a swing toe changes Z from the stock -50 to -30. Positive Z points upward in this geometric interpretation. The action-gallery prose claiming more negative Z means “higher up” conflicts with the actual lift sequence and must not guide motion.

What is source-confirmed, and what needs a physical frame check

ConventionEvidence strengthMeaning
Leg identities and orderExplicit source labelsRF, LF, LR, RR
Calibration referenceSource constant[60,0,-30] for each leg
Stock stand target, phase 0Generated source coordinates[45,45,-50], [45,0,-50], [45,0,-50], [45,45,-50]
Stock sit target, phase 0Generated source coordinates[45,45,-30], [70,0,-30], [70,0,-30], [45,45,-30]
Local yaw referenceExact equationgamma=45°-atan2(y,x)
Z lift conventionGait source-30 is lifted relative to -50
Body displacement X/Y signsHelper formulasDifferent sign patterns across local frames
Exact assembled root-axis origin and physical positive X/Y arrowsRequires inspection of geometry/axis figure and actual mountingDo not substitute a guessed global X-forward convention

The official pose page confirms independent foot frames but contains stale symmetric stance arrays and a duplicated rear-leg name. Its current action-gallery prose also describes X/Y in an oversimplified global way. The detailed reference figures are linked in the source ledger, but image retrieval was blocked in this environment, so their physical arrow directions were not visually verified. This package intentionally leaves that narrow physical convention open instead of inferring it from memory. The source equations, local model and leg/channel mapping remain exact.

Body and camera conventions

move_body_absolute() uses opposite X signs for the right and left sides and opposite Y signs for front and rear. Its formula is a source-defined transformation, not a declaration that all leg coordinates share a single global axis. Likewise the names of the X/Y rotation helpers should not be copied into a ROS URDF without physical verification of the rotation axes.

Camera image coordinates are another frame: detection X/Y are pixel positions in an image. A flip setting can reverse the relationship between target movement in the image and a robot turn. Thresholds must be normalized against the actual image width. The stock bull-fight example uses absolute X thresholds 100 and 220 while Vilib's default capture width is 640. That is a 320-width-style center band in a 640-width stream; inspect measured image coordinates before relying on its behavior.

Record all future logs with a frame identifier, unit and timestamp. A vector labeled merely “position” is insufficient. A useful first bench record is a photograph of each root axis plus observed toe motion for a small X, Y and Z increment, made after calibration on a supported robot. It supplies the missing frame evidence without assuming a world pose sensor exists.

Source evidence: pc-core, pc-single-leg, pc-bull-fight, vi-core, pc-pose-doc, pc-gallery-doc. Unknown physical arrow directions are tracked in unknowns.json.

Movement is a sequence of target poses

do_step() requests one four-leg coordinate frame or iterates a stored stand/sit frame list. do_action() requests a multi-frame named action and repeats it a given number of times. A gait cycle is therefore not the same as one toe movement, one millimetre of travel or one fixed-duration motor command. Travel distance depends on surface, body loading, calibration and slippage.

How a forward gait works

The stock forward property supplies seven principal frames. It lifts one selected foot, advances that foot, plants it, shifts the stance relationships, then lifts/repositions the other selected foot. normal_action decorators permute leg arrays according to stand_position, allowing the complementary phase to run on the next request. check_stand prepends standing frames when necessary. Property evaluation changes state such as z_current and ready_state; even merely asking for an action's coordinate list can affect the next list generated.

The list is a conservative sequential gait rather than a dynamically stabilized trot. Several contacts remain available while a foot swings. The user program does not continuously compute center of pressure or react to measured body roll. Coordinates and source flags alone do not establish that all intended feet are in contact.

Stability from first principles

The support polygon is the convex region formed by the contacts that are actually bearing load. For slow movement on level ground, the vertical projection of the center of mass needs to remain within that region with some margin. When one foot lifts, the polygon changes. A foot sliding or hovering removes the contact the geometric plan assumed. Body motion, acceleration and incline make this static criterion insufficient by itself.

Stance phase means a foot is intended to remain supporting the robot while the body moves relative to it. Swing phase lifts and relocates that foot. A successful gait coordinates those phases so load transfer occurs before support is removed. The stock code supplies targets; it does not measure those events. This is why a gait that appears reasonable in coordinate space can fail on polished flooring or with a changed payload.

Timing and interpolation

The interpolation layer blends joint angles, not Cartesian foot coordinates. Intermediate toe paths can curve even when only endpoint coordinates were specified. Speed 50 nominally starts from a 505 ms frame interval, then the angular-speed cap can lengthen it. Several frames, prepended stand frames and explicit sleeps accumulate into a gait's total time. At speed 100 the nominal base time is 10 ms, but large angular changes still encounter the cap. No gait-speed calibration in cm/s has been established.

Calls block while moving. An obstacle check performed before a gait does not keep sampling throughout every part of the action. Network stop latency includes the current blocking segment and how command dispatch is implemented. The 871 frames produced by library dance from the constructor-equivalent sit state illustrate why expressive actions should not be queued casually in an interactive controller.

Custom action engineering

Store poses as four triplets in the declared leg order, and actions as lists of those poses. add_action(name,frames) registers an in-memory action; it does not save a persistent file. The recording example uses deep copies to keep saved frames from following later edits, but its saved list is still process memory. Export authored motion data explicitly in a future project.

current_step_all_leg_value() returns only a shallow outer-list copy. Editing an inner triplet can mutate library state before any motion call. Use a deep copy for experimentation. current_step_all_leg_angle() reports command positions, not sensed joint angles. Pair motion logs with video or a new sensor if you need evidence of physical motion.

A useful gait laboratory

Start from a proven low-speed stance and change one parameter at a time: swing height, stride, phase timing or body shift. Record commanded frames, action duration, battery voltage, surface, added mass, falls and measured displacement. Reject a candidate trajectory if it relies on silent IK projection or loses its support margin. An IMU can add orientation evidence later; it does not retrospectively make the stock gait closed loop.

Source evidence: pc-core, hat-robot, pc-record-step, pc-custom-step; validation/action-gallery.json. Geometric stability discussion is engineering reasoning, with no measured stability claim.

Inverse kinematics, derived from the actual implementation

Forward kinematics asks where a toe ends up when joint angles are known. Inverse kinematics asks which angles could put the toe at a requested position. PiCrawler's solver uses a planar two-link triangle after accounting for a horizontal yaw and offset. It does not solve the dynamics, loads or traction of the robot. A coordinate solution is a geometric command, not proof that a servo can achieve it under load.

The planar construction diagram shows the nominal triangle separately from physical chassis orientation.

The geometric reduction

Let the requested local toe coordinate be (x,y,z), and let A=48, B=78, C=33 in the model's nominal millimetre units. The horizontal distance from the yaw axis is

[ w=\sqrt{x^2+y^2}. ]

Subtract the first horizontal offset C to reach the bending-plane distance, v=w-C. The straight-line distance from that plane's first bending joint to the toe is

[ u=\sqrt{v^2+z^2}. ]

The angle of that toe vector within its vertical plane is theta=atan2(z,v). atan2 preserves signs and handles quadrants, unlike simply using atan(z/v). The horizontal yaw angle before the servo-reference adjustment is phi=atan2(y,x). This is why X and Y cannot be treated as a universal room coordinate across all four legs: they are inputs to each leg's local model.

Two uses of the law of cosines

The bending links A and B and the toe distance u form a triangle. If b is its included knee angle, the law of cosines gives

[ \cos b=\frac{A^2+B^2-u^2}{2AB}. ]

If a is the angle between link A and the toe vector, then

[ \cos a=\frac{A^2+u^2-B^2}{2Au}. ]

The raw upper-link orientation in the bending plane is a+theta. The source then converts the geometric angles to the kit's servo references in degrees:

[ \alpha=90^\circ-\operatorname{deg}(a+\theta),\qquad \beta=\operatorname{deg}(b)-90^\circ,\qquad \gamma=45^\circ-\operatorname{deg}(\phi). ]

coord2polar() rounds these to four decimals and returns [alpha,beta,gamma]. do_step() supplies [beta,alpha,gamma] to the servo-array pipeline. Do not “correct” the forward conversion by passing the original return list unchanged: the forward function's parameter labels do not align with the inverse function's return order.

A worked coordinate

For the calibration reference [60,0,-30], w=60, v=27 and the raw u is approximately 40.36. The current solver returns [14.2919,-64.5078,45.0]. The array sent before offsets/directions is [-64.5078,14.2919,45.0]. With the right-front direction multipliers, zero synthetic offsets would make the yaw command -45 degrees. Zero here is a hypothetical numerical fixture, not the club's calibration.

For [45,45,-50], the returned inverse angles are [55.0255,-41.3726,0.0]. Reordered into the forward function, they reproduce [45,45,-50] within the source rounding. The package's offline test checks 114 unprojected coordinates with an independently derived forward model. This verifies the mathematical interpretation, not a physical linkage measurement.

Workspace: three different restrictions

The unconstrained two-link triangle requires |B-A| ≤ u ≤ A+B, or 30 ≤ u ≤ 126. This is a necessary geometric condition. It says nothing about joint collision limits, servo travel or stability. PiCrawler uses a much narrower numeric interval: it clips u to 30..91.58. The upper number is close to sqrt(A²+B²), corresponding to the knee reference beta approaching zero rather than maximum straight-line extension. It should not be called the leg's full theoretical reach.

Before calculating u, the source also checks the distance L=sqrt(x²+y²+z²). Requests with LA+B+C are radially rescaled; an all-zero request uses an L fallback without generating a sensible nonzero direction. The lower/upper radial check is not equivalent to the two-link triangle check. Next, u is clipped without consistently projecting v and z to match the new u. The routine therefore can return angles for a different toe location than the requested coordinate.

Finally limit_angle() clamps each triplet presented by set_angle(). Despite its local alpha/beta variable names, after the reorder these limits apply to knee beta (-90..90), upper-link alpha (-10..90) and yaw gamma (-60..60). Servo.angle() supplies another -90..90 bound after offsets and direction. This layered behavior is essential for interpreting a failed pose.

Silent projection and israise

An offline probe of [200,0,-100] returns finite inverse angles and a reconstructed toe approximately [109.7468,0,-49.9682], over 100 mm away from the request. The angle limiter does not flag that particular projected request. Consequently do_step(...,israise=True) is not a comprehensive workspace validator: it raises only for the later angle-clamp condition. Applications requiring strict coordinate truth should perform their own bounds/finite-value validation and compare the reconstructed reachable point before hardware control.

Targets near u=|B-A| or full extension have poor conditioning: small changes can cause substantial joint-angle changes, and collinear configurations lose useful directional leverage. x=y=0 makes the yaw direction physically indeterminate even though Python's atan2 returns a numeric result. Non-finite inputs, malformed arrays and interpolated paths also need application validation. A safe starting pose can have an unsafe straight interpolation in joint space to another otherwise valid pose.

Calibration is applied after the geometric solution

The solver knows nominal lengths, not assembly bias. Calibration adds a stored angle correction per servo. It does not change A, B or C, solve gear backlash, measure a real toe position, or make the requested body motion stable. Re-indexing a badly mounted horn and then recalibrating can be necessary; making an offset increasingly large to compensate for a wrong mechanical assembly is not a sound strategy.

Body transformations

Picrawler.MoveList.move_body_absolute(x,y,z) constructs four local coordinate triplets with different signs. It uses Z_TURN=-40 as its base. The source's rotate_body_absolute_x() changes Z with opposite signs for right and left leg groups; rotate_body_absolute_y() changes Z between front and rear groups. These method names are not a standard ROS frame declaration. They produce coordinate arrays and do not issue motion until passed to do_step(). They are advanced implementation helpers, not a general six-DOF body IK engine.

A future body solver should declare one global body frame, physical hip transforms and a world foot frame, then apply inverse rigid transforms before per-leg IK. Test the transforms numerically before moving the robot. The present package documents the existing formulas and their bounds; it does not rewrite the gait library or introduce unverified calibration values.

Source evidence: pc-core, hat-robot, hat-servo; validation/offline-results.json. Equations are an original derivation of the pinned implementation, with all projection/ordering differences retained.

The current library MoveList uses properties evaluated at access time. A property name with underscores is also addressable through its space-separated form because __getitem__ replaces spaces. Custom registration remains separate. Not every example-level named expression is a library action.

Library propertyCall nameDefinition lineFrames from constructor-equivalent sit state
sitsit3431
standstand3555
readyready4061
forwardforward42812
backwardbackward44312
turn_leftturn left45811
turn_rightturn right47211
push_uppush up4848
wavewave50614
look_leftlook left5237
look_rightlook right5397
turn_left_angleturn left angle56011
turn_right_angleturn right angle58011
look_uplook up6016
look_downlook down6096
dancedance638871

Frame counts come from offline property evaluation with cached stand-then-sit construction state, z_current=-30, ready_state=1 and phase 0. They include prepended stand frames where the property supplies them. Counts change with prior state/phase, and are not durations or measured stride lengths. The forward/backward sequences have seven principal gait frames before any standing preparation. No motor outputs were generated by this evaluation.

The example gallery's menu contains sit, stand, wave_hand, shake_hand, fighting, excited, play_dead, nod, shake_head, look_left, look_right, look_up, look_down, warm_up and push_up. A dance function exists in that file but is commented out of the menu. Those functions may contain their own coordinate sequences rather than use a same-named library property. An empty initial menu input and negative indices also need input-policy review before embedding that menu in a club controller.

Body translation/rotation helpers are methods returning coordinate data. They are not no-argument built-in actions unless registered explicitly. The source map and API map show their exact paths and arguments.

Source evidence: pc-core, pc-gallery; validation/action-gallery.json and validation/offline-results.json.

Continue

Meeting checklist · Source library · Modification atlas · All project proposals