Categories
links

Links interlude

https://www.nature.com/articles/nature14422 and MAP-Elites algorithm: https://www.researchgate.net/publication/277323278_Robots_that_can_adapt_like_animals

https://github.com/benureau/recode/tree/master/cully2015

https://github.com/resibots/ite_v2

http://picbreeder.org/

http://www.cs.uvm.edu/~jbongard/papers/2014_PLOSCompBio_Auerbach.pdf

very cool: http://eplex.cs.ucf.edu/ecal13/demo/PCA.html?uid=192750

https://www.creativemachineslab.com/

http://eplex.cs.ucf.edu/

https://www.shadowrobot.com/products/modular-grasper/

https://www.coroma-project.eu/

Categories
AI/ML dev evolution

ONS variant of HyperNEAT

https://open.uct.ac.za/bitstream/handle/11427/27910/thesis_sci_2018_didi_sabre_z.pdf?sequence=1&isAllowed=y

The TD methods, were further compared to variants of NEAT and HyperNEAT (that is, OS, ONS, NS, OGN and GNS) with and without behavior transfer. The results demonstrated that the ONS variant of HyperNEAT performs much better (with respect to effectiveness and efficiency) than both TD methods and all variants of NEAT. Specific
evolutionary search methods to direct NE such as behavior diversity maintenance and the hybrid approach, work most effectively at balancing exploration versus exploitation in the search space, more so than TD methods.

Evolutionary search approaches investigated were objective-based search (OS), novelty search (NS), genotypic diversity search (GNS), hybrid of objective and novelty search
and hybrid of objective based and genotypic diversity maintenance search (ONS and OGN, respectively). In this thesis, three methodological features were explored to
ascertain an appropriate combination that enables the evolution of high quality solutions based on effectiveness (task performance) and efficiency (speed of adaptation)
of evolved behaviors. These features are as follows: First, direct versus indirect encoding neuro-evolution methods for collective behavior evolution (that is, NEAT and
HyperNEAT, respectively). Second, non-objective evolutionary search versus objective based search approach for guiding collective behavior evolution. Third, neuro-evolution
with collective behavior transfer.

“with behavior transfer” referring more or less to crossover/mutate rather than starting from scratch with new individuals. Something like that.

https://github.com/sdidi/KeepawaySim

Categories
AI/ML CNNs Vision

Self Attention

https://attentionagent.github.io/ there is no conscious perception of the visual world without attention to it

http://papers.nips.cc/paper/8302-stand-alone-self-attention-in-vision-models

and the difference between them and conv nets

https://openreview.net/forum?id=HJlnC1rKPB

https://github.com/epfml/attention-cnn

Categories
AI/ML dev envs neuro simulation

OpenAI Gym MultiNEAT

ok also, just saw this: https://gym.openai.com/evaluations/eval_a0YXWDc4SKeJjyTH7IrHBg/

it doesn’t work apparrently, but could be salvaged into something,

possibly written by this guy https://blog.otoro.net/

https://attentionagent.github.io/ there is no conscious perception of the visual world without attention to it

# Using ES-HyperNEAT to try to solve the Bipedal walker.
# This attempt was not successful. Adjustment of hyperparameters is likely needed.

# A neural network is trained using NeuroEvolution of Augmenting Topologies
# The idea is from the paper: "Evolving Neural Networks through Augmenting Topologies"
# This gist is using MultiNEAT (http://multineat.com/)

import logging
import numpy as np
import pickle

import gym

import MultiNEAT as NEAT

# NEAT setup
params = NEAT.Parameters()
params.PopulationSize = 200;

params.DynamicCompatibility = True;
params.CompatTreshold = 2.0;
params.YoungAgeTreshold = 15;
params.SpeciesMaxStagnation = 100;
params.OldAgeTreshold = 35;
params.MinSpecies = 5;
params.MaxSpecies = 10;
params.RouletteWheelSelection = False;

params.MutateRemLinkProb = 0.02;
params.RecurrentProb = 0;
params.OverallMutationRate = 0.15;
params.MutateAddLinkProb = 0.08;
params.MutateAddNeuronProb = 0.01;
params.MutateWeightsProb = 0.90;
params.MaxWeight = 8.0;
params.WeightMutationMaxPower = 0.2;
params.WeightReplacementMaxPower = 1.0;

params.MutateActivationAProb = 0.0;
params.ActivationAMutationMaxPower = 0.5;
params.MinActivationA = 0.05;
params.MaxActivationA = 6.0;

params.MutateNeuronActivationTypeProb = 0.03;

params.ActivationFunction_SignedSigmoid_Prob = 0.0;
params.ActivationFunction_UnsignedSigmoid_Prob = 0.0;
params.ActivationFunction_Tanh_Prob = 1.0;
params.ActivationFunction_TanhCubic_Prob = 0.0;
params.ActivationFunction_SignedStep_Prob = 1.0;
params.ActivationFunction_UnsignedStep_Prob = 0.0;
params.ActivationFunction_SignedGauss_Prob = 1.0;
params.ActivationFunction_UnsignedGauss_Prob = 0.0;
params.ActivationFunction_Abs_Prob = 0.0;
params.ActivationFunction_SignedSine_Prob = 1.0;
params.ActivationFunction_UnsignedSine_Prob = 0.0;
params.ActivationFunction_Linear_Prob = 1.0;

params.DivisionThreshold = 0.5;
params.VarianceThreshold = 0.03;
params.BandThreshold = 0.3;
params.InitialDepth = 2;
params.MaxDepth = 3;
params.IterationLevel = 1;
params.Leo = False;
params.GeometrySeed = False;
params.LeoSeed = False;
params.LeoThreshold = 0.3;
params.CPPN_Bias = -1.0;
params.Qtree_X = 0.0;
params.Qtree_Y = 0.0;
params.Width = 1.;
params.Height = 1.;
params.Elitism = 0.1;

rng = NEAT.RNG()
rng.TimeSeed()

list = []

for i in range(0,14):
	list.append((-1. +(2.*i/13.), -1., 0.))

for i in range(0,10):
	list.append((-1. +(2.*i/9), -0.5, 0))


substrate = NEAT.Substrate(list,
                           [],
                           [(-1., 1., 0.), (-0.5, 1., 0.), (0.5, 1., 0.), (1., 1., 0.)])

substrate.m_allow_input_hidden_links = False;
substrate.m_allow_input_output_links = False;
substrate.m_allow_hidden_hidden_links = False;
substrate.m_allow_hidden_output_links = False;
substrate.m_allow_output_hidden_links = False;
substrate.m_allow_output_output_links = False;
substrate.m_allow_looped_hidden_links = True;
substrate.m_allow_looped_output_links = False;

substrate.m_allow_input_hidden_links = True;
substrate.m_allow_input_output_links = False;
substrate.m_allow_hidden_output_links = True;
substrate.m_allow_hidden_hidden_links = True;

substrate.m_hidden_nodes_activation = NEAT.ActivationFunction.SIGNED_SIGMOID;
substrate.m_output_nodes_activation = NEAT.ActivationFunction.UNSIGNED_SIGMOID;

substrate.m_with_distance = False;

substrate.m_max_weight_and_bias = 8.0;


def trainNetwork(env, seed):
    # Training parameters
    generationSize = 50
    episode_count = 10
    max_steps = 1000
    # Max reward for environments that reward 1 for each succesfull step (e.g. CartPole-v0)
    max_reward = episode_count * max_steps

    def evaluate(genome):
        net = NEAT.NeuralNetwork()
        genome.BuildESHyperNEATPhenotype(net, substrate, params)

        cum_reward = 0

        for i in xrange(episode_count):
            ob = env.reset()
            net.Flush()

            for j in xrange(max_steps):
                # get next action
                net.Input(ob)
                net.Activate()
                o = net.Output()
                action = np.clip(o,-1,1)
                ob, reward, done, _ = env.step(action)
                cum_reward += reward
                if done:
                    break

        return cum_reward

    # Create initial genome
    g = NEAT.Genome(0, 24, 0, 4, False, 
                    NEAT.ActivationFunction.TANH, NEAT.ActivationFunction.TANH, 0, params)
    pop = NEAT.Population(g, params, True, 1.0, seed)

    current_best = None

    for generation in range(generationSize):
        for i_episode, genome in enumerate(NEAT.GetGenomeList(pop)):
            reward = evaluate(genome)

            if reward == max_reward:
                return pickle.dumps(genome)

            genome.SetFitness(reward)

        print('Generation: {}, max fitness: {}'.format(generation,
                            max((x.GetFitness() for x in NEAT.GetGenomeList(pop)))))
        current_best = pickle.dumps(pop.GetBestGenome())
        pop.Epoch()


    return current_best

env_name = "BipedalWalker"

if __name__ == '__main__':
    # Test the algorithm multiple times
    for test_case in xrange(0, 1):
        # setup logger, environment and monitor
        logger = logging.getLogger()
        logger.setLevel(logging.INFO)
        env = gym.make("%s-v2" % env_name)
        outdir = "/tmp/neat-%s-results-%d" % (env_name, test_case)
        env.monitor.start(outdir, force=True)

        # Train network
        learned = trainNetwork(env, test_case)

        # Test trained network on 1000 episodes
        learned_genome = pickle.loads(learned)
        net = NEAT.NeuralNetwork()
        learned_genome.BuildESHyperNEATPhenotype( net,substrate, params)

        episode_count = 1000
        max_steps = 1000

        for i in xrange(episode_count):
            ob = env.reset()
            net.Flush()

            for j in xrange(max_steps):
                # get next action
                net.Input(ob)
                net.Activate()
                o = net.Output()
                action = np.clip(o,-1,1)
                ob, reward, done, _ = env.step(action)
                if done:
                    break


        # Dump result info to disk
        env.monitor.close()
Categories
AI/ML evolution

HyperNEAT art

https://www.food4rhino.com/app/octopus#lg=1&slide=7

and this bonkers shape searcher software https://youtu.be/SlyXJEO76BI https://www.food4rhino.com/app/octopus

Categories
dev

Installing MultiNEAT

import MultiNEAT as NEAT

need to install MultiNEAT.

Tried to install
using these instructions
https://github.com/peter-ch/MultiNEAT

it said success despite this:

byte-compiling build/bdist.linux-x86_64/egg/MultiNEAT/init.py to init.pyc
File "build/bdist.linux-x86_64/egg/MultiNEAT/init.py", line 45
t = {**traits, 'w':w}
^
SyntaxError: invalid syntax


Installed /usr/local/lib/python2.7/dist-packages/multineat-0.5-py2.7-linux-x86_64.egg
Processing dependencies for multineat==0.5
Finished processing dependencies for multineat==0.5


then tried
pip install .
https://stackoverflow.com/questions/1471994/what-is-setup-py
It gets these errors:

/usr/bin/ld: cannot find -lboost_python36
/usr/bin/ld: cannot find -lboost_numpy36

boost libs missing. Apparently it has a conda install, but I don’t entirely understand whether conda and pip will play nicely together. conda also a big install and the Chromebook is not big on space. Ok Miniconda is smaller.

https://anaconda.org/conda-forge/multineat

To install this package with conda run one of the following:
conda install -c conda-forge multineat
conda install -c conda-forge/label/cf201901 multineat
conda install -c conda-forge/label/cf202003 multineat

apt-get install libboost-all-dev
...already installed

https://stackoverflow.com/questions/36881958/c-program-cannot-find-boost possible solution.

ah…

/usr/local/lib/python2.7/dist-packages

root@chrx:/opt/MultiNEAT# ls -l /usr/local/lib/python2.7/dist-packages
total 7312
-rw-r–r– 1 root staff 39 Apr 8 21:50 easy-install.pth
-rw-r–r– 1 root staff 7482106 Apr 8 21:50 multineat-0.5-py2.7-linux-x86_64.egg

so it’s compiling with python2.

I’m gonna go with conda instead.

conda install MultiNEAT

https://anaconda.org/conda-forge/multineat

https://docs.conda.io/en/latest/miniconda.html#linux-installers

you need to chmod 755 the install file, and don’t forget to add to $PATH.

echo “PATH=$PATH:/opt/miniconda3/bin” >> ~/.bashrc

then close window and open new bash window, to refresh envs. (envs are environment variables, if someone is actually reading this)

conda install -c conda-forge multineat

(base) root@chrx:~# conda install -c conda-forge multineat
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: | 
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed                                                                          

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - multineat -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.5,<3.6.0a0']

Your python: python=3.7

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

ok…

root@chrx:~# conda info

     active environment : base
    active env location : /opt/miniconda3
            shell level : 1
       user config file : /root/.condarc
 populated config files : /root/.condarc
          conda version : 4.8.2
    conda-build version : not installed
         python version : 3.7.6.final.0
       virtual packages : __glibc=2.27
       base environment : /opt/miniconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /opt/miniconda3/pkgs
                          /root/.conda/pkgs
       envs directories : /opt/miniconda3/envs
                          /root/.conda/envs
               platform : linux-64
             user-agent : conda/4.8.2 requests/2.22.0 CPython/3.7.6 Linux/4.16.18-galliumos galliumos/3.1 glibc/2.27
                UID:GID : 0:0
             netrc file : None
           offline mode : False


ok let’s go back to compiling boost from source cause conda don’t like 3.7. Which seems like I should do a –force or something, cause wtf. So here’s the theory of C++ linking (fml):

https://stackoverflow.com/questions/16710047/usr-bin-ld-cannot-find-lnameofthelibrary

here’s more relevant

https://askubuntu.com/questions/944035/installing-libboost-python-dev-for-python3-without-installing-python2-7

https://stackoverflow.com/questions/12578499/how-to-install-boost-on-ubuntu

Here’s some Dockerfile on it:

RUN cd /usr/src && \
 wget --no-verbose https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.gz && \
 tar xzf boost_1_65_1.tar.gz && \
 cd boost_1_65_1 && \
 ln -s /usr/local/include/python3.6m /usr/local/include/python3.6 && \
 ./bootstrap.sh --with-python=$(which python3) && \
 ./b2 install && \
 rm /usr/local/include/python3.6 && \
 ldconfig && \
 cd / && rm -rf /usr/src/*

I’m doing the steps one by one, ./b2 made it compile. it’s taking like a good few mins now.

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    /opt/boost_1_65_1

The following directory should be added to linker library paths:

    /opt/boost_1_65_1/stage/lib

ok let’s try again…

/usr/bin/ld: cannot find -lboost_python36
/usr/bin/ld: cannot find -lboost_numpy36

ldconfig

nope ok where is the library?

# find | grep boost_python

(there's all the boost libs i built under /opt, and also these:)

./usr/lib/x86_64-linux-gnu/libboost_python-py36.so
./usr/lib/x86_64-linux-gnu/libboost_python3-py36.so.1.65.1
./usr/lib/x86_64-linux-gnu/libboost_python-py27.so.1.65.1
./usr/lib/x86_64-linux-gnu/libboost_python3-py36.so
./usr/lib/x86_64-linux-gnu/libboost_python-py27.a
./usr/lib/x86_64-linux-gnu/libboost_python-py36.a
./usr/lib/x86_64-linux-gnu/libboost_python.so
./usr/lib/x86_64-linux-gnu/libboost_python3.a
./usr/lib/x86_64-linux-gnu/libboost_python-py27.so
./usr/lib/x86_64-linux-gnu/libboost_python3.so
./usr/lib/x86_64-linux-gnu/libboost_python3-py36.a
./usr/lib/x86_64-linux-gnu/libboost_python.a

Ok ./usr/lib/x86_64-linux-gnu/ is where the .so is.

https://stackoverflow.com/questions/3808775/cmake-doesnt-find-boost

https://askubuntu.com/questions/449348/why-are-boost-package-libs-installed-to-usr-lib-x86-64-linux-gnu

https://stackoverflow.com/questions/36881958/c-program-cannot-find-boost

the last one had the sauce that worked for someone for something similar

So I’m changing this bit of setup.py

        include_dirs = ['/opt/boost_1_65_1']
        library_dirs = ['/opt/boost_1_65_1/stage/lib']
        extra.extend(['-DUSE_BOOST_PYTHON', '-DUSE_BOOST_RANDOM', #'-O0',
                      #'-DVDEBUG',
                      ])
        exx = Extension('MultiNEAT._MultiNEAT',
                        sources,
                        libraries=libs,
                        library_dirs=library_dirs,
                        include_dirs=include_dirs,
                        extra_compile_args=extra)

nope

https://unix.stackexchange.com/questions/423821/gcc-usr-bin-ld-cannot-find-lglut32-lopengl32-lglu32-lfreegut-but-these

So we need to use LD somehow.

You need:

  1. To actually have the library in your computer
  2. Help gcc/the linker to find the library by providing the path to the library
    • You can add -Ldir-name to the gcc command
    • You can the library location to the LD_LIBRARY_PATH environment variable
  3. Update the “Dynamic Linker“:sudo ldconfig

Let’s see what it’s running…

x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.6/src/PythonBindings.o build/temp.linux-x86_64-3.6/src/Genome.o build/temp.linux-x86_64-3.6/src/Innovation.o build/temp.linux-x86_64-3.6/src/NeuralNetwork.o build/temp.linux-x86_64-3.6/src/Parameters.o build/temp.linux-x86_64-3.6/src/PhenotypeBehavior.o build/temp.linux-x86_64-3.6/src/Population.o build/temp.linux-x86_64-3.6/src/Random.o build/temp.linux-x86_64-3.6/src/Species.o build/temp.linux-x86_64-3.6/src/Substrate.o build/temp.linux-x86_64-3.6/src/Utils.o -L/opt/boost_1_65_1/stage/lib -lboost_system -lboost_serialization -lboost_python36 -lboost_numpy36 -o build/lib.linux-x86_64-3.6/MultiNEAT/_MultiNEAT.cpython-36m-x86_64-linux-gnu.so

ok and indeed there doesn’t seem to be anything under /opt/boost_1_65_1/stage/lib with python in the name. We found it in /usr/lib/x86_64-linux-gnu/ earlier.

nope nope nope

https://stackoverflow.com/questions/24173330/cmake-is-not-able-to-find-boost-libraries

SET (BOOST_ROOT "/opt/boost_1_65_1")
SET (BOOST_INCLUDEDIR "/opt/boost_1_65_1/boost")
SET (BOOST_LIBRARYDIR "/opt/boost_1_65_1/libs")

ok so I think it’s just that the Boost.Python package isn’t here. It’s in usr/lib … hmm more later

Here’s something promising: https://github.com/andrewssobral/bgslibrary/issues/96

#:/usr/lib/x86_64-linux-gnu# find | grep boost_python
./libboost_python-py36.so
./libboost_python3-py36.so.1.65.1
./libboost_python-py27.so.1.65.1
./libboost_python3-py36.so
./libboost_python-py27.a
./libboost_python-py36.a
./libboost_python.so
./libboost_python3.a
./libboost_python-py27.so
./libboost_python3.so
./libboost_python3-py36.a
./libboost_python.a

Hmm the answer doesn’t make sense here. Half of those are already symlinks. Let’s go back and make sure we compiled correctly.

./bootstrap.sh --with-libraries=python --with-python=python3.6

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH

nope. ok what is cmake doing?

It calls Find.Boost,

dies on :

No header defined for python36; skipping header check

No header defined for numpy36; skipping header check

so, ok i worked it out

I changed the CMakeList.txt line to -lboost_python3 -lboost_numpy3

Installed /usr/local/lib/python3.6/dist-packages/multineat-0.5-py3.6-linux-x86_64.egg
Processing dependencies for multineat==0.5
Finished processing dependencies for multineat==0.5

ok but when i try run a python boi in the examples folder,

Boost.Python.ArgumentError: Python argument types in
Genome.init(Genome, int, int, int, int, bool, ActivationFunction, ActivationFunction, int, Parameters, int)
did not match C++ signature:
init(_object*, unsigned int, unsigned int, unsigned int, unsigned int, bool, NEAT::ActivationFunction, NEAT::ActivationFunction, int, NEAT::Parameters, unsigned int, unsigned int)

ok fuck it, github, help me.

https://github.com/peter-ch/MultiNEAT/issues

Ok so the guy pointed out that the constructor changed. It works fine now, after adding a field.

Categories
meta

Musing on audio/visual/motor brain

Just some notes to myself. We’re going to be doing some advanced shitty robots here, with Sim-To-Real policy transfer.

ENSEMBLE NNs

I had a look at merging NNs, and found this https://machinelearningmastery.com/ensemble-methods-for-deep-learning-neural-networks/ with this link as one of the most recent articles: https://arxiv.org/abs/1803.05407 – It recommends using averages of multiple NNs.

AUDIO

For audio there’s https://github.com/google-coral/project-keyword-spotter which uses a 72 euro TPU https://coral.ai/products/accelerator/ for fast processing.

I’ve seen convolution network style NNs on spectrograms of audio (eg https://medium.com/gradientcrescent/urban-sound-classification-using-convolutional-neural-networks-with-keras-theory-and-486e92785df4) Anyway, it’s secondary. We can have it work with an mic with a volume threshold to start with.

MOTION

Various neural networks will be trained in simulation, to perform different tasks, with egg and chicken and human looking objects. Ideally we develop a robot that can’t really fall over.

We need to decide whether we’re giving it spacial awareness in 3d, using point clouds maybe? Creating mental maps of the environment?

VISION

Convolution networks are typical for vision tasks. We can however use HyperNEAT for visual discrimination, here: https://github.com/PacktPublishing/Hands-on-Neuroevolution-with-Python/tree/master/Chapter7

But what will make sense is to have the RPi take pics, send them across to a server on a desktop computer, play around with the image in OpenCV first, and then feed that to the neuro-evolution process.

Categories
Hardware Locomotion Vision

Robot prep 2: GPIO and Camera

So I’ve got the RPi camera images sending to my laptop now, after installing OpenCV4, and running the test code from https://github.com/jeffbass/imagezmq

Next, we need to try move the servos with code.

https://learn.adafruit.com/16-channel-pwm-servo-driver/python-circuitpython

ok so i installed these

First, if no pip3,

sudo apt-get update

sudo apt-get install python-pip3

Then,

sudo pip3 install adafruit-circuitpython-pca9685

sudo pip3 install adafruit-circuitpython-servokit

Adafruit make you copy paste line by line from here…

https://github.com/adafruit/Adafruit_CircuitPython_Motor

Ok looking in the example folder of that,..

from board import SCL, SDA
import busio
from adafruit_pca9685 import PCA9685
from adafruit_motor import servo
i2c = busio.I2C(SCL, SDA)

pca = PCA9685(i2c)
pca.frequency = 50

servo2 = servo.Servo(pca.channels[2])

for i in range(90):
servo2.angle = i
for i in range(90):
servo2.angle = 90 - i
pca.deinit()

i changed it to 90 degrees and got rid of the comments. It suggests a min and max for the servo.

I ran it and the servo got angry with me and wouldn’t stop. I had to unplug everything because it was eating up the cables in its madness.

Ok so datasheet of MG996R: https://www.electronicoscaldas.com/datasheet/MG996R_Tower-Pro.pdf

It keeps going if I plug just the power back in. It seems to rotate continuously. So something is f***ed. Rebooting RPi. It’s supposed to be 180 degree rotation. Will need to read up on servo GPIO forums.

I also tried the ‘fraction’ style code: https://github.com/adafruit/Adafruit_CircuitPython_Motor/blob/master/examples/motor_pca9685_servo_sweep.py

and it rotated and rotated.

So, I think it must be a continuous servo. Now that I look at the product https://mantech.co.za/ProductInfo.aspx?Item=15M8959 i see it was a continuous servo. Derp.

Ok so let’s see… continuous servo: https://github.com/adafruit/Adafruit_CircuitPython_Motor/blob/master/examples/motor_pca9685_continuous_servo.py

We need to set some limits, apparently these are the defaults.

servo7 = servo.ContinuousServo(pca.channels[7], min_pulse=750, max_pulse=2250)

and possibly set this using a calibrated servo, using the calibrate.py program

pca = PCA9685(i2c, reference_clock_speed=25630710)

https://github.com/adafruit/Adafruit_CircuitPython_PCA9685/tree/master/examples

ok. cool.


At a later date, testing the MG996R servo,

I needed to initialise the min_pulse value at 550, or it continuously rotated.

servo7 = servo.ContinuousServo(pca.channels[1], min_pulse=550, max_pulse=2250)

Categories
Vision

Installing OpenCV on RPi

I followed these instructions:

Install OpenCV 4 on Raspberry Pi 4 and Raspbian Buster

sudo apt-get -y update && sudo apt-get -y upgrade

sudo apt-get -y install build-essential cmake pkg-config

sudo apt-get -y install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev

sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

sudo apt-get -y install libxvidcore-dev libx264-dev

sudo apt-get -y install libfontconfig1-dev libcairo2-dev

sudo apt-get -y install libgdk-pixbuf2.0-dev libpango1.0-dev

sudo apt-get -y install libgtk2.0-dev libgtk-3-dev

sudo apt-get -y install libatlas-base-dev gfortran

sudo apt-get -y install libhdf5-dev libhdf5-serial-dev libhdf5-103

sudo apt-get -y install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5

sudo apt-get -y install python3-dev

but then needed two more libs installed, which I found here:

https://github.com/EdjeElectronics/TensorFlow-Object-Detection-on-the-Raspberry-Pi/issues/18

sudo apt install libilmbase23
sudo apt install libopenexr-dev

According to the PyImageSearch guy, opencv will be faster if we build from source, for RPi, but that takes an extra 2 hours. So no.

So the remaining parts were:

sudo wget https://bootstrap.pypa.io/get-pip.py  sudo python get-pip.py
sudo python3 get-pip.py
sudo rm -rf ~/.cache/pip
sudo pip install virtualenv virtualenvwrapper 

Add these to ~/.bashrc

export WORKON_HOME=$HOME/.virtualenvsexport VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3source /usr/local/bin/virtualenvwrapper.sh

Then

source ~/.bashrc
mkvirtualenv cv -p python3
pip install "picamera[array]"
pip install opencv-contrib-python 

This gave this error: Could not find OpenSSL

ok so

sudo apt-get install libssl-dev

Categories
dev Hardware hardware_ Linux

RPi without keyboard and mouse

https://sendgrid.com/blog/complete-guide-set-raspberry-pi-without-keyboard-mouse/

https://github.com/motdotla/ansible-pi

First thing is you need a file called ‘ssh’ on the raspbian to enable it:.

https://www.raspberrypi.org/forums/viewtopic.php?t=144839

ok so I found the IP address of the PI

root@chrx:~# nmap -sP 192.168.101.0/24

Starting Nmap 7.60 ( https://nmap.org ) at 2020-04-05 17:06 UTC
Nmap scan report for _gateway (192.168.101.1)
Host is up (0.0026s latency).
MAC Address: B8:69:F4:1B:D5:0F (Unknown)
Nmap scan report for 192.168.101.43
Host is up (0.042s latency).
MAC Address: 28:0D:FC:76:BB:3E (Sony Interactive Entertainment)
Nmap scan report for 192.168.101.100
Host is up (0.049s latency).
MAC Address: 18:F0:E4:E9:AF:E3 (Unknown)
Nmap scan report for 192.168.101.101
Host is up (0.015s latency).
MAC Address: DC:85:DE:22:AC:5D (AzureWave Technology)
Nmap scan report for 192.168.101.103
Host is up (-0.057s latency).
MAC Address: 74:C1:4F:31:47:61 (Unknown)
Nmap scan report for 192.168.101.105
Host is up (-0.097s latency).
MAC Address: B8:27:EB:03:24:B0 (Raspberry Pi Foundation)

Nmap scan report for 192.168.101.111
Host is up (-0.087s latency).
MAC Address: 00:24:D7:87:78:EC (Intel Corporate)
Nmap scan report for 192.168.101.121
Host is up (-0.068s latency).
MAC Address: AC:E0:10:C0:84:26 (Liteon Technology)
Nmap scan report for 192.168.101.130
Host is up (-0.097s latency).
MAC Address: 80:5E:C0:52:7A:27 (Yealink(xiamen) Network Technology)
Nmap scan report for 192.168.101.247
Host is up (0.15s latency).
MAC Address: DC:4F:22:FB:0B:27 (Unknown)
Nmap scan report for chrx (192.168.101.127)
Host is up.
Nmap done: 256 IP addresses (11 hosts up) scanned in 2.45 seconds

if nmap is not installed,

apt-get install nmap

Connect to whatever IP it is

ssh -vvvv pi@192.168.101.105

Are you sure you want to continue connecting (yes/no)? yes

Cool, and to set up wifi, let’s check out this ansible script https://github.com/motdotla/ansible-pi

$ sudo apt update
$ sudo apt install software-properties-common
$ sudo apt-add-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible

ok 58MB install…

# ansible-playbook playbook.yml -i hosts –ask-pass –become -c paramiko

PLAY [Ansible Playbook for configuring brand new Raspberry Pi]

TASK [Gathering Facts]

TASK [pi : set_fact]
ok: [192.168.101.105]

TASK [pi : Configure WIFI] **
changed: [192.168.101.105]

TASK [pi : Update APT package cache]
[WARNING]: Updating cache and auto-installing missing dependency: python-apt
ok: [192.168.101.105]

TASK [pi : Upgrade APT to the lastest packages] *
changed: [192.168.101.105]

TASK [pi : Reboot] **
changed: [192.168.101.105]

TASK [pi : Wait for Raspberry PI to come back] **
ok: [192.168.101.105 -> localhost]

PLAY RECAP ****
192.168.101.105 : ok=7 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

And I’ll unplug the ethernet and try connect by ssh again

Ah, but it’s moved up to 192.168.1.106 now

nmap -sP 192.168.101.0/24 (I checked again) and now it was ‘Unknown’, but ssh pi@192.168.101.106 worked

(If you can connect to your router, eg. 192.168.0.1 for most D-Link routers, you can go to something like Status -> Wireless, to see connected devices too, and skip the nmap stuff.)

I log in, then to configure some stuff:

sudo raspi-config

Under the interfaces peripheral section, Enable the camera and I2C

sudo apt-get install python-smbus
sudo apt-get install i2c-tools

ok tested with

raspistill -o out.jpg

Then copied across from my computer with

scp pi@192.168.101.106:/home/pi/out.jpg out.jpg

and then make it smaller (because trying to upload the 4MB version no)

convert out.jpg -resize 800×600 new.jpg

Cool and it looks like we also need to expand the partition

sudo raspi-config again, (Advanced Options, and first option)


Upon configuring the latest pi, I needed to first use the ethernet cable,

and then once logged in, use

sudo rfkill unblock 0

to turn on the wifi. The SSID and wifi password could be configured in raspi-config.


At Bitwäsherei, the ethernet cable to the router trick didn’t work.

Instead, as per the resident Gandalf’s advice, the instructions here

https://raspberrypi.stackexchange.com/questions/10251/prepare-sd-card-for-wifi-on-headless-pi

worked for setting up wireless access on the sd card.

“Since May 2016, Raspbian has been able to copy wifi details from /boot/wpa_supplicant.conf into /etc/wpa_supplicant/wpa_supplicant.conf to automatically configure wireless network access”

The file contains

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=«your_ISO-3166-1_two-letter_country_code»

network={
    ssid="«your_SSID»"
    psk="«your_PSK»"
    key_mgmt=WPA-PSK
}

Save, and put sd card in RPi. Wireless working and can ssh in again!

2022 News flash:

Incredibly, some more issues.

New issue, user guide not updated yet

https://stackoverflow.com/questions/71804429/raspberry-pi-ssh-access-denied

In essence, the default pi user no longer exists, so you have to create it and set its password using either the official Imager tool or by creating a userconf file in the boot partition of your microSD card, which should contain a single line of text: username:hashed-password

Default pi and raspberry

pi:$6$/4.VdYgDm7RJ0qM1$FwXCeQgDKkqrOU3RIRuDSKpauAbBvP11msq9X58c8Que2l1Dwq3vdJMgiZlQSbEXGaY5esVHGBNbCxKLVNqZW1