Skip to content

Instantly share code, notes, and snippets.

View martinstarkov's full-sized avatar
🐢

Martin martinstarkov

🐢
View GitHub Profile
@martinstarkov
martinstarkov / build_web_dependencies.sh
Last active February 22, 2026 16:52
Build SDL3 (+ SDL_image, SDL_ttf, SDL_mixer) for WebAssembly with Emscripten
: '
Put the below lines inside a separate version file: root/cmake/SDLVersions.cmake
set(SDL_VERSION 3.4.0)
set(SDL_IMAGE_VERSION 3.4.0)
set(SDL_TTF_VERSION 3.2.2)
set(SDL_MIXER_VERSION 3.1.2)
Or alternatively hard code them down below if your CMake does not need the versions
'
@martinstarkov
martinstarkov / event_handler.cpp
Last active July 16, 2024 18:27
Convenient Event Handler Implementation
#include <iostream>
#include <functional>
#include <unordered_map>
#include <type_traits>
#include <cstdint>
struct Event {
public:
virtual ~Event() = default;
};
@martinstarkov
martinstarkov / opengl_layout_reflection.cpp
Last active July 16, 2024 13:34
Automatic OpenGL Vertex Buffer Layout Determination (Reflection) using Luple
#include <array>
#include <cstdint>
#include <iostream> // for debugging only
#include <type_traits>
#include <utility>
#include <vector>
// Luple from: https://github.com/alexpolt/luple
template <typename... TT>
@martinstarkov
martinstarkov / stepper_swapper.ino
Last active July 16, 2024 13:35
Arduino Stepper Swapper
#include <Arduino.h>
#include <Servo.h>
#include <string.h>
class ServoMotor {
public:
ServoMotor(int pin, int cw, int stop, int ccw, int delay)
: pin_{ pin }, cw_{ cw }, stop_{ stop }, ccw_{ ccw }, delay_{ delay } {}
@martinstarkov
martinstarkov / identify_matrices.m
Created June 16, 2024 04:52
Identify matrices and target selection
input = true;
h = 0.01;
data = load('no_input_test.mat').IO_data;
if (input)
data = load('stair_test.mat').IO_data;
end
@martinstarkov
martinstarkov / coriolis_identify_2_state.m
Last active June 15, 2024 01:48
Identification including coriolis force
input = true;
h = 0.01;
data = load('no_input_test.mat').IO_data;
if (input)
data = load('stair_test.mat').IO_data;
%data = load('/MATLAB Drive/data/n_04_06_08_stair_45_2.mat').IO_data;
%data = load('/MATLAB Drive/data/0_step_20_2.mat').IO_data;
@martinstarkov
martinstarkov / determine_equilibrium.m
Created June 13, 2024 21:02
Script for determining helicopter setup equilibrium conditions
% Example usage
eq_angle_deg = 15; % degrees
data = load('/MATLAB Drive/ramp_test.mat').IO_data;
[x_eq, u_eq] = get_eq_conditions(eq_angle_deg, data);
% Output
fprintf('x_eq(1) = %.3f\n',x_eq(1));
fprintf('x_eq(2) = %.3f\n',x_eq(2));
@martinstarkov
martinstarkov / mpc_matrices.m
Created June 13, 2024 20:26
Script for determining matrices of MPC
N = 4;
A = [5 6 7; 8 9 10; 11 12 13];
B = [1 2 3]';
Q = [5 0 0; 0 1 0; 0 0 0.01];
R = 0.1;
x0 = [1, 2, 3]';
@martinstarkov
martinstarkov / determine_struct_layout.cpp
Last active July 16, 2024 13:37
Struct Member Determination (Reflection) using Luple
#pragma once
#include <utility>
#include <type_traits>
namespace luple_ns {
//type list
template<typename... TT> struct type_list {
@martinstarkov
martinstarkov / observer.m
Created June 5, 2024 18:46
Luenberger Observer
h = 0.001;
c = [-10.6561, 0.0018, 0.237, -4.8731e-05, 828.106, 0.0063898, -1.7446, -0.485];
x_eq = [0.27, 0, 200];
[Ad, Bd, Cd, Dd] = discrete_matrices(x_eq, c);
Ld = -place(Ad', Cd', [0.9, 0.91, 0.92])'
obsmat = obsv(Ad,Cd);