Cpac Systems: Automated build environment

I have been responsible for automating a large portion of the software build environment for Cpac Systems marine products. Basically new software is built by an automated build server every time someone commits new code to the software repository, but also on request when a software release needs to be done. I have automated the build and release processes piece by piece and now (with a few exceptions) we can release a new software for a large batch of products in a matter of minutes, compared to before when a software release could take a day. The reason for this is Python scripts that handle the complete build and documentation process of every software, which is done in parallell for a multitude of products. Before this process would be done by individuall software programmers for "their product" on build day.

Cpac Systems: Automatic Hardware-in-the-loop (HIL) tests

I like automating boring tasks, and one of them sometimes is integration testing. At Cpac Systems I have been writing scripts and configuring hardware for automatic testing of Electronic Control Units (ECUs). Basically connecting the essential control units for running a boat to the same system, and writing automatic test cases that perform hardware-in-the-loop (HIL) tests. All of it connected to Jenkins Continous Integration server.

Cpac Systems: Programming for outboard steering and propulsion systems

The project involved solving complex problems and also lots of boat testing around the world (Sweden, Japan and the US). My main tasks were to implement software algorithms, and as a side project I also developed a boat simulator to reduce time spent doing boat testing.

Cpac Systems: Personal involvement in academia connections

Collaboration between industry and academia is something I consider important. From mid 2016 to now I have been the contact person between a vehicle simulation group at Chalmers University of Technology. I also try to attend student fairs where Cpac Systems is exhibiting. All in all, it is a great way of staying in contact with future engineers and technologies.

Master thesis: Remote controlled truck - Proof of concept for designing a remote system for a Volvo truck

A proof of concept for designing a remote system for a Volvo truck. Designing and buildning a remote control to be able to drive a Volvo truck from outside the truck. Investigating wireless technology, safety aspects, designing and building PCB, designing and building mechanics for remote control, systemizing the whole system and writing embedded code. Simulink was used to glue it all together.

The thesis is available from the Chalmers University online library

Tagged with:

Cpac Systems: Programming dongles and interfaces for marine networks

When different systems need to exchange data but their protocols differ, then an interface is a solution. For some months I was doing embedded C programming of dongles and interfaces for marine network communication busses (CAN).

Chalmers Formula Student Management group 2014

With the aim to become better at leading projects I applied and got accepted to the Management group for Chalmers Formula Student. I got project management leadership education from Mats Fredriksson and led a small group of people in the startup of the best project at Chalmers University of technology.

Realtime data plotter

Debugging sensors on a microprocessor can be a hassle and the most used approach is to output the sensor values to a serial monitor. Realtime plotting is a better and more visual way of doing the same thing.


  • Real-time plotter of your data while it is still being processed by your application
  • Plots live data from serial port. Microprocessor choice does not matter as long as it can send serial data to your computer.
  • 6 channels of data (and this can be increased if necessary)
  • Live bar charts
  • Live line graphs
  • You just send the data you want to debug with a space as delimiter like this "value1 value2 value3 value4 value5 value6". Floats or integers does not matter.
  • Open source
  • Robust. It will not crash because of corrupt data stream or similar.
  • Multi platform Java. Tested on OSX and Windows 8 (and should work on Linux as well).

I created this software to debug an Arduino Due on my self-balancing robot. To tune the controls of the robot I needed fast feedback to know if I was making progress or not. The video below demonstrates typical use of the realtime plotter:


You can also follow the project at Github. If you make improvements to the source code, please share it by making a pull request at Github.

How to install and use

Since I have an Arduino I will use it as example but any micro processor can be used.

  1. Get ProcessingIDE to run the code. It is a neat and useful IDE for doing graphical stuff.
  2. Download controlP5 gui library and unzip it into your Processing libraries folder
  3. Connect the Arduino to the usb or serial port of your computer.
  4. Upload the example code (RealtimePlotterArduinoCode) to the Arduino
  5. Check serial monitor (at 115200) and check that it outputs data in the format "value1 value2 value3 value4 value5 value6".
  6. Close the serial monitor (since only one resource can use the serial port at the same time).
  7. Open the Processing sketch and edit the serial port name to correspond to the actual port ("COM3", "COM5", "/dev/tty.usbmodem1411" or whatever you have)
  8. Run the sketch

Advanced use

The realtime plotter can be expanded to also send commands to the microprocessor. The usual approach when programming microprocessors is to set some parameters in the beginning of the code, upload them to the processor, see the result, change the parameters again, upload, and so on until satisfactory performance is achieved. This iterative process takes a lot of time and a better approach is to send updated parameters to the microprocessor from your computer via serial data. For example I needed to tune some parameters on my robot and created a command panel that runs in parallell with the realtime plotter. For each change in parameters I immediately am able to see the result on the plotting screen. Example code of this is located in /RealtimePlotterWithControlPanel.



I decided to send and receive the data as ascii characters instead of binaries. The greatest disadvantage is performance and ease of use is the main advantage.

In some sense the realtime data plotter can also be used as a very slow and limited digital oscilloscope. I would not recommend using it for any high frequency applications though.

Some comments about earlier approaches and the used libraries

I have tried many different ways of doing this. My first approach was Matlab but I had problems with it locking the serial port. It was a hassle to get it working and getting everything configured takes to much time. My second approach was Python and graphing libraries but this was still not very satisfactory. The Processing language together with a graph library and ControlP5 made the whole thing much easier.


Generating an interface for robust manual control using Supervisory Control Theory

This is a project at Chalmers consisting of implementing a control system generated from Supervisory Control Theory.

Problem description

"Operation sequencing and resource safety is a non-trivial task within modern manufacturing systems. Typically, this task is handled manually which is time-consuming and error-prone. Whether a particular system works correctly is determined by how long it has been able to function without severe error. Obviously this situation is not sustainable and can be greatly improved by using software tools and mathematics to guarantee correct functionality. Such "model-based formal methods" is one main part of the research within the Automation group at Chalmers. This project aims at implementing a proof-of- concept of existing methods."

Present at IFAC 2014

Our paper was good enough to be presented by our examiner, Martin Fabian, at IFAC 2014. http://www.ifac2014.org/

Our solution

1. Create a model of the sequence:

Sequence to manufacture a full car

Sequence to manufacture a full car

2. Express it as automatas:

Representation of operations as automata

Representation of operations as automata

3. Extract guards to forbid bad behaviors e.g. deadlocks and forbidden states:

Guard extraction from non-blocking supervisor

Guard extraction from non-blocking supervisor

4. The HMI is implemented in HTML5 and AngularJS that communicates to the OPC server of the PLC:

The HMI with only executable operations being shown

The HMI with only executable operations being shown


Overview of the system and the implementation


Download the article Robust Manual Control of a Manufacturing System using Supervisory Control Theory in collaboration with Martin Fabian.

Download the source code from Bitbucket

Tagged with:

Selfbalancing Lego robot

As a part of the Embedded Control Systems course we( Brian Bonafelia, Nicklas Gustafsson, Per Nyman och jag) got a task of programming a self balancing robot in Lego Mindstorms (NXT). The benefit of using Lego from a control theoretical point of view is that it has quite bad mechanics, and there demonstrates the strengths of control theory; to compensate bad mechanics with sophisticated software. Focus in the course if mainly not on Lego building but more on creating the mathematical model and programming control theory algorithms corresponding to said model. Now the result with a short video:

Video with more talk and more details:

Downlosad the report "Self-balancing two-wheeled robot"