Skip to main content

MuJoCo Pencil Balancer

by Neuraville

MuJoCo Pencil Balancer

A pencil stands upright in a cup carried by a two-motor planar five-bar linkage. Two fixed cameras about 90 degrees apart watch the pencil against white backdrops, as in event-camera pencil-balancing rigs. The goal is to move the cup under the pencil so it stays upright. Sensors: two cameras, motor encoders, cup position, and a gyroscope and accelerometer on the pencil. Actuators: two position servos at the linkage base. License: Apache-2.0. See model/LICENSE.

Specifications

Manufacturer
Neuraville
Type
Classic Control
Environment
Simulated
Category
MuJoCo Physics Simulator
Controller
MuJoCo
Sensors
Camera
Joint position
Joint velocity
Body state
IMU
Gyroscope
Accelerometer
Actuators
Position servo
Connectivity
ZMQ
Local

Getting started

MuJoCo Pencil Balancer Integration Guide

Overview

A pencil (0.30 m, 12 g) stands in a cup on a pivot that tilts in two directions. Two base motors drive a flat five-bar linkage that moves the cup across the board. The brain keeps the pencil upright by moving the cup under it, the way a hand balances a stick.

Without control the pencil passes 0.5 rad of tilt in about 0.5 s, so the loop from sensing to motor command has to be fast.

Actuators

FEAGI labelWhat it doesRange
left_base_motorPosition servo at the left linkage base-1.0 to 1.0 rad
right_base_motorPosition servo at the right linkage base-1.0 to 1.0 rad

Near the home pose the cup moves about:

  • Left/right (x): both motors turned the same way. +0.3 rad on both moves the cup about +7 cm.
  • Toward/away from the motors (y): motors turned opposite ways. Left -0.3 and right +0.3 moves the cup about +8 cm toward the motors.

Sensors

SensorNotes
cam_left, cam_rightFixed cameras at the front corners, about 90 degrees apart, aimed at the pencil against white backdrops. Each sees the pencil's lean in one direction.
Motor encoders and velocitiesleft_base_motor, right_base_motor
cup_positionCup position on the board
pencil_gyroscope, pencil_accelerometerIMU at the pencil's midpoint
pencil_tilt_roll, pencil_tilt_pitchGround-truth tilt from vertical, for scoring. Use the cameras or IMU for control if the goal is vision-based balancing.

Environment feedback

The preset Keep pencil upright sends pain when the pencil leans past 20 degrees or touches the board.

Model notes

  • The five-bar loop is closed with two equality/connect constraints onto a carriage that slides in x and y, so the pencil pivot stays aligned with the board axes.
  • The passive joints (elbows, carriage slides, pencil tilt) appear as joints, but only the two base motors are actuated.
  • Timestep 0.002 s. The default pose (qpos0) tilts the pencil about 2 degrees (0.03 / -0.02 rad), so it starts falling on its own at every run start and reset. The tilt joints use ref so they still read the angle from vertical.

View marketplace for this embodiment · Back to embodiment explorer

MuJoCo Pencil Balancer | Neurorobotics Studio