Coder Social home page Coder Social logo

robotology / icub-firmware-models Goto Github PK

View Code? Open in Web Editor NEW
6.0 17.0 5.0 18.66 MB

Models underlying the iCub Firmware

Home Page: https://robotology.github.io/icub-firmware-models/

License: BSD 3-Clause "New" or "Revised" License

MATLAB 87.84% C 12.16%
firmware icub models simulink

icub-firmware-models's Introduction

iCub Firmware Models

ZenHub Community

This repository hosts all the models underlying the iCub Firmware.

Maintainers

This repository is maintained by:

@pattacini

Contributing

We accept contributions via forks and pull-requests.

icub-firmware-models's People

Contributors

ale-git avatar mfussi66 avatar pattacini avatar sgiraz avatar triccyx avatar valegagge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

icub-firmware-models's Issues

Automatize performance analysis of codegen

From @valegagge:

I'd like to suggest improving the code inside the application in order to automatize as much as possible this check of performance: for example, we could have a simple Matlab script that could get the data collected in the firmware and plot them automatically. ๐Ÿ–Œ๏ธ

Run a test campaign before merging AMCBLDC_experimental and AMCLBDC

At the moment there are two projects that involve the AMCBLDC board, the official one and the Experimental one.
The Experimental project involves a major refactor of the supervisor and leverages the Common Simulink project to make the structure more modular.

While the first trials were successful (#84), the integration tests were not exhaustive.

This issue aims to track which tests need to be performed, before making Experimental the official project.

AMCBLDC: supervisorTX doesn't handle the overcurrent flag.

While working on issue #40, I noticed that the SupervisorTX supervisorTX doesn't handle the overcurrent flag, while the SupervisorRX performs the check.

SupervisorTX SupervisorRX
image image
As you can see, in the dictionary, Flafs struct doesn't contain the overcurrentinfo The Fault handler state machine checks the filtered current value

I suppose this is a bug, isn't it? @pattacini @mfussi66

I can fix it before addressing the #40.

AMCBLDC: Inspect suspect regression in simulation

While working on AMCFOC Testing I tried to run a motor control simulation, using the latest devel branch.

To my surprise, the simulated pmsm could not spin because there was no commutation between phases:

foc_new

We can see that 3-phase currents and voltages remain somewhat constant, while they actually should have this kind of waveform:

Closed loop current control:
foc_normal

Open loop voltage control:
voltage_normal

So I checked the AMCBLDC project, to verify if upstream everything was working fine.
Most specifically I used the testing model https://github.com/robotology/icub-firmware-models/blob/devel/boards/amcbldc/tests/control/control_pmsm.slx , and I noticed the same behaviour happening starting from the PR regarding D-axis alignment, even though the physical motor spins with no problem.

I can make some tests to see which changes in this PR affect the simulation.

cc @Nicogene @pattacini @sgiraz

Perform preliminary firmware tests on the AMC-BLDC

Task description ๐Ÿ“

We recently refactored the motor control supervisor (see #65). We now have to test the new architecture on the AMC-BLDC board.
For this we need:

  • to restructure the AMC-BLDC architectural model with the new supervisor
  • a setup with a motor

Useful links and documents

Definition of Done โœ…

Demo with setup running with the new firmware.


Originally opened by @fiorisi in different repo.


As suggested by @pattacini, it will be useful to create the AMCBLDC customizations in a separate path, so that the two versions can live side by side.

AMCFOC โ€“ Develop Architectural Model

This is the main collector for issues on the development of the architectural model for the AMCFOC board.

We will mainly inherit the model from the AMCBLDC and adapt it to a different context.
Some preliminary work on this includes:

  • Extract general-purpose components from AMCBLDC and put them in a common basket.
  • Check if 2 FOC components can run seamlessly on a single CM4 core.
  • Study how to make the AMCBLDC/Supervisor general enough to cope with 2 motors.
  • Get rid of CAN-based components as we'll rely on ETH โ”
    • We decided to do so!

Note
๐Ÿ—“๏ธ Regarding the timeline, we ought to complete the development by the end of PI16 (~ Oct 2023) to be ready for testing the new ergoCubv2.0 arm at the end of the year.

Check direct current

We're required to verify that the direct current $I_d$ is kept to $0$ effectively by the FOC PID.
To this aim, we may rely on a temporary hack for the CAN protocol.
To be checked on the setup.

(Aside from $I_d$, it might be convenient to check the bare three-phase currents too.)

cc @Nicogene

AMCFOC โ€“ Refactor the Supervisor motor-independent part

Following up on the excellent work done on the dictionary (see #54), we need to deal with the motor-independent part of the Supervisor.

Important

It's true that we aim to address the AMCFOC, but it's essential to keep in mind that at a certain time we'll have also to integrate the AMCBLDC CAN handler and 4 motors (AMC4DC) instead of 2.

AMCBLDC โ€“ Make `Vmax` + other useful params configurable via CAN

As of now, Vcc and Vmax are statically defined in the model. This prevents us from adapting those parameters to the setups/robots w/o re-generating the code.

It'd be thus great to have the possibility to tune the voltage values on the fly via CAN, for example to adapt for cable or battery voltage supply.
We haven't done that yet as the current CAN protocol doesn't foresee this option.

EDIT

We may consider at this stage including other motor-related useful parameters to configure via CAN; see also #14.

In total:

  • The Vmax.
  • The motor resistance and inductance.
  • Some control-specific params: swapBC, hall sensor offset.
  • The thermal resistance, the thermal time constant, and the critical temperature.
  • The environment temperature (perhaps).

AMCBLDC โ€“ Complete the `STATUS` msg

As of now, we only send the quadrature voltage and a flag reporting the status of the external e-stop.
However, the STATUS message has many more flags that are meant to be transmitted, although many are not yet handled internally.

AMCBLDC โ€“ Read `Vcc` on the fly

It's be super useful to have the AMCBLDC board capable of reading the supply voltage Vcc on the fly in order to adapt wrt. changing conditions (network supply, batter, setup...).

To this end, we're required to develop a dedicated API and expose the value to the architectural model.
See also #8.

AMCFOC: refactor motor-specific supervisor to be used with `For Each subsystem`

The idea of the AMCFOC motion controller is to be referenced in a For Each subsystem. This kind of subsystem allows calling the block multiple times, depending on the dimensionality of the input/output signals. In this way, we can use the same functions for multiple motors.
However, this type of subsystem relies on the internal function-call subsystems to have the trigger signal of width=1. The motor-specific supervisor is full of these triggers. It is therefore necessary to replace this kind of logic with an equivalent one, most likely with a less modular state machine, that allows us to resolve this limitation and enable the full features of the supervisor.
After this, it will be possible to create unit tests for the motor-specific supervisor.

Inspect and resolve the interaction between `For each subsystem` and FOCInnerLoop

The FOCInnerLoop block is the one called by the ADC interrupt in the firmware. Since the for-each subsystem expect to call this function once for each motor every ~36usec, we need to check if there are any implementation mismatches between the codegen and the expected behaviour which is interrupt based and not periodic.

AMCBLDC โ€“ Refactor the IRQ handler responsible for calling FOC

From @marcoaccame


Another thought:

I am a little nervous to have an important high priority and high frequency IRQ Handler that executes for long time. The rule of thumb is: the more important the IRQ handler, the less code it must run. Now: it is executed every 37 us, lasts about 15 us. Also it runs code which requires mutual exclusion. A little too much in my opinion.

I would clean up and move out of the IRQ Handler all the MBD code by doing the following.

  • keep inside the IRQ Handler only a quick copy from DMA area of the three currents (maybe into a circular FIFO) and use an RTOS event to wake up a very high priority thread called threadFOC.
  • the high priority thread threadFOC is waken up by an event from the IRQ handler which: copies just the three currents in a thread safe and very quick mode (I may do it perhaps also w/out disabling the IRQ...) and then use the three currents to run the MBD FOC algorithm.
  • redefine the mutex used by the MBD code to be an RTOS mutex because it must protect data between two RTOS threads. The advantage is that the RTOS mutex has priority inversion.
  • re-evaluate the duration and frequency of the IRQ Handler and of the two threads FOC and TICK.
  • if the IRQ Handler is still not regular, I would check the priorities of the IRQ handlers and of the DMA to make sure no other has higher priority.

The framework of the application is a little messy. It was developed long ago and it needs maybe some tidy up.

For now I document in here what we need to have.

foc-tick
Figure. Scheme of the required SW entities.

We need a new thread tFOC alongside to the existing threads tCAN and tTICK. Also we need a different mutual exclusion mechanism between actions performed inside tTICK and tFOC: we can use a embot::os::rtos::mutex_t.

The interactions amongst entities are the following:

  • tCAN -> object: when we have a new can frame from the embot::hw::can driver then thread tCAN, the producer, adds it to the input FIFO which is protected w/ a mutex vs concurrent access from tTICK, the consumer.
  • tTICK -> tCAN: if there is a can frame to send back as a reply or a periodic streaming the thread tTICK sends an event to thread tCAN which retrieves a vector of replies from the output FIFO (mutex protected).
  • tTICK <-> tFOC: access to shared data is done by means of a rtos::mutex_t.
  • IRQ handler -> tFOC: the handler every 37 us has three new current values, it copies them into a volatile variable and then sends a wake up rtos event to thread tFOC. The thread wakes up, disable IRQ for the handler, copies the volatile variable into local memory and re-enables IRQ. At this time it runs safely the FOC algorithm.

The tTICK thread is periodic @ 1ms, the tFOC is activated by the periodic IRQ handler @ 37us (so the thread is de-facto periodic as well).

Almost all objects are available. I just need to refactor and test.

Refine thermal model with inductive load

          A F2F chat with @pattacini and @maggia80 highlighted that it is important to consider how the PWM signal is generated (whether it is in Left-aligned mode or Center-aligned), and how the current is measured.

Since we are dealing with an inductive load, we need to consider exponential transitory effect, during which the PWM signal of a phase is positive.
The current is measured in the middle of the positive PWM, during which the transitory might not be exhausted. This depends on the time constant (Phase resistance and inductance), and on the duty cycle.

Therefore accounting for the electrical transitory period might be the key to improve the model and reduce the performance discrepancy in continuous current (aka Iq in the case above).

Support material:

Originally posted by @mfussi66 in #36 (comment)

Fit the thermal model

          Let's proceed with identifying the parameters $R_t$ and $\tau$ robustly by covering a wide range of operating conditions with currents and temperatures (it'll certainly take a while to do so).

As usual, the validation will need to be performed on motors/setup/operating-conditions not seen during fitting.

Originally posted by @pattacini in #34 (comment)

Use `Simulink Test` to automatize regression tests

Simulink Test is a blockset specifically devoted to testing.

Since we have already developed a bunch of nice tools for communicating with the AMCBLDC board, Simulink Test will seamlessly integrate with them to carry out preliminary regression tests like:

  • changing modes
  • current control
  • logic control (e.g., the SW Current Limiter)

Also, we can produce nice reporting.

There's no hurry but we should definitely address it.

Here below some nice webinars we can inspect illustrating the perks of using a test harness and HIL:

Refactor AMCBLDC prj to expose library components

We aim to extract general-purpose components from the AMCBLDC project and put them in a shared basket/library to support other boards' FW.

Warning
We shall guarantee that AMCBLDC will remain 100% operational throughout the process with continuous testing.

Add documentation regarding code generation guidelines - Stint 1

Now that we have achieved some sort of expertise regarding code generation for an embedded board, it might be nice to create a .md document that highlights the best practices and settings to apply for an effective and flexible process.

For example, it could contain:

  • Simulink model settings
  • CMSIS settings
  • Best practices for Simulink blocks
  • Stateflow guidelines
  • a sprinkle of dictionary usage

CMSIS routines for `sin`/`cos` are not used in FOC

While I was looking at the generated code of the FOC in the AMCBLDC, I spotted that the trigonometric functions for sin and cos are implemented by resorting to std instead of CMSIS.

I spent quite some time investigating this issue and, from the code generation report, it seems that the replacement library for the Cortex-M correctly detects the presence of sin and cos although it doesn't apply the substitution.

To check the performance gain, we can simply replace std::sin and std::cos with arm_sin_f32 and arm_cos_f32. However, the problem still remains when it comes to code generation.

There are easy alternatives that recruit proper approximations of sin and cos but the reason why the link to CMSIS is not performed is unclear.

Definitely, worth investigating.

Analyze FOC timing of AMCBLDC and AMC2C

          Let me try to recap what I got from a F2F alignment with @sgiraz.
  1. There's pretty much NO difference between using STD or CMSIS ops on AMCBLDC and AMC2C.
  2. On the AMCBLDC, the FOC is taking up $8$ $\mu s$ and NOT $17$ $\mu s$. The difference is represented by the ADC operations.
  3. FOC takes up $14$ $\mu s$ on AMC2C, longer than on AMCBLDC.
  • Point 1 completes this issue โœ… We go with STD. See #75.
  • Follow-up question on Point 2: "Why does ADC last that long compared to FOC? Is there any margin for improvement?"
  • Follow-up question on Point 3: "Why is AMC2C slower than AMCBLDC?" We know this is an ongoing study and we're probably at the right point to contact ST.

cc @Nicogene @sgiraz @marcoaccame @maggia80 @mfussi66

Originally posted by @pattacini in #67 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.