Machinekit running on CHIP with RT PREEMPT kernel


#1

I finally found time to hack a GPIO driver for Machinekit. Machinekit is a general purpose machine control software for Linux. I have described the steps on how to build Machinekit and an RT PREEMPT kernel for the CHIP in this blog post. Does anyone if it is possible to create custom flasher images?

Thanks,
Your Machine Koder


Getting RTlinux, RTAI, or RT preempt on Chip
#2

Respect…
Nothing more to say.

/Marc


#3

WOW!

I bought a BBB a year ago to make MK run on it in order to control my 3D printer.

Awesome to see this running on CHIP. Sadly I have a pocketCHIP and still the BBB around without having anything done with it.
For the BBB I would need a cape to connect the printer, which I don´t have.

Could you suggest a way to connect a printer to the Chip? 4 Steppers, 3 Endstops, 2x Temp
… the usual 3d Printer config…


#4

You are my hero!

Any idea on the latency numbers?


#5

Hi @machinekoder

I have got the implemented CHIP example (square/siggen) running.
Is pwgen implemented as well?
In best case, I have a permission denied.
But probably I don’t understand the syntax.
Can’t find a python based example on Google…
Thanks again.

/Marc


#6

Hi @marc,

You can use a pwmgen. The Python HAL API is not documented very well at the moment. However, the command you are looking for is hal.loadrt('pwmgen', names='pwm-1, pwm-2'). I will create some usage detailed examples in a later blog post.


#7

Thank you @gnomic. I have not done any latency tests yet.


#8

@yello:

For running a 3D printer, the BBB is more suitable because it has an additional microcontroller (PRU) for generating steps, PWM, etc… I can recommend you the CRAMPS board. Here you can find an example Machinekit config: MendelMax-CRAMPS.

If you want to control a 3D printer using the CHIP you have to use the software stepgen component. It should work, but I’m not sure about the performance. Furthermore, you will require a hardware interface to the 3D printers steppers.

So far I have only developed a GPIO driver for the CHIP. However, for the low latency stuff, such as measuring temperature and controlling the PWMs one can quickly build an HAL Python component (see this blog post for an example.


RFC for an idea: The MachineCHIP
#9

Hi Gnomic,

Just started in a new wonderful world. So don’t ask too much. :smirk:

By the way I am running the not recommended:
CONFIG_PREEMPT_RT_FULL: Kernel Features > Preemption Model > Fully Preemptible Kernel (RT).

And my WIFI is “freaking out”:

I am mostly interested in the PWM generator.

/Marc


#10

Hi Machinekoder,

I can’t find a way to get your hint working.

This is what I have at the moment…

from machinekit import hal
from machinekit import rtapi as rt

# we need a thread to execute the component functions
rt.newthread('main-thread', 1000000, fp=True)

# load GPIO driver
rt.loadrt('hal_chip_gpio', output_pins='0,', input_pins='1')

gpio = hal.Component('chip_gpio')

# Is this the way to bind to  pin0 ???
gpio.pin('out-00').link('pulse')

# load pwmgen
rt.loadrt('pwmgen', 'output_type=0')

pwmgen = hal.Component('pwmgen.0')

pwmgen.pin('enable').set(1)

# 25 Hz?????
pwmgen.pin('pwm-freq').set(25)

pwmgen.pin('pwm').link('pulse')

# setup update functions
hal.addf('chip_gpio.read', 'main-thread')
hal.addf('pwmgen.update', 'main-thread')
hal.addf('chip_gpio.write', 'main-thread')

# ready to start the threads
hal.start_threads()

This is a screenshot from halcmd:

By the way I am using a LED on pin0

/Marc


#11

@marc Your configuration looks good. However, in the halcmd output the pwm-freq pin has a wrong value. Can you please try pwmgen.pin('pwm-freq').set(25.0). The frequency is in Hz as can be read in the documentatin for the pwmgen component.


Machine Koder


#12

Hi @machinekoder

No matter what I try for the pwm-freq.
25.0
1.0
100.0
Nothing changes.

The same with using halcmd (halcmd setp pwmgen.0.pwm-freq 10.0)

But, when I use 0.1, 0.01, 0.001 the value of the freq becomes always 0.5
When I played random around with pwm-freq , the problem flips at 0.49 and 0.5

pwm-freq 0.5 gives a value of -5e+08
pwm-freq 0.49 gives a value of 0.5

FYI:
When I use, your example, with siggen there is no problem with “feeding” a new “siggen.0.frequency”.

Thanks for your quick answer.

/Marc


#13

@marc The pwmgen component also has a make-pulses function:

pwmgen.make-pulses (no floating-point)
Generates the actual PWM waveforms, using information computed by update.
Must be called as frequently as possible, to maximize the attainable PWM frequency and resolution, and minimize jitter.
Operates on all channels at once.

Can you please try to add hal.addf('pwmgen.make-pulses', 'main-thread') to your config.


Machine Koder


#14

@machinekoder

Yes! This works.

Sorry, but I forgot a lot…, so I am a noob…
Many moons ago I “played around” with linuxcnc
It’s complex and difficult to learn in 2 days.
I thought “pwmgen.make-pulses.time”, while staring at the “hal output” did this job.
Will continue my fight.

Playing with “setp pwmgen.0.value” activates my LED.

It’s alive :sunglasses:

Step by step. Pulse after pulse…

Thanks!

/Marc


#15

@marc Good to hear that it works now. Btw. the .time pin of each function show the execution time of the function in CPU ticks.


Machine Koder


#16

@marc

Dude, I think you are brilliant. I don’t have my CHIPs yet, so I’m a spectator with ideas. I appreciate the share and the info.


#17

Thanks, but…
Credits where it belongs… -> @Machinekoder

/Marc


#18

Hi @machinekoder,

I know it’s madness to write a loop in python reading a value from a file in RAM and use halcmd
to set values of pwmgen.0 but it’s fun.

Let’s kick the CHIP to it’s limit…

The left top graph is the raw input of the 6 bit LRADC on the chip.
The right top graph, I filtered the signal
The left bottom graph shows the value (controlled by a slider) which writes the value to the file in a tmpfs and becoms the input for pwmgen.0 and controls the brightness of the LED.
Yep I can fade smooth! Not very fast but that’s fine by me.

I am using pin CSID0
ASAP I will try one LED more and a servo.

Do you think it make sence if have a look at the source of halcmd to reduce CPU load?
Or has halcmd, “by nature” a “big delay”?

/Marc


#19

It’s only me again.
Probably talking to myself.

@ me

A cyclus of the Python loop crawling to HAL and use halcmd to change a value is around 0.14 sec.
So, as a HAL noob, the only conclusion I can make:
From user space, disturbing the real time process and change settings is a no-go if you need speed.

Or am I wrong?

/Marc


#20

@marc

You are not alone. I find your Python benchmark interesting (alarming). There should be almost no time involved in the actual Python code, but can you post the code? I’ll look it over and provide any suggestion i can.