kassam 2a78f1b609 Record/replay studio, manual recorder kit, and new-robot install tooling
Dashboard (web/hand_web.py)
- Record/replay panel driving g1_record_replay.py as a pty child: take library
  (replay/download/duplicate/rename/delete/upload/delete-all), pause & resume,
  and in-take key buttons that grey out in the --fingers modes the recorder
  ignores (measured: in touch mode the keys change nothing at all).
- /api/restart is container-aware: it kills inspire_g1 and lets the supervisor
  relaunch it. It used to run manage.sh, which started a SECOND inspire_g1
  beside the supervised one - two writers on one RS-485 bus - and never
  returned.
- Shape/combo libraries take a .bak on every write, with an undo button. Both
  files are rewritten in full, so deleting the last entry was unrecoverable.

recorder/
- The recorder lives in this project now: one source of truth for the CLI and
  the dashboard, with pause/resume added to replay.
- record.sh picks a runtime by itself (a python with the SDK, the vendored SDK,
  or the inspire-hand container). bundle.sh packs a ~340KB portable kit.

tools/
- preflight.sh: read-only readiness report for a new robot (hardware, docker,
  build prerequisites, per-robot settings) ending in an install-path verdict.
- fetch_deps.sh: stage build dependencies, verifying the libs are aarch64.
- export_ui.py: regenerate an embedding app's vendored copy of the UI.

docker/
- build_image.sh resolves its dependencies from several layouts: deps/ inside
  the project, /usr/local, a source install prefix, or a ROS2 colcon workspace
  (where the idl headers live when /usr/local has none).
- web/ is copied in the last layer, so dashboard edits skip the C++ rebuild.
- restart=always, and start.sh always builds so an edit cannot silently run a
  stale image.

deps/unitree_sdk2 is vendored so a robot that has never seen the SDK can build.
Docs: README quickstart + embedding notes, SETUP_G1 corrected (that udev rule
stopped creating /dev/inspire_* symlinks a while ago), ROBOT_README describing
a live install.
2026-08-28 20:27:28 +04:00

108 lines
2.7 KiB
C++

#include <mutex>
// #include <go2_idl/WirelessController_.hpp>
#include "unitree/idl/go2/WirelessController_.hpp"
#include "unitree/common/thread/thread.hpp"
#include "unitree/robot/channel/channel_subscriber.hpp"
#include "advanced_gamepad.hpp"
#define TOPIC_JOYSTICK "rt/wirelesscontroller"
using namespace unitree::common;
using namespace unitree::robot;
class GamepadExample
{
public:
GamepadExample() {}
// setup dds model
void InitDdsModel(const std::string &networkInterface = "")
{
ChannelFactory::Instance()->Init(0, networkInterface);
joystick_subscriber.reset(new ChannelSubscriber<unitree_go::msg::dds_::WirelessController_>(TOPIC_JOYSTICK));
joystick_subscriber->InitChannel(std::bind(&GamepadExample::MessageHandler, this, std::placeholders::_1), 1);
}
// set gamepad dead_zone parameter
void SetGamepadDeadZone(float deadzone)
{
gamepad.dead_zone = deadzone;
}
// set gamepad smooth parameter
void setGamepadSmooth(float smooth)
{
gamepad.smooth = smooth;
}
// callback function to save joystick message
void MessageHandler(const void *message)
{
std::lock_guard<std::mutex> lock(joystick_mutex);
joystick_msg = *(unitree_go::msg::dds_::WirelessController_ *)message;
}
// work thread
void Step()
{
{
std::lock_guard<std::mutex> lock(joystick_mutex);
gamepad.Update(joystick_msg);
}
// some operations
if (gamepad.A.on_press)
{
press_count += 1;
}
// print gamepad state
std::cout << "lx: " << gamepad.lx << std::endl
<< "A: pressed: " << gamepad.A.pressed
<< "; on_press: " << gamepad.A.on_press
<< "; on_release: " << gamepad.A.on_release
<< std::endl << "press count: " << press_count
<< std::endl << "===========================" << std::endl;
}
// start the work thread
void Start()
{
control_thread_ptr = CreateRecurrentThreadEx("nn_ctrl", UT_CPU_ID_NONE, 40000, &GamepadExample::Step, this);
}
protected:
ChannelSubscriberPtr<unitree_go::msg::dds_::WirelessController_> joystick_subscriber;
unitree_go::msg::dds_::WirelessController_ joystick_msg;
Gamepad gamepad;
ThreadPtr control_thread_ptr;
std::mutex joystick_mutex;
int press_count = 0;
};
int main()
{
// create example object
GamepadExample example;
// set gamepad params
example.setGamepadSmooth(0.2);
example.SetGamepadDeadZone(0.5);
// start program
example.InitDdsModel();
example.Start();
while (1)
{
usleep(20000);
}
return 0;
}