Skip to content

Instantly share code, notes, and snippets.

View ctmakro's full-sized avatar

Qin Yongliang ctmakro

View GitHub Profile
@ctmakro
ctmakro / klipper_on_win7.md
Last active May 15, 2023 19:45
20210526 How to compile and run Klipper (highest performance 3D printer firmware with most awesome features) on Anycubic Kossel (Arduino Mega / atmega2560) + OctoPrint from Windows 7 x64

How to compile and run Klipper on atmega2560 + OctoPrint from Windows 7 x64

Situation

  • I own an Anycubic Kossel delta 3D printer, running custom Marlin firmware, custom mainboard(atmega2560), connected to my PC via USB (USB Serial), controlled mostly via Printrun(Pronterface)
  • I want ultra high performance and latest improvements in my 3D printer, with the help from Klipper software/firmware
  • Normally you should go get an Raspberry Pi and do everything (compile/install Klipper / OctoPrint) from there, but I don't have a Pi, don't want to mess with the cables, decided to run Klipper from my PC

Steps

@ctmakro
ctmakro / test.cpp
Last active April 28, 2020 18:01
Correct way to do precisely timed routine task on Arduino
/*
With an Arduino,
If you want to:
1) execute a function precisely every N microseconds (or precisely 1,000,000/N times every second),
REGARDLESS of the running time of that function
2) obtain a precision of +-4 microseconds with NO ACCUMULATION OF ERROR
3) use no 3rd party libraries
Then this is for you.
*/
@ctmakro
ctmakro / example.c
Created May 3, 2018 09:11
_kbhit() equivalent (peek UART buffer before getchar() or scanf()) on Xilinx Zynq Baremetal.
// return true if there is character in uart recv buffer, false otherwise.
int peek(){
#include <xuartps_hw.h>
#include <xparameters.h>
return XUartPs_IsReceiveData(XPAR_PS7_UART_0_BASEADDR);
}
// it is recommended to use inbyte() to read a byte after peek() returned true.
@ctmakro
ctmakro / ipython_display.py
Last active April 15, 2024 03:22
Display numpy ndarray as Image in Jupyter/IPython notebook
# if input image is in range 0..1, please first multiply img by 255
# assume image is ndarray of shape [height, width, channels] where channels can be 1, 3 or 4
def imshow(img):
import cv2
import IPython
_,ret = cv2.imencode('.jpg', img)
i = IPython.display.Image(data=ret)
IPython.display.display(i)
@ctmakro
ctmakro / rosetta.py
Last active October 30, 2017 20:39
you should not know what this is
# tacos=[[2.7647068559860712, -0.008816344965933138, 0.08419820920066164], [4.1482390698137275, 0.004365272677300839, 0.059974440683546126], [4.799411832657377, 0.012794506986796655, 0.07305748780077449], [2.395640662714245, 0.005136789959712116, 0.055235542912785984], [3.3942322982802495, 0.0034807961045444052, 0.058021672551073204], [4.556883550968967, 0.006043932006157158, 0.050294840880930024], [2.1072139294765933, 0.019171523718931313, 0.15339955024246338], [3.3087723737032717, 0.02240615211003253, 0.1343706158894652], [4.568062436714624, 0.01720806864461718, 0.07717739475940219]]
# psoas=[[1.0832688044403371, 1.0456262964311989], [1.0823437836374254, 0.8830063845929389], [0.9780701248134204, 1.016855183151065]]
test=None
test999=None
@ctmakro
ctmakro / trilaterate_iterative.py
Last active February 3, 2019 13:04
Iterative Trilaterate Algorithm in Python3
import numpy as np
def normalized(v):
norm = np.sqrt(np.sum(v**2))
return v / norm
# Trilateration to find the target point, given positions of 3 points, and distances(radiuses)
def trilaterate(points, distances):
precision = 1e-3
iteration = 1000
@ctmakro
ctmakro / trilaterate.py
Last active August 23, 2017 14:01
Trilaterate algorithm in Python3 with NumPy
import numpy as np
def trilaterate(points, distances):
# ported from https://github.com/gheja/trilateration.js
# points -> list of np arrays in the form of [[x, y, z], [x, y, z]
# distances -> np array [r1, r2, r3]
p1,p2,p3 = points
r1,r2,r3 = distances
def norm(v):
return np.sqrt(np.sum(v**2))
@ctmakro
ctmakro / osrl.bat
Last active August 19, 2017 16:28
batch script to initialize osim-rl on windows
REM make sure you have miniconda installed
cd c:\
conda create -n osrl -c kidzik opensim git python=2.7
activate osrl
git clone https://github.com/stanfordnmbl/osim-rl
git clone https://github.com/ctmakro/stanford-osrl
pip install pyro4 pymsgbox
@ctmakro
ctmakro / ddpg.py
Created January 17, 2017 06:55
DDPG, train 64*50 every 50 steps, 1/f^2 noise added
from __future__ import print_function
# Deep Deterministic Policy Gradient Method
# David Silver et al.
# implemented in plain Keras, by Qin Yongliang
# 2017 01 13
# heavily optimized for speed, lots of numpy flowed into tensorflow
# 2017 01 14
@ctmakro
ctmakro / ddpg.py
Created January 14, 2017 08:03
Deep Deterministic Policy Gradient
from __future__ import print_function
# Deep Deterministic Policy Gradient Method
# David Silver et al.
# implemented in plain Keras, by Qin Yongliang
# 2017 01 13
'''
summary