Development - new features and changes over last months, mainly new TF training script - #66
Development - new features and changes over last months, mainly new TF training script#66marcinpaluch1994 wants to merge 142 commits into
Conversation
(cherry picked from commit 5f2cb2d)
…l on physical one.
…l on physical one.
…ller, along old trajectories.
…iment_3_04_2025 # Conflicts: # others/prepare_standard_experiment_folder.py
…neral state utilities.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
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, |
There was a problem hiding this comment.
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).
| s[POSITION_IDX+1]= vel | ||
|
|
||
| self.steps_beyond_terminated = None | ||
| return super().init_state(rng) |
There was a problem hiding this comment.
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.
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>


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(Eulervs neural net) and compute accelerations viasecond_derivatives_mode(ODE, neural-only, or ODE+NN residual), with updatedQ2u(Q, u_max)usage throughout.Reworks control disturbance injection by replacing
add_control_noise/controlDisturbance*with a statefulControlNoiseGeneratorbacked by a new time-step-invariantCorrelatedNoiseGenerator, and renames exported parameters tocontrolNoiseScale/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
Taskregistry (tasks.py), aPygameViewer, aCartPoleSimulatorBaseinterface, replaces the legacy sensors sim withCartpole_CustomSim, and addsCartpole_Remoteto run the environment against physical hardware over ZeroMQ.Written by Cursor Bugbot for commit 95c12c2. This will update automatically on new commits. Configure here.