Skip to content

Instantly share code, notes, and snippets.

@SebastianBitsch
SebastianBitsch / ota_update_esp.cpp
Created April 12, 2025 01:14
Update ESP boards over-the-air
/*
* ESP32 HTTP OTA Update Example
* This sketch demonstrates how to check for and download firmware updates
* from an HTTP server.
*/
#include <WiFi.h>
#include <HTTPClient.h>
#include <HTTPUpdate.h>
@SebastianBitsch
SebastianBitsch / load_env.py
Last active March 29, 2025 15:25
Read `.env` file to environment in Python
# Usage:
# load_env(path = ".env")
# API_KEY = os.getenv('API_KEY', 'some-secret')
import os
def load_env(path: str) -> None:
"""
Function for loading .env file for secret API keys etc. and write them to the global enviroment
I have the .env file located in the top ws dir, but could be anywhere. Gets rid of dotenv dependency
@SebastianBitsch
SebastianBitsch / mesh2ply.py
Created March 25, 2025 08:47
Convert a mesh to a .ply file
import argparse
import open3d as o3d
# Convert mesh file to .ply point clouds
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--input_path', type=str, help='Path of the file to convert, output will be in the same dir if no output is given')
parser.add_argument('--ouput_path', type=str, help='Path of where to save the file')
parser.add_argument('--n_points', type=int, default=100_000, help='How many points the ply file should contain')
@SebastianBitsch
SebastianBitsch / count_parameters.py
Last active March 20, 2025 11:45
Count pytorch model parameter
import torch
def count_parameters(model):
"""
Nice to have helper function stolen from:
https://discuss.pytorch.org/t/how-do-i-check-the-number-of-parameters-of-a-model/4325/9
"""
return sum(p.numel() for p in model.parameters() if p.requires_grad)
@SebastianBitsch
SebastianBitsch / terminal_plots.py
Last active February 21, 2025 21:20
Python terminal time-series plots
"""
-- Use example in ROS2 terminal:
self.get_logger().info(f"X: {plot_bipolar(self.kf.x[3])}, Y: {plot_bipolar(self.kf.x[4])}, Z: {plot_bipolar(self.kf.x[5])}")
-- Output:
[INFO] [1740172663.636000550]: X: |..........|@.........|, Y: |..........|..........|, Z: |..........|..........|
[INFO] [1740172663.685122760]: X: |..........|@@........|, Y: |..........|@.........|, Z: |..........|..........|
[INFO] [1740172663.735189229]: X: |..........|@@........|, Y: |..........|@.........|, Z: |..........|@.........|
[INFO] [1740172663.785187161]: X: |..........|@.........|, Y: |..........|@@........|, Z: |..........|@@........|
[INFO] [1740172663.836043554]: X: |..........|..........|, Y: |..........|@@........|, Z: |..........|@@........|
@SebastianBitsch
SebastianBitsch / stl2obj.py
Created January 24, 2025 14:45
Convert CAD-model to a .obj file in python with Open3D
import os
import argparse
import numpy as np
import open3d as o3d
# Just a basic dummy material
material_contentes = """
newmtl material_0
Ka 0.40000000 0.40000000 0.40000000
@SebastianBitsch
SebastianBitsch / list_cameras.py
Last active March 8, 2025 21:51
List available OpenCV cameras
import os
import sys
from contextlib import contextmanager
import cv2
@contextmanager
def quiet():
"""
Temporarily redirect stdout and stderr to devnull to suppress OpenCV's warnings.
@SebastianBitsch
SebastianBitsch / stl2ply.py
Created October 3, 2024 14:33
Convert CAD-model to point cloud (`.stl` to `.ply`)
import argparse
import open3d as o3d
# Convert .stl models to .ply point clouds
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--file', type=str, help='Path of the file to convert, output will be in the same dir named *.ply')
parser.add_argument('--n_points', type=int, default=10000, help='How many points the ply file should contain')
parser.add_argument('--draw_output', type=bool, default=False, help='Should the resulting file be shown in plot')
@SebastianBitsch
SebastianBitsch / README.md
Last active March 20, 2025 11:36
Minimal python scripting language

Minimal Python scripting language

The example contains just a simple command interpreter for setting, getting, and persisting variables. It is meant as a demo that could be extended with more commands and more complex functionality to use in for instance ROS2.

Uses a command lookup system (COMMANDS dictionary) to map user input to the appropriate functions and execute them. The user interacts with the program through a basic REPL (Read-Eval-Print Loop) in the command_loop().

Commands:

  • help : Print information about commands
  • set : Set a variable with a given name to a specific value.
@SebastianBitsch
SebastianBitsch / rdt.py
Last active March 31, 2024 11:31
RDT (Rapidly-exploring Dense Tree) algorithm Python
import numpy as np
def project_point_to_linesegment(start: np.ndarray, end: np.ndarray, p: np.ndarray) -> np.ndarray:
"""
Vectorized operation for projecting a point onto on array of line segments.
Follows the procedure outlined in: https://stackoverflow.com/a/1501725/19877091
Parameters:
start (np.ndarray) (N, 2): Starting point of the line segments.
end (np.ndarray) (N, 2): Ending point of the line segments.