WORK-E NETWORK - PROGRESS - THANKS RAY !

Ray really helped me out in the shoutbox.  First, he informed me of how to get static routes to work, but with that information my initial network diagram became unsatisfactory.  The objective is to have one network adapter (wlx0) constantly try to find the best internet connection, while the rest of the system maintain a "stable" connected network.  If the wlx0 finds a "new and improved" wifi with internet access, most likely I will not have access "add a static route".  

Ray suggested I uses another NAT .  It Works Great ! 

WORK-E NETWORK

Work-E is a mobile wifi access point.  A wifi router offers other devices to connect to the "work-e-network". In addition the the mobile access point, work-e has another network adapter which is constantly trying to find and connect to the internet (wlx0...).

It was a little challenging to get the nat working automatically after a reboot.  The following files had to be created or modified.

/sbin/nat.sh


#file : home/GroG/work-e/nat.sh edit raw
#!/bin/bash
# responsible for installing nat between 2 network interfaces
#  wlx00e04c6770ed (upstream/gateway) <- (NAT) <- en01 <- tp-link <- (192.168.7.0 WORK-E NETWORK)
# on work-e
#
# file : /sbin/nat.sh
# chmod +x /sbin/nat.sh
#
# references :  https://www.howtoforge.com/nat_iptables

echo starting iptables nat

# ipforwarding
sysctl -w net.ipv4.ip_forward=1
# verify
sysctl net.ipv4.ip_forward

iptables --flush            # Flush all the rules in filter and nat tables

iptables --table nat --flush

iptables --delete-chain

# Delete all chains that are not in default filter and nat table

iptables --table nat --delete-chain

# Set up IP FORWARDing and Masquerading
# eno1 is "private" wlx is "public"

iptables --table nat --append POSTROUTING --out-interface wlx00e04c6770ed -j MASQUERADE
iptables --append FORWARD --in-interface eno1 -j ACCEPT

# clean up (deletes) FIXME - perhaps persist via netplan explicit routes
# ip route delete 0.0.0.0/0 dev eno1
# ip route delete 192.168.0.1/32 dev eno1

# end file : /sbin/nat.sh
#########################################################################

/etc/systemd/system/nat.service


#file : home/GroG/work-e/nat.service edit raw
#########################################################################
# file : /etc/systemd/system/nat.service
# systemctl enable nat
# systemctl daemon-reload

[Unit]
Description=nat service

[Service]
ExecStart=/sbin/nat.sh

[Install]
WantedBy=multi-user.target

/etc/netplan/01-nat-networkmanager.yaml


#file : home/GroG/work-e/01-nat-networkmanager.yaml edit raw
#########################################################################
# file : /etc/netplan/01-nat-networkmanager.yaml
# Let NetworkManager manage all devices on this system
# commands :
#             netplan generate
#             netplan apply

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eno1:
      addresses:
        - 192.168.100.1/24
      # gateway4: 192.168.0.1
      nameservers:
          search: [myrobotlab.org]
          addresses: [8.8.8.8, 8.8.4.4]

Network Cards connected to Work-E's brain
wireless :  wlx00e04c6770ed - inet 192.168.0.16 netmask 255.255.255.0
wired :  eno1 - inet 192.168.100.1 netmask 255.255.255.0

WORKING ROUTE TABLE
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    600    0        0 wlx00e04c6770ed
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eno1
192.168.0.0     0.0.0.0         255.255.255.0   U     600    0        0 wlx00e04c6770ed
192.168.100.0   0.0.0.0         255.255.255.0   U     100    0        0 eno1
 
References :
 
Re-enabling network for TP-Link
 
# disable dnsmask and hostapd

systemctl disable dnsmasq
systemctl disable hostapd

systemctl stop dnsmasq

systemctl stop hostapd
 
# re-enable systemd-resolve

systemctl enable systemd-resolved
systemctl start systemd-resolved
 
# re-enable nat

systemctl enable nat
systemctl start nat
 
# reboot
 
# verify tp-link uplink ip is reachable
ping 192.168.100.2
 
# back out changes in 
/etc/network/interfaces
 
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
 
# auto wlx00e04c6770ed
# iface wlx00e04c6770ed inet static
# hostapd /etc/hostapd/hostapd.conf
# address 192.168.7.1
# netmask 255.255.255.0
 
# verify network handles a reboot
shutdown -r now
 

WORK-E's in the House ! 

Driven with remote joystick. My house is NOT wheelchair friendly - but I managed with a few bumps and small scrapes to drive WORK-E into my office.  The Joystick service values will need to be tweaked. WORK-E's script needs more dead-zone and stretched map values so its not so hard to control.

Now in the office I'll be working on WORK-E's NETWORK and of course brain upgrades ... Oh, did you know inside, is where all MRL's that you download come from ?  Yep, this one of the computers of the build swarm.

 

 

Finally ! .. started a "real" robot again and I have named it WORK-E 

At the moment its the a wheelchair base which I purchased for $150, I had to get new deep cycle marine batteries and a Sabertooth motor controller to control it. Overall, its very simple design. My intention is to develop remote mobile and autonomous control with MRL.  When it becomes pretty worky, I'll put something like an InMoov on top of it, except I want big strong arms - because how else will it be able to carry the beer home from the super market ?

 

WORK-E CURRENT BLOCK DIAGRAM

BOM

     
  Operating
System
uname -a
Linux parrot 4.12.0-parrot6-amd64 #1 SMP Parrot 4.12.6-1parrot6 (2017-08-24) x86_64 GNU/Linux
 
cat /etc/os-release 
PRETTY_NAME="Parrot GNU/Linux 3.9 Intruder"
NAME="Parrot GNU/Linux"
ID=parrot
VERSION="3.9 (Intruder)"
VERSION_ID="3.9"
ID_LIKE=debian
ANSI_COLOR="1;31"
HOME_URL="https://www.parrotsec.org/"
SUPPORT_URL="https://community.parrotsec.org/"
BUG_REPORT_URL="https://dev.parrotsec.org/"

Debian 10 Buster ???

  Laptop Dell Precision M4800
    2X 25 - Sabertooth Motor Controller
     

WIRING DIAGRAM

 

NEEDED SAFETY CONTROLS

The wheelchair with the 2 marine batteries is very heavy. It can move quickly enough to generate enough force to be somewhat hazerdous (I've already accidently ran over some yard plants).  To avoid other casualties I will be looking into implementing some safety controls.  

  • When communication stops - it should stop.  When I'm driving it remotely and the wifi or rf to the dongle stops .. I don't want it to keep rolling at full speed.
  • Kill Switch - there should be a easy to hit kill switch which cuts all power
  • Bumpers - there should be a bumper all around the bot which activates the kill switch (perhaps pvc with a switch)

As I add more sensors to the system it should be more capable of safetly maneuvering, but the 3 above are my current priorities.

ACCIDENTS

When I was driving WORK-E around in the backyard, the laptop lid closed, and when it did - all the software stopped, with the last command telling the motor controller to move forward at 80%. So nothing changed when it hit a wall :P.

The laptop closing no longer puts it into sleep mode.  In addition I'll be adding many sensors which will at some point distinguish if it should stop or not.  Also, I'll be adding an external emergency kill switch for a manual shut-off of all power.

WIFI

WORK-E will probably have his own wifi router and at some later point a mobile smartphone.  At the moment WORK-E is in the shop, and the shop is 20+ feet away from the house.  I usually like working on software in the house, since the shop is unheated.  To do so successfully, there must be "good" connectivity.  I setup an old wifi router I have in the house, then connected the two routers with a ether over power link (???link???).  It has worked well, except routing. Ping requests from my computer to WALL-E were taking over a 1000ms to complete, while ping requests from WALL-E to google were only 14ms.  I configured the old wifi router to do dynamic routing with RIP .. after the restart of the router - pings from my computer only take 5ms.  goodtimes

WORK-E SCRIPT

If you don't want to run MRL as root, you'll probably need to add a few groups to your user.  This one for example is for using the joystick on Linux/Ubuntu

usermod -a -G input robot


#file : home/GroG/work-e.py edit raw
#########################################
# work-e.py
#########################################
# uncomment for virtual hardware
from org.myrobotlab.service import Serial
# virtual = True

# sabertooth serial port - if on windows might be COM4
# port = "COM14"
# port = "/dev/ttyUSB0"
# I use udev rules to always make it the same port
port = "/dev/ftdi0"

# controller index for the joystick
controllerIndex = 0

# start optional virtual serial service, used for test
if ("virtual" in globals() and virtual):
    # use static method Serial.connectVirtualUart to create
    # a virtual hardware uart for the serial service to
    # connect to
    uart = Serial.connectVirtualUart(port)
    uart.logRecv(True) # dump bytes sent from sabertooth

# TODO - list & print controllers
# TODO - list & print controllers
# TODO - list & print axis

# start the services
sabertooth = Runtime.start("sabertooth","Sabertooth")
m1 = Runtime.start("m1","MotorPort")
m2 = Runtime.start("m2","MotorPort")
joy = Runtime.start("joy","Joystick")
joy.setController(controllerIndex)

# configure services
m1.setPort("m1")
m2.setPort("m2")

# in some cases its necessary to "invert" a motor
m1.setInverted(True)
m2.setInverted(True)

# attach services
sabertooth.attach(m1)
sabertooth.attach(m2)
m1.attach(joy.getAxis("y"))
m2.attach(joy.getAxis("rz"))

# FIXME - sabertooth.attach(motor1) & sabertooth.attach(motor2)
# FIXME - motor1.attach(joystick) !
sabertooth.connect(port)

m1.stop();
m2.stop();

# good to go - play with joystick

PROTECTIVE RAIN COVERING

It rains alot here - so I wanted to have a roomy component area which would not get wet.  I re-purposed a plastic bin with clips.  I'll probably makes some slots in the bottom and mount a fan for ventiation.

LAPTOP SHOULD STAY ON WITH LID SHUT

vi /etc/UPower/UPower.conf
IgnoreLid=true
service upower restart

There is more "options" in /etc/systemd/logind.conf, but these don't cover all the usecases. For example, even when I changed HandleLidSwitch=ignore it would still go into suspend after the lid was shut AND the power adapter was removed.

STOP USB PORT SWITCHING

When the laptop rebooted, or when the USB-FTDI cable was inadvertently pulled out, and plugged back in, often the /dev/ttyUSB0 would change to /dev/ttyUSBx.  Where x would be a random number.  Having the com port switch on you all the time can be aggrevating.  On Linux it can be solved this way.

Udev ! - first query
https://unix.stackexchange.com/questions/66901/how-to-bind-usb-device-un...

then the rule
https://playground.arduino.cc/Linux/Udev 

KINECT

Currently I'm running Parrot OS which is a derivative of Debian. To get the Kinect working, I followed the NeuroDebian FreeNect install instructions.

A very useful command was to list all usb Xbox devices

┌─[✗]─[root@parrot]─[~]
└──╼ # lsusb | grep Xbox
Bus 003 Device 056: ID 045e:02ae Microsoft Corp. Xbox NUI Camera
Bus 003 Device 049: ID 045e:02b0 Microsoft Corp. Xbox NUI Motor
Bus 003 Device 050: ID 045e:02ad Microsoft Corp. Xbox NUI Audio
 
And above are my 3 devices.

 

References :


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Kakadu31's picture

I likme it! your base is a

I likme it! your base is a little better looking than mine. I will need to test soon if My system is still working with all those changes with sabertooth but If not I guess your code will do for me too, As I also am running it from linux, use a sabertooth controller and have a big differential steering base ;) You could add a diagramm or picture of the communication mode of the sabertooth. I guess it will help some people not to read the whole manual to figure it out as I did and you probably too =)

GroG's picture

The switch diagram, wiring

The switch diagram, wiring diagram, example code, and references to all manuals is on the service page.

http://myrobotlab.org/service/Sabertooth

bartcam's picture

Nice Work Grog, great base

Nice Work Grog, great base for inteligent lawn mover. :)