## Some random links on uses of Convex relaxations, in particular Semidefinite programming

Problems involving outer products of vector variables can be relaxed into semidefinite programs. That’s a general trick. Then the low rank bit from SVD is an approixmate solution for the vector

https://en.wikipedia.org/wiki/Matrix_completion

convex relaxation for distributed optimal control

http://ieeexplore.ieee.org/document/7464306/

graph matching in relation to Image correspondence

Permutation matrices have sum of rows and columns must be 1 constraint, is one relaxation.

quickMatch. Actually, not convex programming but was the root of the chain of references I ‘m digging through

http://openaccess.thecvf.com/content_ICCV_2017/papers/Tron_Fast_Multi-Image_Matching_ICCV_2017_paper.pdf

https://dl.acm.org/citation.cfm?id=2600314

matchALS

www.cis.upenn.edu/~kostas/mypub.dir/xiaowei15iccv.pdf

https://arxiv.org/abs/1402.1473

https://vision.in.tum.de/research/convex_relaxation_methods

Finding MaxCut approximation of a graph is a classic one

Quantum Semidefinite programming course

Density matrices have a semidefinite constrina (non negative probabilities)

https://cs.uwaterloo.ca/~watrous/CS867.Winter2017/

Sum of Squares is a semidefinite program that can guarantee that lyapunov functions actually work

## Cart Pole Trajectory optimization using Cvxpy

I’ve been watching Russ Tedrake’s underactuated robotics and been trying some stuff out. The Drake package probably does this stuff better. Also IpOpt and Snopt are the libraries that get mentioned when people want to do this stuff for real.

It’s  too slow to be practical. That is mostly the fault of the cvxpy overhead. The ECOS solver itself says that it solves each iteration in about 0.02 seconds on my macbook.

The idea is to use linearized dynamics as constraints. Then iteratively ask cvxpy to solve for us. Until hopefully it converges. This is Sequential Convex Programming https://web.stanford.edu/class/ee364b/lectures/seq_slides.pdf

I used the discretization of the equations of motion using the mehotd described here https://epubs.siam.org/doi/pdf/10.1137/16M1062569

It is possible I did it right.

The Hermite Collocation for the trajectory and trapezoidal for the control

If we used just an absolute value cost, this all would be a linear program. Something to consider. Also CVXOPT would probably be faster.

It hurts me that the constraint and cost matrices are banded and could be solved so quickly. But the next level up in programming complexity takes a lot more work it seems to me.

This is the result

Green is cart acceleration. You can see it slamming into the maximum acceleration constraint

Blue is pole angle and orange is angular velocity. So it does a pretty good job. For some settings it is just awful though.

## Making a Van Der Graaf Generator

Will has been juicin’ to make a Van der Graaf generator. Similar to the Stirling engines, we followed youtube instructions to make it out of trash (soda bottles and soda cans and tape) and failed miserably.

We were mostly following this video https://www.youtube.com/watch?v=vfvjGeOGoBU

Yesterday, we took the gloves off and went to home depot. We used a trash fan motor which is awesome. 3d Printed some pieces for mounting the motor and for mounting the roller on the shaft with a press fit.

https://cad.onshape.com/documents/5016468595aba2e0189feaa4/w/5325496b7d68ecef269a238a/e/3cc572cbcee673b79b85caba

Big ole 4″ pvc is the stalk. A flange to mount to the base which is a nice circle wood from the nice wood section of . Used two ikea bowls as the globe. I think it is important to have the upper roller somewhat deeply inside the globe?

We’re using pantyhose as a belt. Sort of the waist area stretched out to be a loop. It is just rubbing on the fixed top pvc roller. Maybe wrapping that in teflon tape would make it even better? The pantyhose is pure nylon. Nylon and pvc are towards opposite ends of the triboelectric series, which is important for the thing to work, but teflon is even farther down.

We used some brushes from home depot as electrical brushes. Might be overkill.

We wrapped the lower roller in more pantyhose to make a bulge. Counterintuitively, this bulge is supposed to keep the belt centered?

We were getting pretty wimpy sparks until we installed to lower brush and properly grounded it. I guess that is really important. Now they are pretty beefy maybe a couple centimeters. You can definitely see them and they sting a bit.

All in all a success!

## LQR with CVXPY

Holy crap this was easy.

And I was able to easily add a constraint on the available force. Hot damn. It is a ridiculously tiny problem I guess, but still pretty damn cool. 0.002 second runtime.

## STM32F411 Discovery Board Getting started

Bought one of these discovery boards for 15\$ from digikey. I like the built in stuff, like the 9axis mems device. I don’t enjoy wiring up little boards particularly and it makes every project so ephemeral.

http://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-eval-tools/stm32-mcu-eval-tools/stm32-mcu-discovery-kits/32f411ediscovery.html

I am concerned that I should have gotten the older board.

User manual has pin connectors

http://www.st.com/content/ccc/resource/technical/document/user_manual/e9/d2/00/5e/15/46/44/0e/DM00148985.pdf/files/DM00148985.pdf/jcr:content/translations/en.DM00148985.pdf

It’s in platform.io as

disco_f411ve

Huh it only supports STM32Cube? I kind of wanted to try libOpenCM3

start a project with

platformio init –board disco_f411ve

platformio run

The examples are invaluable

https://github.com/platformio/platform-ststm32/tree/develop/examples

ok. There is a blink for the Hardware abstraction layer (HAL) and Low level (LL)

Hmm. Neither blink examples work off the bat. SYS_CLOCK is undefined for Low level

and board not supported in the HAL.

Alright let’s try libopencm3

https://github.com/libopencm3/libopencm3-examples

make in top directory first

follow directions to init submodule

alirght I guess I need to download the arm toolchain

https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads

I put them on my path

export PATH=~/Downloads/gcc-arm-none-eabi-7-2017-q4-major/bin:\$PATH

Then ran make

also need to apt install gawk

editted the Makefile of miniblink

https://github.com/libopencm3/libopencm3/blob/master/ld/devices.data

stm32f411re stm32f4 ROM=512K RAM=128K

that’s the right config even though re is wrong

Okay was getting weird error

sudo make flash V=1

the V=1 gives verbose

I may have had to apt install openocd?

Need to run under sudo. Go fig.

Alright got some blinking! WOOO

Ah I see. PD12 is PortD12. Makes sense.

## Trying Platform.io

PlatformIO and Visual Studio Take over the World

http://platformio.org/

Somehow I was not aware of this thing. It is a build tool for microcontrollers

Seems like people basically like it. 1000+ stars on github

python -m pip install -U platformio

make a folder

platformio init –board icestick

Holy crap. Is this thing going to download and setup the tools? THAT. IS. AWESOME. If it works.

Better yet clone this bad boy

https://github.com/platformio/platformio-examples

https://github.com/platformio/platformio-examples/tree/develop/lattice_ice40/lattice_ice40-leds

go to the blink folder.

platformio run

platformio run –target upload

Holy. Hell. It worked. THAT IS NUTS.

The commands it ran to compile

Hmm. I’m puzzled. Where did this come from? How did it know counter.v?

Mecrisp has an icestick version. Intriguing (Mecrisp is a forth implementation)

https://github.com/platformio/platform-lattice_ice40/tree/develop/examples/leds

had to sudo apt install libreadline6 and gtkwave to run simulation

I had to follow these instructions to get the FTDI device to work

https://stackoverflow.com/questions/36633819/iceprog-cant-find-ice-ftdi-usb-device-linux-permission-issue

and change the platformio.ini file to say icestick instead of icezum. Actually i don’t think that is necessary.

## Cart Pole using Lyapunov and LQR control, OpenAI gym

We’re having a lot of trouble hacking together a reinforcement learning version of this, so we are taking an alternative approacg, inspired by wtaching the MIT underactuated robotics course.

http://underactuated.csail.mit.edu/underactuated.html?chapter=acrobot

It took some pen and paper to get the equations of motion (which are maybe right?).

openai gym has

We switch over to LQR when the y position of the pole is above a certain height

https://en.wikipedia.org/wiki/Linear%E2%80%93quadratic_regulator

This scipy function solves the algebriac ricatti equation in the ocntinous time infite horizon section

https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.linalg.solve_continuous_are.html

Things that helped: Trying to balance pole first from upright position then from downright.

Tuning weights for theta and thetadot. Thetadot was too small made it unstable

Hacked in the LQR control by adjusting force_mag variable. Nasty.

Put it some slight compensation for a delayed observation, which reflects our actual sensor system

## Linksprite CNC machine

I’m impressed with the package in the box. Well organanized.

Putting it together took maybe 4 hours, half watching The Wire.

The x-axis screw is not fitting. I’m hoping the end is just ground incorrectly.

Nope. This has been a huge pain. They sent me the wrong screw. There are 8mm 4mm and 2mm pitch T8 rods. They have 1 2 and 4 starts to their threading. I have bought the maximal number of incorrect rods. I now have in posession the 4mm pitch rod I need. Figuring this out has set me back a month and another 30\$. I am annoyed.

There is a crack in the z-axis printed part. Epoxy should fix it.

open up arduino serial monitor

115200 baud both NL & CR

Hmm. LinuxCNC is more complicated than I thought. It seems installing it on my regular ubuntu 14.04 is not an option without a lot of dangerous futzing. Uses a real-time special kernel.

http://linuxcnc.org/docs/devel/html/code/building-linuxcnc.html

whenever it didn’t work i apt-get installed whatever was missing.

I also had to add a non redistributable when that error came up.

make

Two Control Guys. One in python one in java

https://github.com/vlachoudis/bCNC

https://github.com/winder/Universal-G-Code-Sender

Pycam and Blendercam do 3d models. Pycam appears to be defunct

http://pycam.sourceforge.net/

go to folder and make.

The website seems wrong. The links aren’t.

Build error

https://sourceforge.net/p/pycam/mailman/pycam-devel/

http://blendercam.blogspot.com/

Pcb

https://github.com/pcb2gcode/pcb2gcode

Inkscape gcodetools.

https://github.com/cnc-club/gcodetools#gcodetools

An Intro to G-code and How to Generate It Using Inkscape

Openscam (now called camotics?) is a path simulator.

http://jscut.org/

S1000 sets the spindle speed

M3 turns spindle on

M5 turns off

even 0.2 depth is a little deep

home. reset

turn on the spindle