Skip to content

Commit a2b1233

Browse files
committed
Update README; Update Getting Started page; Move panic() on FLASH_SAFE_EXECUTE_CORE_INIT_FAILURE to core1; Implement k_ff feed forward factor via CV_47;
1 parent 9345521 commit a2b1233

File tree

7 files changed

+19
-22
lines changed

7 files changed

+19
-22
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ So suggestions on how to improve things and bug reports are always much apprecia
3737
The wiki is also work in progress and will be updated to be as comprehensive as possible.
3838

3939
------------
40-
![rotating gif of RP2040-Decoder](https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages-dev/img/rotating.gif)
40+
<div style="display: flex; justify-content: space-between; align-items: center;">
41+
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages-dev/img/top.png" alt="Image 1" style="width: 50%;"/>
42+
<img src="https://raw.githubusercontent.com/gab-k/RP2040-Decoder/refs/heads/gh-pages-dev/img/bottom.png" alt="Image 2" style="width: 50%;"/>
43+
</div>
4144

4245

Software/CV.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ uint8_t CV_ARRAY_DEFAULT [CV_ARRAY_SIZE] = {
6262
0b00000000, //CV_44 -
6363
0b00000000, //CV_45 -
6464
0b00000000, //CV_46 -
65-
// TODO: Update controller CVs and implement/redefine k_ff in the speed controller initialization
6665
// Speed controller - Configuration /////////////////////////////////////////////////////////////////////////////////
67-
0b00110010, //CV_47 - Feed-forward gain k_ff = CV_47/10000 Default = 50 -> 0.005 //
66+
0b11100110, //CV_47 - Feed-forward factor k_ff in % = CV_47/255 Default = 230 -> 0.902 = 90.2% //
6867
0b00001010, //CV_48 - PID Control low pass filter time constant (tau) in ms //
6968
0b00000101, //CV_49 - PID Control sampling time t in ms //
7069
0b00011001, //CV_50 - PID Control I_Factor = CV_50/10 Default = 25 -> 2.5 //

Software/core0.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,15 +784,7 @@ int main() {
784784
while (!flash_safe_execute_core_init_done) {
785785
watchdog_update();
786786
}
787-
788-
busy_wait_ms(100);
789787

790-
791-
// Check for error calling flash_safe_execute_core_init() on core1
792-
if(get_error_state() & FLASH_SAFE_EXECUTE_CORE_INIT_FAILURE){
793-
panic("Error calling flash_safe_execute_core_init() on core1!"); //TODO: test
794-
}
795-
796788
// Check CV array for factory state of flash or missing ADC offset setup
797789
cv_setup_check();
798790

Software/core1.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ void controller_startup_mode(controller_parameter_t *const ctrl_par) {
180180
ctrl_par->startup.base_pwm_arr_i = (ctrl_par->startup.base_pwm_arr_i+1)%BASE_PWM_ARR_LEN;
181181
// Set ramp_up_mode flag to true
182182
ctrl_par->mode = PID_MODE;
183-
// multiply with constant value of 0.9 and set as current feed forward value for pid mode
184-
ctrl_par->feed_fwd = 0.9f * (float)ctrl_par->startup.level;
183+
// Multiply with k_ff constant and set as current feed forward value
184+
ctrl_par->feed_fwd = ctrl_par->startup.k_ff * (float)ctrl_par->startup.level;
185185
}
186186
}
187187

@@ -229,7 +229,6 @@ void controller_pid_mode(controller_parameter_t *const ctrl_par) {
229229
}
230230

231231
// General controller function gets called every x milliseconds where x is CV_49 i.e. sampling time (pid->t)
232-
// TODO: Consider fixed point arithmetic to improve performance...
233232
void controller_general(controller_parameter_t * ctrl_par) {
234233
// Change in direction -> reset previous derivative, error and integral parts and pwm_base_done
235234
const bool direction_changed = get_direction_of_speed_step(speed_step_target) !=
@@ -275,11 +274,16 @@ void init_controller(controller_parameter_t *const ctrl_par) {
275274
LOG(1, "Motor controller initialization...\n")
276275
// General controller variables
277276
ctrl_par->mode = STARTUP_MODE;
277+
ctrl_par->measurement = 0.0f;
278+
ctrl_par->measurement_prev = 0.0f;
279+
ctrl_par->measurement_corrected = 0.0f;
280+
ctrl_par->setpoint = 0;
278281
ctrl_par->feed_fwd = 0;
279282

280283
// Startup controller variables
281284
ctrl_par->startup.level = 0;
282285
ctrl_par->startup.base_pwm_arr_i = 0;
286+
ctrl_par->startup.k_ff = (float) CV_ARRAY_FLASH[46]/255;
283287
for (int i = 0; i < BASE_PWM_ARR_LEN; ++i) {
284288
ctrl_par->startup.base_pwm_arr[i] = 0;
285289
}
@@ -331,11 +335,6 @@ void init_controller(controller_parameter_t *const ctrl_par) {
331335
ctrl_par->pid.k_p_m_1 = (ctrl_par->pid.k_p_y_1 - ctrl_par->pid.k_p_y_0) / ctrl_par->pid.k_p_x_1;
332336
ctrl_par->pid.k_p_m_2 = (ctrl_par->pid.k_p_y_2 - ctrl_par->pid.k_p_y_1) / ctrl_par->pid.k_p_x_2;
333337

334-
// General Controller initialization
335-
ctrl_par->measurement = 0.0f;
336-
ctrl_par->measurement_prev = 0.0f;
337-
ctrl_par->measurement_corrected = 0.0f;
338-
ctrl_par->setpoint = 0;
339338
LOG(1, "Motor controller initialization done!\n")
340339
}
341340

@@ -356,6 +355,7 @@ void core1_entry() {
356355
flash_safe_execute_core_init_done = flash_safe_execute_core_init();
357356
if (flash_safe_execute_core_init_done != true){
358357
set_error(FLASH_SAFE_EXECUTE_CORE_INIT_FAILURE);
358+
panic("Error calling flash_safe_execute_core_init() on core1!");
359359
return;
360360
}
361361

Software/core1.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef struct startup_parameters_t {
4242
uint16_t level; /**< Latest level */
4343
uint16_t base_pwm_arr[BASE_PWM_ARR_LEN]; /**< base pwm ring buffer array */
4444
uint16_t base_pwm_arr_i; /**< base pwm ring buffer array index */
45+
float k_ff; /**< Feed forward factor */
4546
}startup_parameters_t;
4647

4748
/**

Software/shared.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "shared.h"
88

9-
// TODO: Implement enum typedef for speed steps, also getter and setter functions checking validity of speed step values.
9+
// TODO: Implement getter and setter functions for speed steps, checking validity of speed step values.
1010
speed_step_t speed_step_target = SPEED_STEP_REVERSE_STOP;
1111
speed_step_t speed_step_target_prev = SPEED_STEP_REVERSE_STOP;
1212
bool cv_setup_check_done = false;

docs/sphinx/source/gs/getting_started.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ In case you are ordering from JLCPCB it is recommended to use the `Fabrication-T
2121
If you got a RP2040-Decoder with USB the easiest way to get the RP2040-Decoder up and running is to just use the precompiled .uf2 file in the latest `release <https://github.com/gab-k/RP2040-Decoder/releases>`_ and skip to :ref:`flashing_the_software`.
2222

2323
However sometimes you might want to build by yourself, be it for debugging or to make your own modifications to the source code.
24-
The easiest way to do this is to just use `Visual Studio Code <https://code.visualstudio.com/>`_ and the Raspberry Pi Pico extension.
24+
The easiest way to do this is to just use `Visual Studio Code <https://code.visualstudio.com/>`_ and the `Raspberry Pi Pico extension <https://marketplace.visualstudio.com/items?itemName=raspberry-pi.raspberry-pi-pico>`_.
2525
The `official documentation <https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf#vscode-extension>`_ of the Pi Pico does a great job of explaining this in detail.
2626

27-
Note: If you are building for Hardware Rev 0.3 or below change the board defintion in your CMakeLists.txt file to: "RP2040-Decoder-board-legacy.h"
27+
.. note::
28+
- Make sure to choose the correct board definition file in your CMakeLists.txt file for example ``RP2040-Decoder-board-Rev-1_0`` for Hardware Rev 1.0.
29+
- In VSCode open the "Software" subdirectory for the extension to detect you project automatically.
2830

2931
.. _flashing_the_software:
3032

0 commit comments

Comments
 (0)