Skip to content

Development - new features and changes over last months, mainly new TF training script - #66

Open
marcinpaluch1994 wants to merge 142 commits into
masterfrom
Development
Open

Development - new features and changes over last months, mainly new TF training script#66
marcinpaluch1994 wants to merge 142 commits into
masterfrom
Development

Conversation

@marcinpaluch1994

@marcinpaluch1994 marcinpaluch1994 commented Jun 27, 2025

Copy link
Copy Markdown
Collaborator

Note

High Risk
High risk because it changes core CartPole dynamics/actuation plumbing (new neural-model stepping and acceleration modes, updated Q2u, renamed noise parameters) and adds a new ZeroMQ-based remote control path, all of which can materially alter simulation fidelity and runtime behavior.

Overview
Adds configurable dynamics execution paths to the simulator: CartPole can now advance state via next_step_mode (Euler vs neural net) and compute accelerations via second_derivatives_mode (ODE, neural-only, or ODE+NN residual), with updated Q2u(Q, u_max) usage throughout.

Reworks control disturbance injection by replacing add_control_noise/controlDisturbance* with a stateful ControlNoiseGenerator backed by a new time-step-invariant CorrelatedNoiseGenerator, and renames exported parameters to controlNoiseScale/Bias/Correlation/controlNoise_mode.

Introduces a new cartpole_ekf.py (EKF + adaptive Q/R tuner with YAML persistence + live reload), updates CSV logging/header metadata, tweaks MPC cost/optimizer configs, and adds an additional neural controller (controller_difflg) plus bundled model artifacts.

Modernizes the Gym env by decoupling physics from tasks and rendering: adds Task registry (tasks.py), a PygameViewer, a CartPoleSimulatorBase interface, replaces the legacy sensors sim with Cartpole_CustomSim, and adds Cartpole_Remote to run the environment against physical hardware over ZeroMQ.

Written by Cursor Bugbot for commit 95c12c2. This will update automatically on new commits. Configure here.

…iment_3_04_2025

# Conflicts:
#	others/prepare_standard_experiment_folder.py

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

high = np.array(
[
self.theta_threshold_radians * 2,
self.angle_limit * 2,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undefined angle_limit attribute crashes Cartpole_OpenAI initialization

High Severity

Cartpole_OpenAI.__init__ references self.angle_limit to build the observation space, but this attribute is never defined on the class. The old self.theta_threshold_radians was removed without replacing it with a self.angle_limit assignment. This causes an AttributeError crash whenever Cartpole_OpenAI is instantiated (e.g., when cartpole_type="openai" is selected in CartPoleEnv).

Fix in Cursor Fix in Web

s[POSITION_IDX+1]= vel

self.steps_beyond_terminated = None
return super().init_state(rng)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StabilizationOpenAI.init_state discards its constructed state

Medium Severity

StabilizationOpenAI.init_state carefully builds a near-upright state s with small angles and velocities (matching classic OpenAI CartPole specs), but then returns super().init_state(rng) which constructs and returns a different state with full-circle random angles. The locally built s is completely discarded, so episodes start with random angles instead of the intended near-upright configuration.

Fix in Cursor Fix in Web

marcinpaluch1994 and others added 13 commits June 16, 2026 07:39
Point Control_Toolkit at the RPGD-C change that keeps OpenMP workers active between control ticks.
The top-level `import tensorflow` forced TF to load as soon as anything imported
CartPole, i.e. before the controller/optimizer (and therefore the desired
CPU/thread policy) was known. Move the import into create_rng so TF loads only
when a TF RNG is actually requested, letting Driver/control.py set CPU affinity
and TF/XLA threading before TensorFlow initializes its runtime.

Co-authored-by: Cursor <cursoragent@cursor.com>
Watch config_controllers.yml and reload LQR gains live during a run; add
a no-op controller_reset so safety-off works. Retune to Q=[10000,1,1,1],
R=2000.

Co-authored-by: Cursor <cursoragent@cursor.com>
Cast switch-timing config values to float and guard the random
initialization so an infinite timeout yields inf instead of feeding
inf into np.random.uniform.

Co-authored-by: Cursor <cursoragent@cursor.com>
Update Control_Toolkit and SI_Toolkit submodule pointers to the verified
working LQR state running on both PC and Zynq.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Point the neural-imitator controller at
CartPoleSimulation/SI_Toolkit_ASF/Experiments Dense-7IN-32H1-32H2-1OUT-8
(reliable swing-up + stabilization on the long pole) and set
input_precision to ap_fixed<12,2> to match the deployed quantization.

Co-authored-by: Cursor <cursoragent@cursor.com>
Point SI_Toolkit at the Development commit adding the positional
weight-loading fallback required to load the Dense long-pole net.

Co-authored-by: Cursor <cursoragent@cursor.com>
Restore m_cart=0.230, u_max=1.77, M_fric=3.22 -- the only set confirmed to swing
up and balance on the physical cartpole with RPGD. The honest decorrelated
system-ID values (m_cart=2.82, u_max~21.5, M_fric~36) and why the 13/22 set broke
RPGD are documented in
Driver/DataAnalysis/MotorAndCartFriction/motor_force_identification_2026-06/README.md.

Co-authored-by: Cursor <cursoragent@cursor.com>
This is the long-pole Dense net used by the PC neural-imitator controller
(swing-up + stabilization). It was only on disk (the Experiments/ folder is
gitignored), so force-add it to make the working MLP reproducible from a clone.
Its normalization matches the firmware HLS4ML 'v1' block (x3232_12_2_v1).

Co-authored-by: Cursor <cursoragent@cursor.com>
- config_controllers.yml: neural-imitator points to the committed
  Dense-7IN-32H1-32H2-1OUT-8 net, nn_evaluator_mode 'C' (same math as
  the on-chip pure-C controller); keep the paper/FPGA 1OUT-1 net as a
  documented alternative.
- Convert_Network_To_C.py: target 1OUT-8 for C-code generation.
- SI_Toolkit: pull in network_parameters.c compile fix.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants