Skip to content

Instantly share code, notes, and snippets.

View mgronhol's full-sized avatar

Markus Grönholm mgronhol

View GitHub Profile
@mgronhol
mgronhol / FindParallels.py
Created May 4, 2020 09:51
Find a set of parallels for machining vise
#!/usr/bin/env python
# https://github.com/mgronhol/infeasible
import Infeasible
solution = Infeasible.Solution()
## Find a set of parallels for a milling vise to get suitable clamping depths
@mgronhol
mgronhol / libMat.py
Created February 5, 2020 23:21
Generate mat-file containing a 2D array of doubles.
#!/usr/bin/env python3
import struct
miINT8 = 1
miINT32 = 5
miUINT32 = 6
miDOUBLE = 9
miMATRIX = 14
mxDOUBLE_CLASS = 6
@mgronhol
mgronhol / dijkstra.py
Created January 27, 2018 15:52
Dijkstra's algorithm
#!/usr/bin/env python2.7
nodes = ["A", "B", "C", "D"]
conns = {}
@mgronhol
mgronhol / flapflap.v
Created May 23, 2017 19:29
Flip-flop in verilog
module flapflap(d,clk,q,qn);
input d,clk;
output q,qn;
reg q,qn;
initial
begin
q=0;
qn=1;
@mgronhol
mgronhol / servo.c
Created March 4, 2017 10:05
Small servo loop
float servo( motor_t *motor, int target ){
int pos_error = target - motor->enc.current_value;
int velocity = motor->enc.current_value - motor->prev_position;
float v_error, out, q;
motor->prev_position = motor->enc.current_value;
/* P for position */
motor->v_target = 0.99f * pos_error;
/* P + lowpass for velocity */
@mgronhol
mgronhol / Makefile
Created January 30, 2017 14:19
Makefile for building firmware for STM32F746ZG using STM32Cube & gcc
GCC_BIN = C:\\Users\\marku\\Desktop\\arm-embedded-env\\gcc\\bin\\
STM32CUBE = C:\\Users\\marku\\Desktop\\arm-embedded-env\\STM32Cube_FW_F7\\
LINKER_SCRIPT = ./STM32F746ZGTx_FLASH.ld
INCLUDE_PATHS = -I$(STM32CUBE)Drivers/CMSIS/Device/ST/STM32F7xx/Include -I$(STM32CUBE)Drivers/STM32F7xx_HAL_Driver/Inc -I$(STM32CUBE)Drivers/BSP/STM32F7xx_Nucleo_144 -I. -IInc/ -I$(STM32CUBE)Drivers/CMSIS/Include
FLOAT_ABI = hard
###############################################################################
AS = $(GCC_BIN)arm-none-eabi-as
@mgronhol
mgronhol / noppapainotin.py
Created December 14, 2016 16:46
Tool to bin dice throwings
#!/usr/bin/env python3
import math, random
def simuloi_nopanheittoa( d, N ):
out = []
for i in range( N ):
out.append( random.randint( 1, d ) )
return out
@mgronhol
mgronhol / bitteja.java
Created December 1, 2016 19:07
Some simple bit handling
// options
final int OPTION1 = 0;
final int OPTION2 = 1;
final int OPTION3 = 2;
// ad nauseam ...
// usage: if( getBit( flags, OPTION3 ) ){ ....
boolean getBit( int value, int pos ){
@mgronhol
mgronhol / libModel.py
Last active August 29, 2016 18:14
Dataflow + stack machine
#!/usr/bin/env python
import math
_next_id = -1
def generate_id():
global _next_id
_next_id += 1
return _next_id
#!/usr/bin/env python3.4
import sys
import shlex
class ParserError(Exception):
pass