Skip to content

274 add some automated model predictive current control to gem control#282

Merged
bhk11 merged 39 commits into
nightlyfrom
274-add-some-automated-model-predictive-current-control-to-gem-control
Dec 19, 2025
Merged

274 add some automated model predictive current control to gem control#282
bhk11 merged 39 commits into
nightlyfrom
274-add-some-automated-model-predictive-current-control-to-gem-control

Conversation

@manjeetjha070
Copy link
Copy Markdown
Collaborator

I have renamed the curred mpc example file to "pmsm_ccs_mpc_dq_current_control.ipynb" and created a new file for finite control set as "pmsm_fcs_mpc_dq_current_control.ipynb".

Copy link
Copy Markdown
Collaborator

@XyDrKRulof XyDrKRulof left a comment

Choose a reason for hiding this comment

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

Already very nice work. For improvements, see my comments.

…ented comments on pmsm_fcs_mpc_dq_current_control.ipynb file
@manjeetjha070
Copy link
Copy Markdown
Collaborator Author

I have implemented the following changes plz. review.

  1. Changed the introductionary text and title to reflect that this is an FCS example and CCS example.
  2. Removed Gekko (and other unused libraries).
  3. Implemented generalized MPC.

Pending point,

  1. To create a FCS environment, I would need a guidance for it.

Copy link
Copy Markdown
Collaborator

@XyDrKRulof XyDrKRulof left a comment

Choose a reason for hiding this comment

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

Hey Manjeet,

thanks for your good work - the FCS - MPC algorithm with prediction horizon > 1 is already looking really good :) Here are some further comments that we discussed:

  1. Replace the "max_depth" variable in the simulate_sequence function with self.ph_ (which, for readability, you could also rename to self.prediction_horizon)
  2. The self.voltage_vectors variable seems to be a mix out of abc and alphabeta coordinates - please change this table to the one you get directly out of the environment:
    self.subactions = -np.power(-1,env.get_wrapper_attr('physical_system')._converter._subactions)
  3. Instead of saving the abc voltage sequence of the lowest cost prediction, save (and return) the indices of them as provided in 2. (e.g., if the best voltage vector is (-1,1,-1) and it is in position 3 return 3)
  4. Update epsilon_el for the future predictions and average it for the abc -> dq conversion:
    v_dq = self._forward_transformation(np.array([v_a, v_b, v_c]), epsilon_el + 0.5*omega*tau)
    epsilon_next = epsilon + omega*tau

If you have any questions regarding any of these points feel free to contact us! :)

…utilities and improve prediction logic

- Replaced manual abc → αβ → dq voltage transformations with environment's native method:
- Updated voltage vector table to use finite set directly from the environment via:

- Now storing and returning subaction **indices** instead of full abc voltage vectors for better integration and comparison
- Updated epsilon handling in prediction loop:
  - Epsilon is now incremented as
  - dq-transformation uses averaged value:
- Replaced hardcoded max_depth with  (renamed from  for clarity)

Previously, I was doing manual calculations: converting abc voltages to αβ and then dq using custom logic.
Now all transformations use the environment's own coordinate conversion function and finite action space, making the controller more accurate and modular.

Thanks again for the helpful feedback!
@manjeetjha070
Copy link
Copy Markdown
Collaborator Author

Refactored FCS-MPC implementation to align with environment-provided utilities and improve prediction logic

  • Replaced manual abc → αβ → dq voltage transformations with environment's native method: abc_to_dq_space
  • Updated voltage vector table to use finite set directly from the environment via:
    self.subactions = -np.power(-1, env.get_wrapper_attr('physical_system')._converter._subactions)
  • Now storing and returning subaction indices instead of full abc voltage vectors for better integration and comparison
  • Updated epsilon handling in prediction loop:
    • Epsilon is now incremented as epsilon_next = epsilon + omega * tau
    • dq-transformation uses averaged value: epsilon + 0.5 * omega * tau
  • Replaced hardcoded max_depth with self.prediction_horizon (renamed from self.ph_ for clarity)

Previously, I was doing manual calculations: converting abc voltages to αβ and then dq using custom logic.
Now all transformations use the environment's own coordinate conversion function and finite action space, making the controller more accurate and modular.

Thanks again for the helpful feedback!

@manjeetjha070
Copy link
Copy Markdown
Collaborator Author

I have revised the description for FCS-MPC, now its ready to get merge.

…rap around GymElectricMotorAdapter class. 2)updated the MPC controller file to process directly from environment,PMSM works.
@manjeetjha070
Copy link
Copy Markdown
Collaborator Author

Now, the MPC controller calculates the motor-specific state vector and electrical jacobian once in the control method, then uses these for prediction in _simulate_sequence. This makes the controller compatible with different motor types and avoids redundant calculations during the prediction loop. Unsupported motor types will raise a clear error.

…troller.make

- Added w_d and w_q parameters to MPCCurrentController
- Updated cost function to use weighted errors
- Modified GemController.make to forward extra kwargs into MPC
…b" and created new file for finite current control
…ented comments on pmsm_fcs_mpc_dq_current_control.ipynb file
…utilities and improve prediction logic

- Replaced manual abc → αβ → dq voltage transformations with environment's native method:
- Updated voltage vector table to use finite set directly from the environment via:

- Now storing and returning subaction **indices** instead of full abc voltage vectors for better integration and comparison
- Updated epsilon handling in prediction loop:
  - Epsilon is now incremented as
  - dq-transformation uses averaged value:
- Replaced hardcoded max_depth with  (renamed from  for clarity)

Previously, I was doing manual calculations: converting abc voltages to αβ and then dq using custom logic.
Now all transformations use the environment's own coordinate conversion function and finite action space, making the controller more accurate and modular.

Thanks again for the helpful feedback!
@bhk11 bhk11 force-pushed the 274-add-some-automated-model-predictive-current-control-to-gem-control branch from af50dc7 to 17373c6 Compare October 27, 2025 21:20
Copy link
Copy Markdown
Member

@bhk11 bhk11 left a comment

Choose a reason for hiding this comment

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

Works fine for me in the mentioned limits in the changelog

@bhk11 bhk11 merged commit 58274d5 into nightly Dec 19, 2025
6 checks passed
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.

3 participants