Matrix manipulation modules (umatrix, ulinalg)

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
User avatar
workless
Posts: 13
Joined: Sat Mar 24, 2018 7:03 pm
Location: Vancouver, BC

Re: Matrix manipulation modules (umatrix, ulinalg)

Post by workless » Wed Mar 28, 2018 4:54 am

OutoftheBOTS_ wrote:
Tue Mar 27, 2018 8:10 am
I am going to be porting all my robots across from RPi to ESP32 running Micropython.
Hi @OutoftheBOTS_. That's good to hear. I am also interested in Robot control in real time. Can you give us an idea what math functions you use for control of your robots and if you need any specific array calculations? It will be interesting to hear whether your existing code (presumably Python) executes fast enough when you port it to the ESP32.

User avatar
workless
Posts: 13
Joined: Sat Mar 24, 2018 7:03 pm
Location: Vancouver, BC

Re: Matrix manipulation modules (umatrix, ulinalg)

Post by workless » Wed Mar 28, 2018 5:08 am

I just discovered that even existing built-ins such as `sum` are slower on MicroPython `arrays` than on lists. So while they are a more efficient way of storing data they have no speed advantage it appears.

Code: Select all

>>> from array import array
>>> data = [float(pyb.rng())/2**30 for i in range(100)]
>>> x = array('f', data)
>>> import utime
>>> def timed_function(f, *args, **kwargs):
...     myname = str(f)
...     def new_func(*args, **kwargs):
...         t = utime.ticks_us()
...         result = f(*args, **kwargs)
...         delta = utime.ticks_diff(utime.ticks_us(), t)
...         print('Function {} Time = {:6.3f}ms'.format(myname, delta/1000))
...         return result
...     return new_func
...     
...     
... 
>>> 
>>> timed_sum = timed_function(sum)
>>> timed_sum(data)
Function <function> Time =  0.440ms
50.97438
>>> timed_sum(x)
Function <function> Time =  0.568ms
50.97438

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Matrix manipulation modules (umatrix, ulinalg)

Post by pythoncoder » Wed Mar 28, 2018 6:21 am

Arrays have one major advantage. The data is stored in contiguous locations. This means that they support the Python buffer protocol reference. So they provide an ideal interface to foreign functions such as those defined using the inline assembler. They also enable the memoryview class to be used to avoid unnecessary copying of data.

You measurements are interesting (and rather surprising).
Peter Hinch
Index to my micropython libraries.

User avatar
workless
Posts: 13
Joined: Sat Mar 24, 2018 7:03 pm
Location: Vancouver, BC

Re: Matrix manipulation modules (umatrix, ulinalg)

Post by workless » Wed Mar 28, 2018 7:41 am

I found out the reason for the poor performance of arrays compared to lists. It's explained [here](https://stackoverflow.com/questions/367 ... rrays-slow). But I agree on the benefits of arrays. They are also a good way of storing data when memory is tight.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: Matrix manipulation modules (umatrix, ulinalg)

Post by OutoftheBOTS_ » Wed Mar 28, 2018 10:30 am

Hi @OutoftheBOTS_. That's good to hear. I am also interested in Robot control in real time. Can you give us an idea what math functions you use for control of your robots and if you need any specific array calculations? It will be interesting to hear whether your existing code (presumably Python) executes fast enough when you port it to the ESP32.
Ok ? I do lots of stuff but this 1 of my current projects that I am working on atm https://www.youtube.com/watch?v=3KQkf40RmP0

This explains the maths for the first 2 dimensions of the firts 2 joints of the leg but of course then there is another layer on top of this that takes it to 3D movement over 3 joints. https://www.youtube.com/watch?v=FEFv9V2uZRc

Now to get smooth coordinated movement with speed control I can't just move the foot from 1 position to the other rather I have to do it in lots of small steps then of course that is only 1 leg and the robot has 4 legs so there can be very maths heavy.

I have wrote a light fast Micro-Python driver for the PCA9685 chip that controls the servos see https://github.com/OutOfTheBots/ESP32_PCA9685

I have now also built my own PCB for the robot with all needed components on the 1 PCB (10amp buck converter, PCA9685, user 1.8" SPI screen) here is the first prototype still needs a few mods to do everything that I want :) see https://youtu.be/vYVp3kqOh9c

Post Reply