Ricardo's Place Robotics, machine learning, or simply random thoughts!

Finally! A proper Python library for MKS servo controllers with CAN

If you’ve ever tried to control MKS SERVO42D or SERVO57D stepper motor controllers from Python, you know the pain. These controllers transform regular stepper motors into servo-like systems with closed-loop feedback, position control, and CAN communication. They’re affordable and capable, but the lack of a proper Python library meant you were stuck writing raw CAN commands or wrestling with incomplete code snippets scattered across forums.

Not anymore.

I just released mks-servo-can — a complete Python library that finally gives these motor controllers the control interface they deserve.

Read more...

🚫 Say no to vibe-coding — be the Manager of AIs instead 🤖

I’m convinced that AI tools will soon dominate most engineering workflows, not by replacing engineers, but by becoming the tool we all need to master.

Like any tool, you don’t get good at it just by reading about it. You practice! So I set myself a new challenge:

How far could I go in a single day(ish), using only an LLM, to build something I actually needed?

Read more...

New Barcode Generator and Scanner

This webside already has an Advanced QR code Generator, but as the name says, it only generates QR codes. The nice thing about QR codes is that anyone can read them directly from the smartphone camera app (at least modern ones). However, there are other codes that you need to install an app only for reading them. I’m not a big fan of installing “yet-another-phone-app”, so I decided to fix this problem creating “yet-another-web-app” called Barcode Tool - Generator & Scanner!

Read more...

Running Ignition Gazebo Ionic on Google Colab

Last week, I saw this post on LinkedIn where Carlos Argueta was showing some interesting robotics perception experiments that were running on Google Colab.

I mentioned in the comments that I had, in the past, managed to run Gazebo on Google Colab. So, I decided to find that old notebook and here it’s:

https://colab.research.google.com/gist/ricardodeazambuja/fae4db3dcee352fee3f95966ca4f3ec6/example-virtual-screen-opengl-gazebo-ignition.ipynb

The magic is only possible thanks to open source software like X virtual framebuffer, VirtualGL, PyVirtualDisplay, among others!

Ignition Gazebo Ionic Running on Google Colab
Ignition Gazebo Ionic Running on Google Colab

Advanced QR Code Generator

I was testing some ideas at home and I needed to create a QR code. I searched online and found a few websites, but they were full of ads and I was not sure what they were doing with my data. So, I went to my “friend” Gemini and asked it for a single webpage QR code generator. After a few iterations, I got something quite interesting!

Read more...

Launching your file manager from the command line avoiding the rubbish!

After spending years using weird magic spells to launch a graphical file manager (e.g. nautilus) from the command line without it printing a lot of rubbish, I finally learned that xdg-open just works!

Use xdg-open . and you will have your graphical file manager PLUS a clean terminal!

Annotating papers and sharing your thoughts, directly from your browser

In the last weeks I’ve been reading a lot of papers. Usually I open an online document (e.g. google docs) and write down my notes there while I read a paper. However, I also like to highlight a pdf as I read it, but that forces me to download the pdf and keep the final file. Therefore I was trying to find a way to annotate a pdf directly from my web browser… and that’s the motivation that made me hack together my very own arxiv-highlighter!

Read more...

Loss function for semantic segmentation using PyTorch (CrossEntropyLoss and BCELoss)

Today I was trying to implement, using PyTorch, the Focal Loss (paperswithcode, original paper) for my semantic segmentation model. Focal Loss is “just” Cross Entropy Loss with some extra sauce that allows you to adjust (γ) how much weight you give to examples that are harder to classify otherwise your optimiser will focus on the easy examples because they have more impact on the loss. To save time, I didn’t even considered writing my own code (although the focal loss is fairly simple), and I went directly to google where I found this nice example:

Read more...

Old digital microscope was driving Ubuntu nuts!

Today I needed to check some connections in the PCB of my ST-Link V2 clone because I wanted to add the trace support following the nice explanations from here. However, my old brandless digital microscope (you know, they all look the same and come in a blue box…) refused to work. dmesg helped me find some repeated error messages (Failed to query (GET_DEF) UVC control 4 on unit 1 or Failed to query (GET_MIN) UVC control 4 on unit 1) and a little bit of google-fu did the rest. I found my system was suffering from a problem with libwebcam0 and uvcdynctrl and the log file /var/log/uvcdynctrl-udev.log was already at 68GB (?!?).

I learned this is a super old bug (first message is from 2011!) and it can slow down your system to a halt. Using apt show and the very useful apt-rdepends I noticed libwebcam0 and uvcdynctrl just depended on each other… so following the suggestion and removing libwebcam0, uvcdynctrl and uvcdynctrl-data solved my problem (sudo apt remove libwebcam0 uvcdynctrl uvcdynctrl-data).

I hope this blog post can help other people avoid spending time on google to solve the same 11-year-old problem…

UPDATE (29/01/2023):
Ubuntu Cheese sometimes is too picky and stops the stream with an error message, so I suggest using ffplay. First, connect your microscope (webcam) and check the devices available (v4l2-ctl --list-devices):

USB2.0 UVC PC Camera: USB2.0 UV (usb-0000:00:14.0-2):
	/dev/video2
	/dev/video3

Integrated_Webcam_HD: Integrate (usb-0000:00:14.0-5):
	/dev/video0
	/dev/video1

In my situation, the microscope was the USB2.0 UVC PC Camera. You can get extra info with ffmpeg -f v4l2 -list_formats all -i /dev/video2. Finally, just use ffplay /dev/video2.

Affiliated links

If you want to support my work, you can buy an equivalent USB microscope on Amazon (or anything else, really) using the affiliated link below:

You lose nothing and I (may) get a few peanuts from Amazon.

Finally I found how to fully shut up apt-get!

I am always using Google Colab, but in many cases I also need to install something using apt-get. The problem was that sometimes you need to add a new repository, update, install… then your notebook becomes full of text and that eats your memory (locally too as the browser needs to render that after all). So, today I found a nice post explaining the reason why the -qq argument may still leave some bits of text behind. You should go there and read it by yourself, but I will copy some info here in case that website disappears.

To add a new repository:

sudo apt-add-repository ppa:some-repository-here -y > /dev/null

And the ultimate commands:

sudo DEBIAN_FRONTEND=noninteractive apt-get update -qq < /dev/null > /dev/null

and

sudo DEBIAN_FRONTEND=noninteractive apt-get install some_cool_free_software -qq < /dev/null > /dev/null

As I started this post mentioning Google Colab, I think it’s worth pasting here the recipe to shut up pip as well:

pip -q install --upgrade some_cool_python_package > /dev/null