Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simulink to C++ - Driver Interface #376

Open
BlakeFreer opened this issue Jan 10, 2025 · 0 comments · Fixed by #381
Open

Simulink to C++ - Driver Interface #376

BlakeFreer opened this issue Jan 10, 2025 · 0 comments · Fixed by #381
Assignees

Comments

@BlakeFreer
Copy link
Contributor

BlakeFreer commented Jan 10, 2025

Development Instructions

Our control system is current writting in Simulink. We are converting it to C++. This task converts the DriverInterface model which is responsible for processing driver inputs (steering wheel angle, accelerator / brake pedal positions, brake lights, etc).

You will fill in a class which has an .Update() method to represent the DriverInterface behaviour.

Setup

  1. Clone this repo https://github.com/macformula/vehicle_control_system
  2. Open the folder in Matlab r2022b. You will need Simulink installed.
  3. In the Matlab file explorer, right click on the src/ folder and click Add to path -> Selected folders and subfolders.

    You may need to do this each time you open Matlab.

  4. Open src/controller.slx. Find the blue driver_interface block. This is what you will be recreating in C++.

Development

  1. In driver_interface.hpp, define structs for the input and outputs (shows as variables on the left and right sides of the block, respectively).
    • You may need to define "enum classes" for the GOV_ input/outputs. See src/enums in the repo.
    • You can omit DI_*_ prefix to the variables. However, use the * character (meaning wildcard in the previous expression) to figure out the variable data type (p and V means float, b meens bool, and e mean enum).
    • Variable names should be in lower_snake_case following the style guide.
  2. Double click on the DI block in Simulink to see inside. Implement this behaviour inside the .Update function in the driver_interface.cc file.
  3. Write tests in driver_interface_test.cc. See example.

Notes

Most of the functions inside the DI block are implemented in the shared/controls folder. You should #include the relevant files and call those functions.

For example, the yellow Finite State Machine is implemented in shared/controls/driver_interface_fsm.hpp. The potentiometerProcessing block is roughly implemented as isInRange() in shared/controls/driver_interface_error_handling.h.

However, some of the functions are very simple and you can choose to "inline" them (implement directly as code instead of calling a function). The function in shared/controls/steering_angle.h is a good candidate for inlining

Resources

See the AMK, BatteryMonitor, and Simple_VD PRs for inspiration. They are implementing other blocks in the Simulink model.

@BlakeFreer BlakeFreer linked a pull request Jan 12, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants