Skip to content

Instantly share code, notes, and snippets.

View ryansturmer's full-sized avatar

Ryan Sturmer ryansturmer

View GitHub Profile
@ryansturmer
ryansturmer / review_1_sensor.py
Last active October 25, 2024 13:56
Python Review - Sensor Code?
import threading
import struct
import serial
import time
class OmegaSensor(object):
def __init__(self, comname):
self.comname = comname
self._stop = False
self.worker = None
@ryansturmer
ryansturmer / review_2_bms.c
Last active December 4, 2024 13:54
Embedded C Code Review Example 2 - Reading a Battery Fuel Gauge
#include <stdint.h>
#include <stdbool.h>
#define COULOMB_COUNT_POLL_INTERVAL 5000 // 5 seconds
#define COULOMB_REMOVAL_INTERVAL 2000 // 2 seconds
#define FUEL_GAUGE_ADDRESS 0x55
#define FUEL_GAUGE_POWER_OK 0x01
#define SYSTEM_TICK_MS 1
// HAL Functions, assume these are defined elsewhere
@ryansturmer
ryansturmer / review_1_uart.c
Created October 25, 2024 12:22
Embedded C Code Review Example 1 - UART Command Prompt
#include <stdint.h>
#include <string.h>
#define UART_RX_BUFFER_SIZE 64
#define COMMAND_BUFFER_SIZE 32
// Pseudo HAL for UART - definitions elsewhere
void UART_SendString(char *str);
void UART_ReceiveInterruptEnable(void);
void UART_ReceiveInterruptDisable(void);
@ryansturmer
ryansturmer / monty2.py
Created January 18, 2021 04:43
Monty Hall Problem
# Monty Hall Problem Simulation
# Author: Ryan Sturmer
#
import random
def play_round(doors, switch):
# Choose the location of the car
car = random.randint(1, doors)
@ryansturmer
ryansturmer / archinstall.sh
Last active July 18, 2019 14:31
Script for Building a Beaglebone Black Archlinux ARM system with JupyterLab.
#!/bin/bash
TMPDIR=.tmp
DEVICE=/dev/mmcblk1
CURDIR=`pwd`
PARTITION=$DEVICE"p1"
PACKAGES="\
base-devel git vim \
nodejs npm \
jupyter jupyter-notebook jupyterlab python2-ipykernel python-numpy python-scipy python-pandas python-requests \
{
"records": [
{
"t": 0,
"ch": "C",
"dir": "out",
"data": "\u0004"
},
{
"t": 1,
@ryansturmer
ryansturmer / fabmo-dev.sh
Last active December 3, 2016 23:24
Convert a binary installation to a development one on an intel edison.
systemctl stop fabmo fabmo-updater
cd /fabmo
mount -w -o remount /
rm -rf engine updater
git clone https://github.com/FabMo/FabMo-Engine.git ./engine
git clone https://github.com/FabMo/FabMo-Updater.git ./updater
cd /fabmo/updater
npm install
touch install_token
@ryansturmer
ryansturmer / miter_panels.py
Created November 3, 2016 03:46
Functions for generating G-Code for mitered box panels
from math import cos, sin, tan, atan2, atan, pi
def gx(n, x=None,y=None,z=None, f=None):
retval = ['G%d' % n]
for a,b in zip(('X','Y','Z','F'), (x, y, z, f)):
if b is not None:
if a == 'F':
b *= 60.0 # Feedrates in ipm not ips
retval.append(' %s%0.4f' % (a,b))
return ''.join(retval)
@ryansturmer
ryansturmer / paint.py
Created October 15, 2016 03:34
Convert @PrimitivePic output to g-code for painting (quadratic bezier curves only)
import xml.etree.ElementTree as ET
import sys
import math
import re
import argparse
import os
def gx(n, x=None,y=None,z=None, f=None):
retval = ['G%d' % n]
for a,b in zip(('X','Y','Z','F'), (x, y, z, f)):
@ryansturmer
ryansturmer / friction-joint.js
Last active August 20, 2016 04:05
Locking joint
function getParameterDefinitions() {
return [
{ name: 'detents', type: 'int', initial: 12, caption: "Detents" },
{ name: 'holeDiameter', type: 'float', initial: 0.25, caption: "Bolt Diameter" }
];
}
function main(params) {
var holeDiameter = params.holeDiameter;
var detents = params.detents;