Category Archives: Uncategorized

Replicating the Visual Pushing and Grasping Paper Pt 1: Calibration

Quick note: This post is more a build log of how I got the calibration and grasping parts of the code base working, moreso than replication of the results; as I am not working with the pushing part.

 

I’m working on a summer project [1] building on a project by some Princeton folks called TossingBot. The idea is nice: combine a simple physics model with a network that learns a residual to add (or subtract) onto the single control parameter (thrown velocity), in order to toss arbitrary objects into a desired bin.

Anyway, although the code for the tossing bot paper is not available yet, the same authors released a nice, well commented / documented code repository for their earlier paper, the visual pushing and grasping paper. (I guess, it seemed like they completed part of it during a google internship, so I feel better that I’m being paid far less and cannot spend much time on releasing quality code).

And I actually got it to work! Wow, replicable work. Okay, so I didn’t get it to work in full — but I do have a vastly simplified version of their code working on my ur5, with a d415 camera, and a different gripper — and by using their pre-trained model out of the box! It outputs grasp predictions, and the ur5 moves to different locations where there are actually objects, picks them up, and then drops them.

I had to solve a few issues to get to this point, so I’ll outline here and explain in more detail later (hopefully — again time is short). Perhaps the most broadly applicable is my understanding of their calibration code.

Relevant links:
https://tossingbot.cs.princeton.edu/
http://vpg.cs.princeton.edu/
https://github.com/andyzeng/visual-pushing-grasping

What I did the last 10 days:

SOFTWARE

  1. Installed 18.04.1 on the lab computer
  2. Installed ROS — This is actually not needed for the VPG code, which has removed ROS as a dependency

Re: ROS, I also learned a hard lesson — checkout the right branch for your ROS packages. e.g. Kinetic Karma or Melodic whatever.  Otherwise will get a ton of errors.

GRIPPER

I used a different gripper than the one used in the paper, so I needed to rewrite portions of the code.

1. Attached robotiq gripper to the robot arm, and got it functional.
1a. Required low profile screws of a short length (8mm) that I couldn’t find in the lab at first.

1b. Got it working directly with the teach pendant.
1b. There is a serial to USB converter which for me happened to be inside the ur5 control box. I unplugged that and plugged it into my desktop (presumably, you could control the gripper directly from the ur5 interface when it’s plugged into the ur5 usb ports).
1c. Got it working with ROS. To be hones, this was a majoorrr pain. I kept getting all sorts of weird errors.
ow, instead, I talk to it directly in python, bypassing ROS entirely. Read the robotiq manuals which give a clear command example.

Relevant links:
https://blog.robotiq.com/controlling-the-robotiq-2f-gripper-with-modbus-commands-in-python
(mostly, just something like `ser.write(“\x09\x03\x07\xD0\x00\x03\x04\x0E”)` )

REALSENSE

Due to using a different version of Ubuntu, I had to a bit of experimenting to install the realsense drivers (which are from Intel, and separate from the VPG codebase).

First off, I had a Realsense D435, and opted to buy a D415 as in the paper, since the D415 is better for static scenarios where precision is more important. And it does seem to perform a lot better on the tabletop by default.

 

 

1. Attempted to install realsense-viewer on my ubuntu 19.10 install. Apparently the deb install only works with a much older version of the linux kernel — thus, started patching things and compiling from source. Did things like patch the patches, since the patches were for 18.04.2 and not… 19.10… I did get it working, but my main lesson was to install 18.04.1 on the ur5 desktop.

Relevant links:

  • Debug log http://orangenarwhals.com/hexblog/2019/06/11/realsense/
  • Start here https://github.com/IntelRealSense/librealsense/blob/development/doc/distribution_linux.md
  • Fail, start to compile from source https://github.com/IntelRealSense/librealsense/blob/development/doc/installation.md
  • See patch script files https://raw.githubusercontent.com/leggedrobotics/librealsense/7183d63720277669aaa540fba94b145c03d864cf/scripts/patch-ubuntu-kernel-4.18.sh

I did also switch from the D435 to the D415 out of a desire to change as little as possible from their setup. (Also, on the Intel website I read that the D435 is better for detecting motion and D415 better for static setups).

UR5

1. Plugged it in
1b. Major lesson: Pendant shows coordinates, the ones in VIEW are different the ones which are reported over serial / you send via python. Have to use dropdown to select BASE.
Additionally, there are two ways to specify configurations which can not be directly mixed and matched. joint config = angle of each of the 6 joints. And the other one is the coordinates (which presumably ur5 has a built-in IK solver and path planner to move to), but note that the final tool position is in axis-angle coordinates, not in rotation of each joint!!! This was super confusing to debug.
2. Learned to use ROS ur_modern_driver and get test_move.py working; ignore the other package — eventually, did not use this since codebase did not need ROS

VPG code

The calibration program outputs the pose of the camera, with which we can transform (shear, rotate, etc.) the acquired depth image into a “birds eye” depth image view.

I learned: use python-urx for debugging (due to upgrade of UR5 firmware itself, from universal robots, the serial communication code of VPG is a bit flaky). The calibrate.py parameters specify checkerboard offset from “tool center” which is defined by the UR5 (by default middle of the outward face of last joint). I documented my work in this github issue. Use the teach pendant to set workspace limits. Use foam to offset z height from table for safety purposes.

Calibration — as copied from github issue —

I’m not sure this is correct, but:

  1. Using the pendant, the limits are the X, Y, Z as displayed under the “TCP” box (it is displayed in mm; the code is in meters).
    e.g.
[[0.4, 0.75], [-0.25, 0.15], [-0.2 + 0.4, -0.1 + 0.4]])  [1]
[minx, max x], [miny, max y], [minz, max z]
  1. This is also just experimentally measured. I’m least certain on this part, but I think it is what the tool would need to do to move to the checkerboard center. So if it needs to move +20cm X – 0.01cm Z to the center of the checkerboard. Presumably the tool center = the middle area of the gripper fingers.

EDIT: Wow not sure what I was thinking, but it’s to the “tool center” of the robot (what is reported on the pendant / over TCP from the UR). And as to the sign of the offset — it’s really checkerboard_pos = tool_pos + offset, so define the offset appropriately. Well, that’s my current belief based on inspecting the code, but maybe I will update the belief tomorrow, who knows. end edit

The readme implies this calibration isn’t so important if you’re using the Intel D415 realsense. For what it’s worth the format of the files is (ignore the actual values)

EDIT: Yup, changed my mind. The calibration actual provides the pose of the camera relative to the robot frame. In this way, the image from the camera, which may be looking at the workspace from the side or at an angle, can be morphed/transformed so that the image is from a perfectly “birds eye” camera. end edit

Also, for starting out, a blank file named camera_depth_scale.txt will suffice to kill errors preventing code run.

real/camera_depth_scale.txt
1.012695312500000000e+00
real/camera_pose.txt
9.968040993643140224e-01 -1.695732684590832429e-02 -7.806431039047095899e-02 6.748152280106306522e-01
5.533242197034894325e-03 -9.602075096454146808e-01 2.792327374276499796e-01 -3.416026459607500732e-01
-7.969297786685919371e-02 -2.787722860809356273e-01 -9.570449528584960008e-01 6.668261082482905833e-01
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00
  1. Any 4×4 checkerboard will work. I used some online checkerboard generator and then printed it out. e.g. here is one
    4x4

[1] Note that it’s possible the pendant display somehow differs from the actual TCP values — my z-values were 0.07 on the pendant corresponding to 0.47 in python; to debug, can use examples/simple.py https://github.com/SintefManufacturing/python-urx

And more rambling thoughts:
I mostly fussed around with the calibrate.py script for a long time, an entire 1-2 days wasted on the fact that I didn’t realize the pendant coordinates were off by 40 cm on the z axis, so combined with the joint config vs position specification issue, I was confused why the robot was constantly trying to go through the table. I suspected it was something like the z axis issue, but really it was using this library to get the pose out
https://github.com/SintefManufacturing/python-urx/
(such a great library!) that helped me figure it out.

Additionally, the tool offset I wasn’t certain how it worked, until I opened the code. I thought it was literally to where I wanted on the gripper to be the centerpoint, but no, it’s literally to what the UR5 thinks is the centerpoint of its tool, which is what it reports the coordinates of.

I’m currently still having some z-depth issues, so trying to work through the very detailed! parameters given in the paper to see what is going on with that.

USB extension cable — USB 3.0 is quite strange. I spent a long time figuring out that my extension cable looks like a USB 3 cable (blue ends, extra pins) but was behaving as a USB 2.0 extension cable… ordered some off of amazon that did the trick (also lsusb -t was very helpful).

Home position —

It seems that

Here’s a video of what it’s doing for now (I’ll rehost onto youtube for longevity when I get the chance)
https://photos.app.goo.gl/r6vtjPbjLJECjzPd6
And a more exciting dynamic maneuver

And pictures

 

Yesterday, when it was kinda working

Hey look, I selected BASE. T__T

Calibration in progress. With some limits to the movel command, punctuated by “I guess it’s safe *shrug*:

And a blurry picture of my lab. Had to crop out my robot a bit to avoid faces.

Until next time, folks. Hopefully I’ll have a working demo of something of my own soon. Right now, just running a mutilated version of someone else’s code. But happy to working with actual robots again.

conclusion

Okay, that was all a bit rambly. But if anyone has questions, feel free to ask away.

 

Foot notes:

As to my motivation, I’m working on a small summer research project, which I will detail if I end up getting it working in full.

The idea is heavily based off of the tossing bot paper, as I liked the idea of combining a physics baseline with learning of the error (the residuals).

My requirements were:
1. can be finished in 3 months starting from scratch
2. has cool demo (to, for instance, a 10 year old maker faire attendee) — so probably something dynamic, movement-wise
3. research worthy, since my qualification trials are at the end of the summer.

I think I’ll struggle most with the last point, but I’m hoping that in the process of working toward my goal, I’ll think of something that could be tweaked or improved.

Building KiCad 5.1.0 From Source – on Ubuntu 18.04

I encountered quite a few issues compiling KiCad 5.1.0 from source that took me a few hours to debug (some spent napping while things compiled). The whole thing is in the end < 20 lines of bash commands, though compilation took me 2-3 hours.

Here’s a tried-and-true method to get it to install (I tested on a VM). You should probably go straight to “install kicad” section.

From the beginning: Virtualbox

To make sure these instructions worked for 18.04.2, I tested on a clean install inside VirtualBox. Here I write down instructions, since some steps were confusing to me when I used Virtualbox for the first time.

  1. Install virtualbox
    1. I forget which of these I used… either download and double-click the *.deb, from the links at the very top of the page
    2. Or follow the instructions add the PPA and install https://www.virtualbox.org/wiki/Linux_Downloads
  2. Download ubuntu 18.04.2 ISO from https://www.ubuntu.com/download/desktop
  3. Create new VM
    1. Machine > New…
    2. Go though — I used 2048 GB memory and 40 GB virtual (expandable) hard disk
  4. Install Ubuntu into the VM
    1.  Machine > Settings > Storage > Controller: IDE
      1. Click the “+” sign over the CD rom
      2. Choose Disk > Add > (then select your .iso file)
    2. Now click okay. We’re back to the main window — click the big green “Start” arrow.
    3. The VM starts up, and the standard “Install Ubuntu” screen should pop up once booted. Install Ubuntu as normal
      1. Make sure to click “Also install proprietary media” as otherwise “Virtualbox Guest Additions ISO” will later not run
  5. We probably want to copy-paste in commands. Thus, install Guest Additions. This already comes built-in to virtualbox, no need to download anything else
    1. Devices > Insert Guest Additions Add-on Image…
    2. Click “run” when pop-up prompts
      1. If nothing happens, try running from commandline
        cd ~/VBox_GAs_6.0.6
        ./autorun.sh install 
        # This should pop up a second terminal, which asks "Do you wish to continue" > "Yes" 
      2. If not, it’ll probably complain about gcc not being installed; run sudo apt install build-essential
    3. Restart sudo shutdown -r now
    4. Now enable clipboard
      1. Devices > Clipboard > Bidirectional
      2. Also, View > Auto-Resize Display should now work, but I turn it off because if you accidentally resize the window your VM could freeze alarmingly

Install KiCad

First let’s install dependencies

sudo add-apt-repository ppa:js-reynaud/kicad-dev-nightly 
sudo apt-get update
sudo apt-get build-dep kicad

This last command will spit out an error — E: You must put some 'source' URIs in your sources.list — so go to “Software and Updates” and check the “Source Code” on the first tab.  Then again run build-dep, as well as install the other dependencies.

$ sudo apt-get build-dep kicad
$ sudo apt install libglm-dev $ LibGLM
$ sudo apt install liboce-foundation-dev liboce-modeling-dev liboce-ocaf-dev liboce-visualization-dev # OCE files 
$ sudo apt-get install libboost-all-dev #Boost

Install Ngspice from source

This was a pain to figure out, since it would compile for 10 minutes before failing. Basically, can’t skip independently installing the dependencies, even with the build-dep step above. Fortunately easy to install dependencies.

$ sudo apt-get install  autoconf automake bison flex gcc git libtool make  # otherwise get 'yacc' errors
$ cd ~/kicad/scripting/build_tools

$ sudo ./get_libngspice_so.sh 
*** ngspice shared library has been built successfully! 
***Now, to finish the installation run the script as root with 'install' parameter
$ sudo ./get_libngspice_so.sh install
*** Installation completed successfully! *

Note: Why not apt install?  If you just run sudo apt-get install ngspice, later during cmake it will complain about

In file included from /home/lir/kicad/eeschema/sim/ngspice.cpp:28:0:
/home/lir/kicad/eeschema/sim/ngspice.h:31:10: fatal error: ngspice/sharedspice.h: No such file or directory

Probably, there’s some symlink solution, but I’ve spent way too long on this already.

Then, install KiCad itself.

We follow http://docs.kicad-pcb.org/doxygen/md_Documentation_development_compiling.html

git clone -b master https://git.launchpad.net/kicad
cd <your kicad source mirror>
mkdir -p build/release
cd build/release

However, there are some issues (specific to 16.04+ I think) with  wxWidgets and wxPython you really don’t want to. Thus we change the cmake line to add options to ignore scripting and things that require wxWidgets / wxPython:

$ cmake -j2 -DCMAKE_BUILD_TYPE=Release -DKICAD_SCRIPTING=OFF -DKICAD_SCRIPTING_MODULES=OFF -DKICAD_SCRIPTING_WXPYTHON=OFF ../../ 
$ make 
$ sudo make install

Now you should be able to run kicad from the commandline

$ kicad

Pops up a GUI kicad window!

Appendix

make clean

If something isn’t working that you think should, try clearing old files generated by make:

$ make clean # clear files
$ make # then try again 

Note

Useful: You can see what other flags you can provide to cmake (using the -D flag), by peeking at kicad/build/release/CMakeCache.txt

lir@lir-VM:~/kicad/build/release $ vi CMakeCache.txt
[...]
 KICAD_SCRIPTING_WXPYTHON=OFF
[...]

Errors

These are some of the errors I ran into. If you see this, the solution to them is one of the lines above…

ngspice errors

CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find ngspice (missing: NGSPICE_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
CMakeModules/Findngspice.cmake:57 (find_package_handle_standard_args)
CMakeLists.txt:607 (find_package)

yacc -d -o parse-bison.c parse-bison.y
/bin/bash: yacc: command not found
Makefile:1052: recipe for target 'parse-bison.c' failed
make[3]: *** [parse-bison.c] Error 127
make[3]: Leaving directory '/tmp/libngspice_so/ngspice/src/frontend'
Makefile:773: recipe for target 'install-recursive' failed
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory '/tmp/libngspice_so/ngspice/src/frontend'
Makefile:1359: recipe for target 'install-recursive' failed
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory '/tmp/libngspice_so/ngspice/src'
Makefile:434: recipe for target 'install-recursive' failed
make: *** [install-recursive] Error 1

 

A whole host of wx errors, solved by not using wx ^___^

-- KiCad install dir: </usr/local>
-- Check for installed GLEW -- found
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- regex
-- Check for installed Python Interpreter -- found
-- Python module install path: lib/python2.7/dist-packages
-- Found wxPython 3.0.2.0/gtk3 (wxWidgets 3.0.2.0)
CMake Error at CMakeLists.txt:780 (message):
Cannot find wxPython.h
    *** Could not run GTK+ test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means GTK+ is incorrectly installed.
configure: error:
The development files for GTK+ were not found. For GTK+ 2, please
ensure that pkg-config is in the path and that gtk+-2.0.pc is
installed. For GTK+ 1.2 please check that gtk-config is in the path,
and that the version is 1.2.3 or above. Also check that the
libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
--libs' are in the LD_LIBRARY_PATH or equivalent.

Error running configure
ERROR: failed building wxWidgets
Traceback (most recent call last):
File "build.py", line 1325, in cmd_build_wx
wxbuild.main(wxDir(), build_options)
File "/tmp/pip-build-v_pIAS/wxpython/buildtools/build_wxwidgets.py", line 373, in main
"Error running configure")
File "/tmp/pip-build-v_pIAS/wxpython/buildtools/build_wxwidgets.py", line 85, in exitIfError
raise builder.BuildError(msg)
BuildError
Finished command: build_wx (4.755s)
Finished command: build (4.755s)
Command '"/usr/bin/python" -u build.py build' failed with exit code 1. [ 78%] Building CXX object pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/swig/pcbnew_scripting_helpers.cpp.o
[ 78%] Building CXX object pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/swig/python_scripting.cpp.o
[ 79%] Built target pcbnew_kiface_objects
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

wx_python_helpers.cpp:(.text+0x3a1): undefined reference to `PyErr_Occurred'
wx_python_helpers.cpp:(.text+0x5b3): undefined reference to `PyUnicodeUCS4_AsWideChar'
../../pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/__/common/swig/wx_python_helpers.cpp.o: In function `Py2wxString(_object*)':

wx_python_helpers.cpp:(.text+0x929): undefined reference to `PyErr_Clear'
collect2: error: ld returned 1 exit status
qa/pcbnew/CMakeFiles/qa_pcbnew.dir/build.make:929: recipe for target 'qa/pcbnew/qa_pcbnew' failed
make[2]: *** [qa/pcbnew/qa_pcbnew] Error 1
CMakeFiles/Makefile2:3908: recipe for target 'qa/pcbnew/CMakeFiles/qa_pcbnew.dir/all' failed
make[1]: *** [qa/pcbnew/CMakeFiles/qa_pcbnew.dir/all] Error 2
home/lir/kicad/eeschema/dialogs/dialog_spice_model.cpp: In member function ‘bool DIALOG_SPICE_MODEL::addPwlValue(const wxString&, const wxString&)’:
/home/lir/kicad/eeschema/dialogs/dialog_spice_model.cpp:809:70: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
m_pwlValList->SetItemData( idx, *reinterpret_cast<long*>( &timeF ) );
^
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/widgets/tuner_slider.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/widgets/tuner_slider_base.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/dialogs/dialog_page_settings.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/base_screen.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/base_units.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/eda_text.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/page_info.cpp.o
[ 41%] Built target eeschema_kiface_objects
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2 [ 34%] Built target idfcyl
[ 35%] Built target idfrect
[ 36%] Built target dxf2idf
In file included from /home/lir/kicad/eeschema/sim/ngspice.cpp:28:0:
/home/lir/kicad/eeschema/sim/ngspice.h:31:10: fatal error: ngspice/sharedspice.h: No such file or directory
#include <ngspice/sharedspice.h>
^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
eeschema/CMakeFiles/eeschema_kiface_objects.dir/build.make:4709: recipe for target 'eeschema/CMakeFiles/eeschema_kiface_objects.dir/sim/ngspice.cpp.o' failed
make[2]: *** [eeschema/CMakeFiles/eeschema_kiface_objects.dir/sim/ngspice.cpp.o] Error 1
CMakeFiles/Makefile2:1087: recipe for target 'eeschema/CMakeFiles/eeschema_kiface_objects.dir/all' failed
make[1]: *** [eeschema/CMakeFiles/eeschema_kiface_objects.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 37%] Built target kicad2step_lib
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

Thanks

I figured most of this out from two forum posts:

https://bugs.launchpad.net/kicad/+bug/1804771

https://forum.kicad.info/t/wxpython-3-1-error-building-kicad-from-source-ubuntu-18-04/11431

$ make clean # clear files
$ make # then try again 

Note

Useful: You can see what other flags you can provide to cmake (using the -D flag), by peeking at kicad/build/release/CMakeCache.txt

lir@lir-VM:~/kicad/build/release $ vi CMakeCache.txt
[...]
 KICAD_SCRIPTING_WXPYTHON=OFF
[...]

Errors

These are some of the errors I ran into. If you see this, the solution to them is one of the lines above…

ngspice errors

CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find ngspice (missing: NGSPICE_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
CMakeModules/Findngspice.cmake:57 (find_package_handle_standard_args)
CMakeLists.txt:607 (find_package)

yacc -d -o parse-bison.c parse-bison.y
/bin/bash: yacc: command not found
Makefile:1052: recipe for target 'parse-bison.c' failed
make[3]: *** [parse-bison.c] Error 127
make[3]: Leaving directory '/tmp/libngspice_so/ngspice/src/frontend'
Makefile:773: recipe for target 'install-recursive' failed
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory '/tmp/libngspice_so/ngspice/src/frontend'
Makefile:1359: recipe for target 'install-recursive' failed
make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory '/tmp/libngspice_so/ngspice/src'
Makefile:434: recipe for target 'install-recursive' failed
make: *** [install-recursive] Error 1

 

A whole host of wx errors, solved by not using wx ^___^

-- KiCad install dir: </usr/local>
-- Check for installed GLEW -- found
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- regex
-- Check for installed Python Interpreter -- found
-- Python module install path: lib/python2.7/dist-packages
-- Found wxPython 3.0.2.0/gtk3 (wxWidgets 3.0.2.0)
CMake Error at CMakeLists.txt:780 (message):
Cannot find wxPython.h
    *** Could not run GTK+ test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means GTK+ is incorrectly installed.
configure: error:
The development files for GTK+ were not found. For GTK+ 2, please
ensure that pkg-config is in the path and that gtk+-2.0.pc is
installed. For GTK+ 1.2 please check that gtk-config is in the path,
and that the version is 1.2.3 or above. Also check that the
libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
--libs' are in the LD_LIBRARY_PATH or equivalent.

Error running configure
ERROR: failed building wxWidgets
Traceback (most recent call last):
File "build.py", line 1325, in cmd_build_wx
wxbuild.main(wxDir(), build_options)
File "/tmp/pip-build-v_pIAS/wxpython/buildtools/build_wxwidgets.py", line 373, in main
"Error running configure")
File "/tmp/pip-build-v_pIAS/wxpython/buildtools/build_wxwidgets.py", line 85, in exitIfError
raise builder.BuildError(msg)
BuildError
Finished command: build_wx (4.755s)
Finished command: build (4.755s)
Command '"/usr/bin/python" -u build.py build' failed with exit code 1. [ 78%] Building CXX object pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/swig/pcbnew_scripting_helpers.cpp.o
[ 78%] Building CXX object pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/swig/python_scripting.cpp.o
[ 79%] Built target pcbnew_kiface_objects
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

wx_python_helpers.cpp:(.text+0x3a1): undefined reference to `PyErr_Occurred'
wx_python_helpers.cpp:(.text+0x5b3): undefined reference to `PyUnicodeUCS4_AsWideChar'
../../pcbnew/CMakeFiles/pcbnew_kiface_objects.dir/__/common/swig/wx_python_helpers.cpp.o: In function `Py2wxString(_object*)':

wx_python_helpers.cpp:(.text+0x929): undefined reference to `PyErr_Clear'
collect2: error: ld returned 1 exit status
qa/pcbnew/CMakeFiles/qa_pcbnew.dir/build.make:929: recipe for target 'qa/pcbnew/qa_pcbnew' failed
make[2]: *** [qa/pcbnew/qa_pcbnew] Error 1
CMakeFiles/Makefile2:3908: recipe for target 'qa/pcbnew/CMakeFiles/qa_pcbnew.dir/all' failed
make[1]: *** [qa/pcbnew/CMakeFiles/qa_pcbnew.dir/all] Error 2
home/lir/kicad/eeschema/dialogs/dialog_spice_model.cpp: In member function ‘bool DIALOG_SPICE_MODEL::addPwlValue(const wxString&, const wxString&)’:
/home/lir/kicad/eeschema/dialogs/dialog_spice_model.cpp:809:70: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
m_pwlValList->SetItemData( idx, *reinterpret_cast<long*>( &timeF ) );
^
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/widgets/tuner_slider.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/widgets/tuner_slider_base.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/dialogs/dialog_page_settings.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/base_screen.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/base_units.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/eda_text.cpp.o
[ 41%] Building CXX object eeschema/CMakeFiles/eeschema_kiface_objects.dir/__/common/page_info.cpp.o
[ 41%] Built target eeschema_kiface_objects
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2 [ 34%] Built target idfcyl
[ 35%] Built target idfrect
[ 36%] Built target dxf2idf
In file included from /home/lir/kicad/eeschema/sim/ngspice.cpp:28:0:
/home/lir/kicad/eeschema/sim/ngspice.h:31:10: fatal error: ngspice/sharedspice.h: No such file or directory
#include <ngspice/sharedspice.h>
^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
eeschema/CMakeFiles/eeschema_kiface_objects.dir/build.make:4709: recipe for target 'eeschema/CMakeFiles/eeschema_kiface_objects.dir/sim/ngspice.cpp.o' failed
make[2]: *** [eeschema/CMakeFiles/eeschema_kiface_objects.dir/sim/ngspice.cpp.o] Error 1
CMakeFiles/Makefile2:1087: recipe for target 'eeschema/CMakeFiles/eeschema_kiface_objects.dir/all' failed
make[1]: *** [eeschema/CMakeFiles/eeschema_kiface_objects.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 37%] Built target kicad2step_lib
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

Thanks

I figured most of this out from two forum posts:

https://bugs.launchpad.net/kicad/+bug/1804771

https://forum.kicad.info/t/wxpython-3-1-error-building-kicad-from-source-ubuntu-18-04/11431

Hands-on with Probabilistic Programming Languages

The past week with one of my graduate classes, we read a few papers on probabilistic programming lanugages (PPLs). A few fellow students presented on the papers, and included a little hands-on demo of PPLs. They’re much more approachable than I thought!

At least in the “hello world” cases, they’re pretty much like normal programming languages with the addition of a few primitives to allow for reasoning about probabilities. In the example of CHURCH, this is the flip primitive. CHURCH uses LISP-like syntax. [1]

Without further ado here are some of the examples given.

CHURCH

Here we use the online compiler at http://v1.probmods.org/play-space.html.

[2]

The first line, display(flip), shows one coin flip (50/50) – in this case we get a` #f, or false. If we run the program again, we might get a #t. Near the end, we see that we can also call flip 0.7 which will return true with 70% likelihood. We then run this 100 times and draw a histogram (I had to right-click and view the image in a new window to see it). Here we can see that we actually got about 78%-22% on this run. If we run the program again, we get a different histogram, and with more flips we get closer to the true 70% distribution.

Prolog

To see an example of how we can use PPLs to perform inference, let’s see an example in prolog.

Follow along here.
https://rextester.com/l/prolog_online_compiler

Here we defined some facts (amy is a parent of bob, and bob is a parent of cathy). Then we defined some rules (what does it mean to be a grandparent?). Finally, at the bottom, I typed in some queries to find out of cathy is a parent of amy (no) and if amy is a grandparent of cathy (yes). Then I clicked Run it and got the output at the bottom.

In this way we see prolog has “reasoned” and created a causal chain from our question to the axioms we have.

We can also write our queries directly into the program, and print them all out.

The code for these examples can be found at these links or the bottom of this post.

I’m not sure why prolog doesn’t have this concept of printing query results. I had a lot of issues with the program not stopping (TIMEOUT) and not being sure where I should type in the queries (marked with ?- in online tutorials), versus typing in the program itself.

Other thoughts

I also learned that they’re not just toy languages for computer science people, and there are statistical researcher who use these on a daily basis.

Footnotes

[1] The instructor said something like “Yea I feel like all these probabilistic programming languages and always in some obscure language. For instance CHURCH targets the niche that knows both LISP and the relevant statistical concepts. They’re mostly useful for the authors.”

[2] Note: Like LISP, the strange operator order is Polish notation.

Appendix

CHURCH

1
2
3
4
5
6
7
8
9
10
11
12
13
14
(display(flip))

(display(+ 2 2))
(display(equal? #f #t))

(define x (list 1 2 3))
(define (square x)
(* x x)
(display (square 6))

(define (flip-biased-coin)
(flip 0.7))

(hist (repeat 100 flip-biased-coin))

Prolog 1

This should be input in their entirety into the coding area, and then run.

1
2
3
4
5
6
7
8
9
10
11
% Facts
parent(amy, bob).
parent(bob, cathy).

% Rules
grandparent(X, Z) :- parent(X, Y), parent(Y, Z).
ancestor(X, Y) :- parent(X, Y).
ancestor(X, Z) :- parent(X, Z), ancestor(X, Z).

% Run program with ?- prompt
?- writeln(‘hello world’), nl.

Prolog 2

This should be input in their entirety into the coding area, and then run.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
program :- write(‘Hello, world!’), nl.
parent(amy, bob).
parent(bob, cathy).
grandparent(X, Z) :- parent(X, Y), parent(Y, Z).
ancestor(X, Y) :- parent(X, Y).
ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y).

printqueries :-
forall(query(Q), (Q -> writeln(yes:Q) ; writeln(no:Q))).

query(parent(amy, cathy)).
query(parent(bob, cathy)).
query(grandparent(amy, cathy)).
query(ancestor(amy, cathy)).

:- program.
:- printqueries.