Skip to content

General Computing

pryre edited this page Jun 17, 2017 · 27 revisions

Linux in a Nutshell

If you have any plans to work with robotics, or high-performance systems, you are most likely looking at using Linux in some form.

TODO

GUI vs. CLI

TODO

Some basic CLI tools to remember (you can use the "-h" and "--help" options to find out more information):

  • ls - List directory
  • cd - Change directory
  • cp - Copy file
  • mv - Move (or rename) file
  • cat - Concatenates (prints) a files contents
  • nano - A basic text editor (use "CTRL+X" to exit)

Some more advanced tools:

  • tmux - Allows for detached sessions (keeps processes alive if disconnected), terminals in 1 window, multiple windows, etc.

Preparing a Work Environment

Before we can dive into using Linux, we will need to install it in some manner.

The "Non-Committal" Way

The easiest way to try Linux in a semi-permanent fashion is to use virtualization. The typical method would be to use a hypervisor, such as "VirtualBox", to effectively emulate the entire system. This method will only create a Virtual Machine which exist as files on your hard drive, and are therefore very easy to uninstall when you are done with

There are main considerations that you should check before using a Virtual Machine:

  • A VM will make it difficult (but not impossible) to communicate from a remote computer to the guest computer.
  • VM support for 3D software (specifically software using OpenGL or DirectX) will most likely not run inside the VM (although there is some exceptions).
  • They provide a super-easy backup solution (after you install ROS, etc., you can copy-paste the VM to make a backup. You can also make Snapshots of the VM to roll back to at a later date).
  • They provide a risk-free environment (nothing done on the Guest should be able to affect Host, also provides immediate protection from accidentally deleting files on the Host)
  • Guest machines should not be used for anything that is time-critical (real time computations can be delayed significantly if the Host is under high load, and the Guest may think it is still running in real-time)

As a suggestion, go check out VirtualBox for further information.

The "Right" Way

The "proper" way to install Linux is by actually installing it to the hard drive. This will get around all the disadvantages that the Virtual Machines suffer, but does require a bit more commitment and setup on the software side. If you are all ready running an operating system, such as Windows, your best option is to look into "dual booting", which will allow you to switch back and forth between the two systems.

For further information on a good place to start, go check out the Ubuntu Dual Boot guide for further information.

Serial Access

As a start point, or as a reliable backup, it may be desirable to configure a login prompt over a hardware serial line. In modern systems, first you must identify the serial port (in this example, we want to start the serial on "/dev/ttyS2"), then it should be as simple as running the following commands:

systemctl enable [email protected]
systemctl start [email protected]

Or (as an example, to use the header Tx/Rx on a Raspberry Pi):

systemctl enable [email protected]
systemctl start [email protected]

Networking in Linux

Networking in Linux is a fairly open experience, as the system will allow nearly any combination of configurations if it is set up correctly. Unfortunately, such a setup takes time, and may not be the most appropriate for a system that can afford to be much simpler.

The best way to list the available networking devices is with the following command:

ifconfig

Quick Setup

For most devices, the best place to start is by getting the ethernet port configured (if it isn't already). For most Ubuntu-type systems, there are two primary options for getting a basic connection up and running.

Going forward, if you are on a fresh system, you may find that there one device as already in the following files, the "loopback" interface. THIS MUST NOT BE DISABLED UNDER ANY CIRCUMSTANCE, as your terminal and many other system functions. It will look something like this for reference:

auto lo
iface lo inet loopback

For most backwards compatibility, edit the file "/etc/interfaces" and ensure the following lines are there.

For DHCP (best when using some kind of router):

auto eth0
iface eth0 inet dhcp

For a static address (best if you need to do a direct connection):

iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.254

The system will need to be rebooted for the settings to be applied.

For newer systems, the folder "/etc/interfaces.d/" can be used to configure multiple setups and devices. To use this option, simply create a file "/etc/interfaces.d/eth0.cfg" and add the same lines as above to it. This won't be covered here for brevity.

Automated/Managed

Before continuing on with managed network solutions, there is a very important point to make: ONLY ONE SOLUTION CAN BE USED AT A TIME. If multiple solutions are used, there WILL be issues with your network connectivity. This means that once you install a network manager, you must disable the lines for devices configured in the "Quick Setup" process.

Before continuing, note that a user may need to be in the "netdev" group to control these network managers:

sudo usermod -aG netdev $USER

Remember to log out and back in to make sure the group permissions are updated.

As far as network managers go, there are 3 main contenders (as of time of writing):

  • NetworkManager - A very configurable, expandable, and scalable network manager
    • Start with sudo systemctl start NetworkManager.service
    • Can be controlled through the command line with nmcli
    • Can be controlled through a GUI with nm-applet
    • Can be configured to run multiple connections at once
  • wicd - A simple, reliable, and scripting-friendly network manager
    • Start with sudo systemctl start wicd.service
    • Can be controlled through the command line with wicd-cli
    • Can be controlled through the command line as an interface with wicd-curses
    • Can be controlled through a GUI with wicd-gtk
    • Can only have one connection active at any one time
  • connman - A light-weight networking solution aimed at ARM-based devices
    • Start with sudo systemctl start connman.service
    • Can be controlled through the command line with connmanctl
    • Can be controlled through a GUI with cmst
    • Can only have one connection active at any one time

**Out of personal experience, wicd provides the most reliable and easiest to configure network manager``

Wireless Networking

Wireless networking can be configured in multiple different ways, depending on the application of your system.

Using a Router

The easiest way to configure and use one or more wireless devices is to have some form of wireless-capable router. This will allow you to to many different configurations, and will usually handle DHCP, so you do not need to worry about static IPs

Ad Hoc

Allows the creation a dynamic networks using only the wireless chips on the devices that are connecting to the network. This is very useful when trying to create a network where multiple devices need to talk to each other in the field, or where using a router will be inconvenient.

Hotspots

A newer configuration where a single device will act as a host/router, allowing other devices to connect to it and will assign IP addresses to each device. This is most useful for devices that need to be connected to for initial configuration, but do not need a permanent connection, or as an initial interface before a permanent configuration is set up.

WiFi issues

Due to the way the 802.11 (WiFi) standard is defined, there is a random and variable delay for a device to wait while the channel is busy. Combined with general noise and interference, this can cause WiFi to be very unreliable, in respect to trying to maintain a low-latency transmission. Out of previous experience, WiFi cannot realistically be relied on for anything that requires a latency <50ms.

Other issues to consider is how to handle disconnections, or devices not connecting in the first place.

Remote Access

For most systems that are running without some form of easy access (e.g. an on-board computer), it is often desirable to have some form of method to access them remotely. The most versatile method is by using Secure Shell (SSH). SSH is a tool that allows us to log in as any user through a remote IP address.

With most distributed OS images, SSH will be enabled by default, all that is needed to log in is a username/password and the remote system's IP address. Most Linux systems will come with the SSH client pre-installed, and if the local system is running something like Windows, a program like "Putty" will need to be used. On Linux, simply run the command:

ssh user@remote-ip

For more powerful systems, it is also possible to achieve a Virtual Remote Connection (VNC), which will allow access to a desktop GUI on the remote system. As a good starting point, look into "TigerVNC" for more information.

Time

Working on a distributed network can bring some unforeseen consequences to how you have to plan out data processing and handling. The main 2 issues that will affect a network are latency (the time it takes for data to be sent) and time syncing (having 2 independent computers tracking "current time" separately).

To get around this, most complex systems will implement 2 other systems:

  • A dedicated local network for the computers to converse over without worrying about other computers clogging up available bandwidth (usually through the use of an router)
  • A method for synchronizing system time across multiple devices

To combat the issues of time synchronization, there are many methods that can be used, however, for the sake of simplicity, we will use a client-server model. Fortunately for us, most large computer-based organizations (should) run a time server. Although this is not on the local subnet (or router), we (hopefully) have a gigabit connection to the timeserver through the network, so for the purposes of the occasional sync (as we don't really have to worry about long-term bandwidth congestion), this will do quite nicely for our purposes.

First off, we need to install and start the package called "chrony" on all computers that will be using network. Next, we just have to tell chrony where to look to find the best timeserver. Open the file "/etc/chrony/chrony.conf" (on Ubuntu-type systems) and scroll down to the first line that is uncommented, it should look something like:

server 0.pool.ubuntu...

OR:

pool 0.pool.ubuntu...

In either case, comment this line out (add a '#' to the front of the line), and just above it we will enter the location of our time server (QUT's timeserver for example):

server time.qut.edu.au iburst

This will configure chrony to only look for this server to sync with. If your network blocks external time servers (as QUT does), this means that your PC will only be able to sync with this time server when you're on the network. If you would like to time sync with a public server when you are not on the network (which is probably a good idea anyway), you could uncomment the original time server, but have it second in the list.

Another fairly critical setting to configure is the "makestep" setting. This will tell chrony that it is allowed to perform a large initial jump in time during the first few time syncs. The following setting will large jumps to occur if the time delta is larger than 1.0 seconds, but only on the first 3 time syncs. Find the and change the setting to the following (or just enter it near the top of the config file):

makestep 1.0 3

Finally, run the following command to restart chrony:

sudo systemctl restart chrony.service

You can now run the following to see what server chrony has synced with (although it may take a few seconds):

chronyc tracking -a

If the server you entered is listed near the top, then success!

Accessing USB Devices

In Linux, there is some devices that may not be accessible without the correct permissions.

USB Flash Drives

Unlike a normal desktop computer set up to be used in a GUI, Linux won't automatically mount a USB flash drive so it can be accessed by a user.

First we must create a mount point (a path that will allow us to access the device). Then we have to give the correct permissions so a user can read and write to the device (in this case, we give read/write for all users).

sudo mkdir /media/usb
sudo chmod  g+rw,o+rw,u+rw /media/usb

Next we can mount the device to the path we created (assuming you know the device and partition you want to mount).

sudo mount /dev/sdX /media/usb 

Lastly, remember to un-mount the device before you remove it from the system (we also use sync to check all data has been transferred)

sync
sudo umount /media/usb 

Serial Adaptors

Before we can use a serial device such as a USB-Serial Converter, we must add our user to the "dialout" group. This will allow us to use any "/dev/ttyX" device.

sudo usermod -aG dialout $USER

Remember to log out and back in to make sure the group permissions are updated.

If we are using a pre-installed system, it is a good idea to remove the "modem manager" package, as it tends to really mess with serial communications. As an example for Ubuntu:

sudo apt remove modemmanager

Cameras & Video

Before we can use a video device such as a webcam, we must add our user to the "video" group. This will allow us to use any "/dev/videoX" device.

sudo usermod -aG video $USER

Remember to log out and back in to make sure the group permissions are updated.

Clone this wiki locally