News Tutorials

Friday Facts 21: Python to Makelangelo

Makelangelo a great way to tinker with algorithmic art, procedural art, generative code, and more. Python is a popular language for building generative art. To send G-code to a Makelangelo plotter over a serial connection using Python, you can use the pyserial library. Here is an example script that demonstrates how to establish the connection and send G-code commands.

First make sure you have pyserial installed.

pip install pyserial

Then, open a serial connection to a USB connected Makelangelo.

import serial
import time

def send_gcode(port, baudrate, commands):
    try:
        # Open the serial port
        with serial.Serial(port, baudrate, timeout=1) as ser:
            time.sleep(2)  # Wait for the connection to establish

            # Send each G-code command
            for command in commands:
                ser.write((command + '\n').encode('utf-8'))
                time.sleep(0.1)  # Short delay between commands
                response = ser.readline().decode('utf-8').strip()
                print(f"Response: {response}")

    except serial.SerialException as e:
        print(f"Serial error: {e}")

# Define the G-code commands to send
gcode_commands = [
    "G28",  # Home all axes
    "G1 X10 Y10 Z0 F3000",  # Move to (10, 10, 0) at 3000 mm/min
    "G1 X20 Y20 Z0 F3000",  # Move to (20, 20, 0) at 3000 mm/min
    # Add more G-code commands as needed
]

# Send G-code commands to Makelangelo plotter
send_gcode('/dev/TTY0', 250000, gcode_commands)

Explanation

  1. Import serial and time: Import necessary modules for serial communication and timing.
  2. Define send_gcode function: This function takes the serial port, baudrate, and a list of G-code commands as arguments. It opens the serial port, sends the G-code commands one by one, and prints the responses from the plotter.
  3. Open the serial port: Using a with statement to ensure the port is properly closed after use.
  4. Send commands: Iterate through the list of G-code commands, send each command, and print the response from the plotter.
  5. Define G-code commands: A list of G-code commands to be sent to the plotter.
  6. Call send_gcode: Pass the serial port, baudrate, and G-code commands to the function.

Ensure that the port (/dev/TTY0) and baudrate (250000) match your Makelangelo plotter’s configuration. Adjust the G-code commands as needed for your specific tasks.

Final thoughts

You might also be interested in related plotter projects like vpype and vsketch.

News Projects

Friday Facts 20: Java Swing Dial UX

Dial is a Java Swing component designed to create a customizable dial interface. This component allows users to interact using the mouse wheel, click-and-drag actions, or keyboard keys. It features an ActionListener to handle turn commands, making it easy to integrate into various Java applications that require a rotary input method. It can be sometimes be more intuitive than a JSlider, which cannot “roll over” back to the starting value.

Key Features

  • Mouse Wheel Interaction: Turn the dial smoothly with the mouse wheel.
  • Mouse Click+Drag: Click and drag to adjust the dial.
  • Keyboard Control: Use the +/- keys to increment or decrement the dial value.
  • Rollover: Unlike JSlider, the dial can wrap around back to the start. Great for controlling an angle value.

Basic Usage

import com.marginallyclever.dial.Dial;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DialDemo {
    public static void main(String[] args) {
        JFrame frame = new JFrame("Dial Demo");
        Dial dial = new Dial();
        
        dial.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("Dial turned: " + dial.getValue());
            }
        });

        frame.add(dial);
        frame.setSize(200, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

Final Thoughts

You can customize the appearance and behavior of the dial through its properties. Adjust the color, range, and initial value as needed to fit your application.

For detailed documentation, visit the GitHub repository.

News

Robot Overlord 2.7.0: Vehicles

Today I’m delighted to announce that Robot Overlord 2.7.0 is out and it adds vehicles. Build your own or use presets like front-wheel drive, rear-wheel drive, motorcycle, mecanum, omni, or tank.

Here are the basic driving controls:

Image

This is what it looks like in the scene graph:

all vehicles start with a CarComponent:

Some wheels can be steered by adding a ServoComponent in the suspension:

I’m especially pleased by the graph tool I made for the PID controller and Torque Curve.

A PID controller (Proportional, Integral, Derivative controller) is a type of control system used to regulate different types of processes. It’s like an auto-pilot mode for controlling systems. Imagine you’re driving a car. You want to keep your car at a constant speed, say, 60 km/hour.

  • The “Proportional” part is like your foot on the gas pedal. If you’re going below 60, you press the pedal down more. If you’re going above 60, you let up on the pedal. The more you are below the target, the harder you press, and vice versa.
  • The “Integral” part is like your memory of what you’ve done so far. If you’ve been below 60 for a while, even if you’re close now, you might press a bit harder on the gas pedal because you remember you’ve been going too slow. It helps to correct sustained, systematic errors (like if your car was carrying heavy weight in the back).
  • The “Derivative” part is like your anticipation of what’s coming. If you’re below 60 but rapidly accelerating, you might ease up on the gas a little, because you’re anticipating hitting the target soon. It helps to mitigate sudden changes (like if you’re about to go downhill).

The torque curve is the relationship between motor speed and motor power. The example graph below is for a NEMA 17 stepper motor used in the Makelangelo art robot.

There’s also a WheelComponent that holds the size and shape of the tires

And of course vehicles need at least one motor

Why cars?

The goal of Robot Overlord is to simulate any kind of robot including robot cars. I would like to see Robot Overlord become the sim/control app used everywhere: All the goodness of free open source, no funky linux like ROS. Tell your teachers, your friends, your preacher, your boss, your employees, your lover, your best friend…everybody.

Plus! The previous way of making robot arms had bones and was missing motors. Now that vehicles have been used to test motors all the arms can be upgraded to use the new system. In app I made one motor with one output and then copy/pasted to LEGO together a 6 axis robot arm. Stepping the motors makes the arm move.

That’s incredibly powerful modular design at work. Love it!

Final thoughts

This is the first version that can be downloaded in all three flavors: Windows, OSX, and Linux. Choose your favorite from the Robot Overlord store page. Huzzah!

2.8.0 will likely be an interim version that converts the existing robot arms to the new motor-driven system.

Full instructions for building custom vehicles are in the Robot Overlord wiki.

As always, you can find me on Discord where I often live code and talk robots.

News

Daisy Driver 2.2

Today I’m delighted to bring you an update to my earlier post about the Daisy Driver motor controller. The latest version meets all my requirements and now I can focus on the next parts of the Sixi 3 robot arm project. I’m making it availble to you right here, right now. Join me in building a world with more interesting robots and read on for all the details.

Read more: Daisy Driver 2.2

What’s in the board?

The Daisy Driver can do so much!

  • The STM32F405 brain is huge and crazy fast. 168 MHz CPU/210 DMIPS, up to 1 Mbyte of Flash.
  • The TMC2130 motor driver can handle up to 1.5amps and includes current change sensing, which could be used for collaborative robots that sense collisions.
  • The IPS2200 rotation sensor is absolute – no need to “home” – touch off a limit switch – when the robot turns on. It always knows where it is.
  • The rotation sensor is also hollow-shaft. A wire can go through the sensor, through the center of the gearbox, and out to the next Sixi 3 actuator.
  • The board can be connected to its neighbors in a linked-list of actuators. They talk to each other through the CANbus network using the CANOpen protocol. This makes electrical work a breeze.
  • Since every CAN device needs a unique address, 6 dip switches make it easy to setup. No pads to solder!
  • It also has a USB connection so you can use a normal Serial interface from your favorite app to talk to the device.
  • The JTAG programming pins make it simple to upload new code from Arduino. Check out our daisy driver Arduino firmware.
  • The RGB LED is a handy status indicator. Have it display CANbus traffic, sensor angle, or morse code!

So why is this important?

Sixi 2 with inside wiring
Sixi 3 with outside wiring

The Sixi 2 robot was my fourth robot arm. It was big, strong, and gorgeous. But it was also 1300 parts in 250 types and it had long cables that ran from the wrist, through the elbow, and into the base. If I’m going to make robots easy for everyone then this is not workable. So I went back to the drawing board again and decided to build a modular robot arm out of identical pieces. The Sixi 3 actuator has less than 50 parts in about 20 types. Even with six actuators in a chain to make a Sixi 3 robot arm that’s less than 300 parts total and none of them are one-offs. production and maintenance at scale! The factory must grow.

Why Daisy Chain?

There are three main ways to wire the joints in a robot arm: all-outside, all-inside, and daisy chain.

All outside wires are easy for maintenance but hard to manage while the robot is running. I’ve had robots try to strangle themselves on their own cabling by accident.

All inside wires are tidy and elegant, but doing any service work means dismantling the entire arm.

Daisy chain is the best of both worlds: no outside wiring and easy maintenance. I’ve tested replacing the elbow of a Sixi 3. It takes about 10 minutes.

So now what?

Next up is to share the goodness with you. The board is available now. More are on the way and I can now refocus my energy on the next step in the bigger picture: using one arm to assemble another arm. As that happens I’m going to need more actuators, more boards, and more gearboxes, plus the Robot Overlord software to run everything.

I’m very interested in talking to anyone that would like to help make an awesome harmonic gearbox, anyone into creating data sheets for electronics, anyone who sees the potential.