Monthly Archives: April 2015

Session doesn’t start: lightdm, xrdp, xfce4

What is the correct way to kill a vncsession in linux?

$ cat /etc/xrdp/xrdp.ini

$ cat /etc/xrdp/sesman.ini
[Logging]
LogFile=/var/log/xrdp-sesman.log
$ rm -rf ~/.cache/*
$ ls -la .xsession
$ ls -la .ICEauthority
$ cat ~/.cache/upstart/startxfce4.log

$ ps ax | grep vnc
25697 ?        S     55:38 Xvnc4 :1 [...]
[...]
30481 ?        S     17:57 Xvnc4 :2 [...]
$ vncserver -kill :1
or
$ kill 25697

Python 2.7

EAFP is a Python acronym that stands for easier to ask for forgiveness than permission. This coding style is highly pushed in the Python community because it completely relies on the duck typing concept, thus fitting well with the language philosophy.

The concept behind EAFP is fairly easy: instead of checking if an object has a given attribute or method before actually accessing or using it, just trust the object to provide what you need and manage the error case.

Datatypes

Lists

An Introduction to Python Lists
Python Lists

Dict

Dictionaries
Python Dictionary
Add to a dictionary in Python?
Python add new item to dictionary [duplicate]

Iterators & Generators

Iterators & Generators

Classes and Objects

Object Oriented Programming
Python’s Super is nifty, but you can’t use it
correct way to use super (argument passing)
Python 3 OOP Part 1 – Objects and types
Python 3 OOP Part 2 – Classes and members
Python 3 OOP Part 3 – Delegation: composition and inheritance
Python 3 OOP Part 4 – Polymorphism
Python 3 OOP Part 5 – Metaclasses
Python 3 OOP Part 6 – Abstract Base Classes

Logging

15.7. logging — Logging facility for Python
Logging HOWTO on docs.python.org
Logging Cookbook on docs.python.org
Good logging practice in Python
PyMOTW – logging – Report status, error, and informational messages
Python Guide – Logging

Datamodel

3.4.1. Basic customization (__init__, __str__, …)

Uniform Access Principle / Property / Class Attribute

“public” or “private” attribute in Python ? What is the best way?
Python Class Attributes: An Overly Thorough Guide
What’s the difference between a Python “property” and “attribute”?
Private Variables and Class-local References
Implementing Descriptors

old-style vs. new-style

New-style Classes
What is the difference between old style and new style classes in Python?
old-style and new-style classes in Python 2.7? [duplicate]

args and kwargs

Understanding kwargs in Python
*args and **kwargs? [duplicate]
What does ** (double star) and * (star) do for Python parameters?

Webserver / WSGI

Web Server Gateway Interface (WSGI) Servers

Documentation / docstring

sphinx.ext.napoleon – Support for NumPy and Google style docstrings
Example Google Style Python Docstrings
Example NumPy Style Python Docstrings

PEP 257 – Docstring Conventions
PEP 258 – Docutils Design Specification
numpy – How-to document
How to document a method with parameter(s)?
Sphinx Code Example

How to document fields and properties in Python?
How to document class attributes in Python?

Rewriting Python Docstrings With a Metaclass

PyCharm

File -> Settings -> Build, Execution, Deployment -> Python Debugger -> Collect run-time types information for code insight

Using Docstrings to Specify Types
Creating Documentation Comments
Generating Reference Documentation (DocUtils, Sphinx)
Python Integrated Tools (Docstring format: Plain, reStructuredText, Epytext)
Documenting Source Code in PyCharm (reStructuredText, Epytext)
PY-9795: wish list item: support for google python style type comments (sphinx.ext.napoleon)

Lasersaur Laser Cutter Software: Lasaur

Drawing Interchange Format (DXF)

Wikipedia: Drawing Interchange Format (DXF)

libdxf
LibreDWG
AutoCAD 2008 DXF Reference (PDF)
QCAD – 2D CAD for Windows, Linux and Mac
VisiCut – a userfriendly tool for laser-cutting

DXF File format _ Polyline
AutoCAD DXF File Format Summary
DXF.TXT – Drawing Interchange and File Formats
DXF10.spec – Drawing Interchange and File Formats
Minimum Requirements for Creating a DXF File of a 3D Model
Open Design Specification for .dwg files (PDF)
Structure Of DXF File Format
Chapter 6 — ENTITIES Section – POLYLINE
KLayout – DXF Format
DXF, Revision 12

Are there any libraries for parsing AutoCAD files?

QCAD – What is dxflib?
QCAD – Download dxflib (OpenSource)

Using AutoCAD file formats with open source libraries

  0                # 
SECTION            # Section

  2                #
HEADER             # Header

  9                #
$ACADVER           # Key

  1                #
AC1018             # Value

  9                #
$ACADMAINTVER      # Key

 70                #
     0             # Value

  0                #
ENDSEC             # End Section

[...]

  0                #
SECTION            # Section

  2                #
ENTITIES           # Section Name: "Entities"

  0                #
POLYLINE           # First Entity

  5                #
40                 # Polyline ID

330                #
1F                 # 

100                #
AcDbEntity         #

  8                #
sheet              # Layer Name: "sheet"

[...]

 10                #
121.6670087034155  # Groupcode Start X: 121.6670087034155

 20                #
166.9818181818182  # Groupcode Start Y: 166.9818181818182

 30                #
0.0                # Groupcode Start Z: 0.0

  0
VERTEX             # Add new vertex

  5                #
42                 # Element Reference: 42

FabScan 3D Scanner

FabScan: The 100-Euro 3D Laser Scanner
FabScan CUBE
GitHub: FabScan-Shield
GitHub: FabScan 1.5
Anleitung: FabScan benutzen
Assembly Instructions

Bang good

650nm 5mW Focusable Red Line Laser Module Laser Generator Diode

Tools

VisiCut – a userfriendly tool for laser-cutting
GitHub: VisiCut

FAQ

$ sudo python fabscanpi-server --config=fabscan/config/default.config.json --settings=fabscan/config/default.settings.json  
Traceback (most recent call last):
  File "fabscanpi-server", line 8, in <module>
    import fabscan
  File "/home/pi/FabScanPi-Server/src/fabscan/__init__.py", line 7, in <module>
    from fabscan.server import FSServer
  File "/home/pi/FabScanPi-Server/src/fabscan/server/__init__.py", line 13, in <module>
    from fabscan.FSVersion import __version__
ImportError: No module named FSVersion

$ cp /usr/lib/python2.7/dist-packages/fabscan/FSVersion.py /home/pi/FabScanPi-Server/src/fabscan
$ sudo python fabscanpi-server --config=fabscan/config/default.config.json --settings=fabscan/config/default.settings.json 
2016-09-08 17:15:27,031 - fabscan.server - INFO - FabScanPi-Server v.0.2.1
2016-09-08 17:15:28,248 - fabscan.server.websockets - INFO - Websocket Server started on port 8010
2016-09-08 17:15:28,264 - fabscan.scanner.laserscanner.FSSerial - DEBUG - Latest available firmware version is: v.20160620
2016-09-08 17:15:28,526 - fabscan.scanner.laserscanner.FSCamera - INFO - Camera module ready...

avrdude-original: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude-original: Device signature = 0x1e950f

avrdude-original: safemode: Fuses OK (E:00, H:00, L:00)

avrdude-original done.  Thank you.

2016-09-08 17:15:30,425 - fabscan.util.FSUtil - DEBUG - avrdude-original: Using autoreset DTR on GPIO Pin 7
2016-09-08 17:15:30,946 - fabscan.scanner.laserscanner.FSSerial - DEBUG - Trying to connect Arduino on port: /dev/ttyAMA0
2016-09-08 17:15:32,952 - fabscan.scanner.laserscanner.FSSerial - DEBUG - Installed firmware version: v.20160620
2016-09-08 17:15:32,953 - fabscan.scanner.laserscanner.FSSerial - INFO - FabScanPi is connected to Arduino or FabScanPi HAT on port: /dev/ttyAMA0
2016-09-08 17:15:35,063 - fabscan.scanner.laserscanner.FSHardwareController - DEBUG - Hardware controller initialized...
2016-09-08 17:15:35,067 - fabscan.scanner.laserscanner.FSScanProcessor - INFO - Laser Scan Processor initilized...
2016-09-08 17:15:35,073 - fabscan.FSScanner - INFO - Scanner initialized...
2016-09-08 17:15:35,074 - fabscan.FSScanner - INFO - Number of cpu cores: 4
2016-09-08 17:15:49,246 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET / HTTP/1.1" 200 -
2016-09-08 17:15:49,322 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /style/lib.css HTTP/1.1" 200 -
2016-09-08 17:15:49,374 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /style/app.css HTTP/1.1" 200 -
2016-09-08 17:15:49,380 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /js/lib.js HTTP/1.1" 200 -
2016-09-08 17:15:49,388 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /js/locales/en/i18n.js HTTP/1.1" 200 -
2016-09-08 17:15:49,396 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /js/app.js HTTP/1.1" 200 -
2016-09-08 17:15:49,455 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /icons/icon_scan.svg HTTP/1.1" 200 -
2016-09-08 17:15:51,259 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /fonts/fontawesome-webfont.woff2?v=4.3.0 HTTP/1.1" 200 -
2016-09-08 17:15:51,369 - fabscan.server.FSHttpRequestHandler - DEBUG - 192.168.1.199 - "GET /api/v1/filters HTTP/1.1" 200 -
2016-09-08 17:15:51,481 - fabscan.server.websockets.FSWebSocket - DEBUG - New client connected
2016-09-08 17:15:52,108 - fabscan.FSScanner - DEBUG - Upgrade available:True
DEBUG:fabscan.FSScanner:Upgrade available:True
2016-09-08 17:15:53,195 - fabscan.scanner.laserscanner.FSScanProcessor - DEBUG - Checking Hardware connections
DEBUG:fabscan.scanner.laserscanner.FSScanProcessor:Checking Hardware connections
2016-09-08 17:16:22,572 - fabscan.server.FSHttpRequestHandler - DEBUG - 192.168.1.199 - "GET /stream/laser.mjpeg HTTP/1.1" 200 -
DEBUG:fabscan.server.FSHttpRequestHandler:192.168.1.199 - "GET /stream/laser.mjpeg HTTP/1.1" 200 -
2016-09-08 17:16:22,577 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /icons/spinner.gif HTTP/1.1" 200 -
DEBUG:fabscan.server.FSHttpRequestHandler:127.0.0.1 - "GET /icons/spinner.gif HTTP/1.1" 200 -
2016-09-08 17:20:55,570 - fabscan.FSScanner - DEBUG - Close Settings
DEBUG:fabscan.FSScanner:Close Settings
eth0      Link encap:Ethernet  HWaddr b8:27:eb:83:80:63  
          inet addr:192.168.1.200  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: 2001:8e0:9ff:1428:ba27:ebff:fe83:8063/64 Scope:Global
          inet6 addr: fd00:1::ba27:ebff:fe83:8063/64 Scope:Global
          inet6 addr: fe80::ba27:ebff:fe83:8063/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:449155 errors:0 dropped:0 overruns:0 frame:0
          TX packets:110572 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:122088557 (116.4 MiB)  TX bytes:95758002 (91.3 MiB)
$ sudo python fabscanpi-server --config=fabscan/config/default.config.json --settings=fabscan/config/default.settings.json 
[sudo] password for pi: 
2016-09-08 18:39:43,245 - fabscan.server - INFO - FabScanPi-Server v.0.2.1
2016-09-08 18:39:44,329 - fabscan.server.websockets - INFO - Websocket Server started on port 8010
2016-09-08 18:39:44,347 - fabscan.scanner.laserscanner.FSSerial - DEBUG - Latest available firmware version is: v.20160620
2016-09-08 18:39:44,608 - fabscan.scanner.laserscanner.FSCamera - INFO - Camera module ready...

avrdude-original: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude-original: Device signature = 0x1e950f

avrdude-original: safemode: Fuses OK (E:00, H:00, L:00)

avrdude-original done.  Thank you.

2016-09-08 18:39:46,509 - fabscan.util.FSUtil - DEBUG - avrdude-original: Using autoreset DTR on GPIO Pin 7
2016-09-08 18:39:47,029 - fabscan.scanner.laserscanner.FSSerial - DEBUG - Trying to connect Arduino on port: /dev/ttyAMA0
2016-09-08 18:39:48,544 - fabscan.scanner.laserscanner.FSCamera - DEBUG - PI Camera Moule ready.
2016-09-08 18:39:49,036 - fabscan.scanner.laserscanner.FSSerial - DEBUG - Installed firmware version: v.20160620
2016-09-08 18:39:49,037 - fabscan.scanner.laserscanner.FSSerial - INFO - FabScanPi is connected to Arduino or FabScanPi HAT on port: /dev/ttyAMA0
2016-09-08 18:39:51,147 - fabscan.scanner.laserscanner.FSHardwareController - DEBUG - Hardware controller initialized...
2016-09-08 18:39:51,152 - fabscan.scanner.laserscanner.FSScanProcessor - INFO - Laser Scan Processor initilized...
2016-09-08 18:39:51,158 - fabscan.FSScanner - INFO - Scanner initialized...
2016-09-08 18:39:51,159 - fabscan.FSScanner - INFO - Number of cpu cores: 4
2016-09-08 18:40:14,505 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET / HTTP/1.1" 200 -
2016-09-08 18:40:14,536 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /js/locales/en/i18n.js HTTP/1.1" 200 -
2016-09-08 18:40:14,549 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /js/app.js HTTP/1.1" 200 -
2016-09-08 18:40:14,558 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /style/lib.css HTTP/1.1" 200 -
2016-09-08 18:40:14,568 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /style/app.css HTTP/1.1" 200 -
2016-09-08 18:40:14,571 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /js/lib.js HTTP/1.1" 200 -
2016-09-08 18:40:14,579 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /icons/icon_scan.svg HTTP/1.1" 200 -
2016-09-08 18:40:15,362 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /fonts/fontawesome-webfont.woff2?v=4.3.0 HTTP/1.1" 200 -
2016-09-08 18:40:15,441 - fabscan.server.FSHttpRequestHandler - DEBUG - 192.168.1.199 - "GET /api/v1/filters HTTP/1.1" 200 -
2016-09-08 18:40:15,542 - fabscan.server.websockets.FSWebSocket - DEBUG - New client connected
2016-09-08 18:40:16,115 - fabscan.FSScanner - DEBUG - Upgrade available:True
DEBUG:fabscan.FSScanner:Upgrade available:True
2016-09-08 18:40:17,219 - fabscan.scanner.laserscanner.FSScanProcessor - DEBUG - Checking Hardware connections
DEBUG:fabscan.scanner.laserscanner.FSScanProcessor:Checking Hardware connections
2016-09-08 18:40:17,356 - fabscan.server.FSHttpRequestHandler - DEBUG - 192.168.1.199 - "GET /stream/laser.mjpeg HTTP/1.1" 200 -
DEBUG:fabscan.server.FSHttpRequestHandler:192.168.1.199 - "GET /stream/laser.mjpeg HTTP/1.1" 200 -
2016-09-08 18:40:17,362 - fabscan.server.FSHttpRequestHandler - DEBUG - 127.0.0.1 - "GET /icons/spinner.gif HTTP/1.1" 200 -
DEBUG:fabscan.server.FSHttpRequestHandler:127.0.0.1 - "GET /icons/spinner.gif HTTP/1.1" 200 -
2016-09-08 18:40:23,177 - fabscan.FSScanner - INFO - Start command received...
INFO:fabscan.FSScanner:Start command received...
2016-09-08 18:40:23,202 - fabscan.scanner.laserscanner.FSScanProcessor - INFO - Scan started
INFO:fabscan.scanner.laserscanner.FSScanProcessor:Scan started
2016-09-08 18:40:23,288 - fabscan.vision.FSImageWorker - INFO - Creating 4 image worker processes.
INFO:fabscan.vision.FSImageWorker:Creating 4 image worker processes.
2016-09-08 18:40:23,721 - fabscan.server.FSHttpRequestHandler - ERROR - [Errno 32] Broken pipe
ERROR:fabscan.server.FSHttpRequestHandler:[Errno 32] Broken pipe
2016-09-08 18:40:28,859 - fabscan.server.FSHttpRequestHandler - DEBUG - 192.168.1.199 - "GET //stream/texture.mjpeg HTTP/1.1" 200 -
DEBUG:fabscan.server.FSHttpRequestHandler:192.168.1.199 - "GET //stream/texture.mjpeg HTTP/1.1" 200 -
2016-09-08 18:42:40,316 - fabscan.scanner.laserscanner.FSScanProcessor - INFO - Finishing texture scan.
INFO:fabscan.scanner.laserscanner.FSScanProcessor:Finishing texture scan.
2016-09-08 18:42:40,354 - fabscan.scanner.laserscanner.FSScanProcessor - INFO - Started object scan initialisation
INFO:fabscan.scanner.laserscanner.FSScanProcessor:Started object scan initialisation
2016-09-08 18:42:40,462 - fabscan.vision.FSImageWorker - DEBUG - Killed Worker Process with PID 814
DEBUG:fabscan.vision.FSImageWorker:Killed Worker Process with PID 814
2016-09-08 18:42:40,468 - fabscan.vision.FSImageWorker - DEBUG - Killed Worker Process with PID 815
DEBUG:fabscan.vision.FSImageWorker:Killed Worker Process with PID 815
2016-09-08 18:42:40,479 - fabscan.vision.FSImageWorker - DEBUG - Killed Worker Process with PID 812
DEBUG:fabscan.vision.FSImageWorker:Killed Worker Process with PID 812
2016-09-08 18:42:40,636 - fabscan.vision.FSImageWorker - DEBUG - Killed Worker Process with PID 813
DEBUG:fabscan.vision.FSImageWorker:Killed Worker Process with PID 813
2016-09-08 18:42:46,545 - fabscan.scanner.laserscanner.FSImageProcessor - DEBUG - 259.2
DEBUG:fabscan.scanner.laserscanner.FSImageProcessor:259.2
2016-09-08 18:42:46,549 - fabscan.scanner.laserscanner.FSImageProcessor - DEBUG - Laser on backwall detected at x-pixel position: 317
DEBUG:fabscan.scanner.laserscanner.FSImageProcessor:Laser on backwall detected at x-pixel position: 317
2016-09-08 18:42:46,553 - fabscan.scanner.laserscanner.FSImageProcessor - DEBUG - Found a point for laser angle calculation
DEBUG:fabscan.scanner.laserscanner.FSImageProcessor:Found a point for laser angle calculation
2016-09-08 18:42:46,555 - fabscan.scanner.laserscanner.FSScanProcessor - DEBUG - Detected Laser Angle at: 33.012678 deg
DEBUG:fabscan.scanner.laserscanner.FSScanProcessor:Detected Laser Angle at: 33.012678 deg
2016-09-08 18:42:46,556 - fabscan.vision.FSImageWorker - INFO - Creating 4 image worker processes.
INFO:fabscan.vision.FSImageWorker:Creating 4 image worker processes.
Process FSImageWorkerProcess-8:
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/home/pi/FabScanPi-Server/src/fabscan/vision/FSImageWorker.py", line 135, in run
    self.image.save_image(image_task.image, image_task.progress, image_task.prefix, dir_name=image_task.prefix+'/laser_'+image_task.raw_dir)
  File "/home/pi/FabScanPi-Server/src/fabscan/file/FSImage.py", line 34, in save_image
Process FSImageWorkerProcess-5:
Traceback (most recent call last):
    os.makedirs(dir_name)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
    mkdir(name, mode)
OSError: [Errno 17] File exists: '/usr/local/fabscanpi/scans/20160908-184023/laser_raw'
  File "/home/pi/FabScanPi-Server/src/fabscan/vision/FSImageWorker.py", line 135, in run
    self.image.save_image(image_task.image, image_task.progress, image_task.prefix, dir_name=image_task.prefix+'/laser_'+image_task.raw_dir)
  File "/home/pi/FabScanPi-Server/src/fabscan/file/FSImage.py", line 34, in save_image
    os.makedirs(dir_name)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 17] File exists: '/usr/local/fabscanpi/scans/20160908-184023/laser_raw'
2016-09-08 18:42:50,665 - fabscan.server.FSHttpRequestHandler - ERROR - [Errno 32] Broken pipe
ERROR:fabscan.server.FSHttpRequestHandler:[Errno 32] Broken pipe


Process FSImageWorkerProcess-6:
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/home/pi/FabScanPi-Server/src/fabscan/vision/FSImageWorker.py", line 138, in run
    points = self.image_processor.process_image(angle, image_task.image, color_image)
  File "/home/pi/FabScanPi-Server/src/fabscan/scanner/laserscanner/FSImageProcessor.py", line 87, in process_image
    points = self.process_line(pixels, angle , color_image)
  File "/home/pi/FabScanPi-Server/src/fabscan/scanner/laserscanner/FSImageProcessor.py", line 272, in process_line
    line1 = self.computeLineFromPoints(camera_position, point)
  File "/home/pi/FabScanPi-Server/src/fabscan/scanner/laserscanner/FSImageProcessor.py", line 326, in computeLineFromPoints
    line.a = (p2.z-p1.z)/(p2.x-p1.x)
ZeroDivisionError: float division by zero
2016-09-08 18:48:08,641 - fabscan.scanner.laserscanner.FSScanProcessor - INFO - Finishing object scan.
INFO:fabscan.scanner.laserscanner.FSScanProcessor:Finishing object scan.
2016-09-08 18:48:17,749 - fabscan.vision.FSImageWorker - DEBUG - Killed Worker Process with PID 828
DEBUG:fabscan.vision.FSImageWorker:Killed Worker Process with PID 828
2016-09-08 18:49:40,068 - fabscan.server.websockets.FSWebSocket - DEBUG - Client disconnected
DEBUG:fabscan.server.websockets.FSWebSocket:Client disconnected