Instructions for getting started

From Rsewiki
Revision as of 13:18, 19 January 2017 by S130074 (Talk | contribs)

Jump to: navigation, search

Contents

Connecting Raspberry Pi to Eduroam

Start by plugging the Raspberry Pi either directly to your PC or to one of the routers on campus. Make sure that you are on the same local network for this.

SSH into the Raspberry Pi by opening a terminal and typing

ssh local@jasmin.local

Replace jasmin with the name of the your robot

When connecting to Eduroam you will eventually have to type in your username and password in the wpa_supplicant.conf-file. In order for your password not to be visible, generate a hash-code for it

echo -n password_here | iconv -t utf16le | openssl md4

Copy the hash-code and clear the terminal window

clear

Now open wpa_supplicant.conf

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Replace whatever in this file so that the content corresponds to the following

country=DK
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
ctrl_interface_group=0
update_config=1
network={
        ssid="eduroam"
        scan_ssid=1
        key_mgmt=WPA-EAP
        eap=PEAP
        phase2="auth=MSCHAPV2"
        identity="username"
        password=hash:your_hash_code
}

Replace username with your username for Eduroam, i.e. your student number and replace your_hash_code with the hash-code you generated in the previous step.

Reboot the Raspberry Pi

sudo reboot

When the Pi has rebooted, connect to it using SSH once again. Check that the Pi is connected to WiFi

ifconfig

Under wlan0 confirm that the Pi has received an IP (inet addr) and note down the first three sections of the IP - they are most likely 10.16.175.xxx

The MAC address (HWaddr) of the Pi should also be noted down - this probably starts with B8:27:EB:xx:xx:xx make sure to get all of it.

Remove the LAN-cabel and connect to the Pi using the IP

ssh local@IP

Replace IP with the actual ID of the robot.

If you want to forward the graphics from the Pi use -X when connecting

ssh -X local@IP

In case the Pi gets a new IP address after reboot, you can search for it using the MAC address and nmap. If nmap is not installed, start by installing it

sudo apt-get install nmap

To search for the Pi using the MAC address in terminal type

sudo nmap -sP 10.16.175.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB:23:A0:F5/{print ip}'

where 10.16.175 is the first three sections of the IP you noted down and B8:27:EB:23:A0:F5 is the MAC address of the Pi. This should return the IP of the Pi.

Hardware Setup

All low level hardware is controlled by the Teensy microprocessor. For the most part, you don't need to make changes here, but some tuning and setup will be necessary. The easiest way to tune parameters and debug mission-lines is through the QtGUI interface:

svn co svn://repos.gbar.dtu.dk/jcan/regbot/qtgui qtgui

The installation might require additional software as listed here under python packages. A manual to QtGUI and possible mission-lines is available here.

Regulators

The Teensy operates with several regulation loops. These can be tuned for optimal performance. The regulators are adjusted under the "Control" tab in QtGUI. Following is listed working parameters for robobot primary functionality:

Velocity

The velocity regulator ensures that the robot keeps the intended speed under different loads. A good set of starting parameters would be as following:

Controller: Kp = 15 | Integrator: Tau_i = 0.15, Limit = 4 | Output limit = 9

Heading

The heading controller should ensure that the robobot keeps the correct heading, this regulator can be setup with:

Controller: Kp = 0.9 | Lead/lag forward: Tau_zero = 1, Tau_pole = 1 | Pre filter:  Tau_zero = 0, Tau_pole = 0.01

Follow edge

This controller helps the robobot navigate after lines marked on the floor. A good starting calibration is:

Controller: Kp = 0.075 

For the edge controller to work properly, a calibration under the "Edge" tab might be necessary, especially to detect white crossing and black crossing. In this case, make sure to calibrate values to the actual tape on the floor.

Calibrating front wheel

The heading should also be adjusted by calibrating the nose wheel controlled by a servo. This is done under the "Servo" tab where servo 0 - the steering servo - should be offset so that the wheel actually points straight.

Software structure

For this section please open the robobot C++ demo and follow along.

General structure

The function missionInit() will initiate three threads on the robobot.

  • Idle
  • Thread 100
  • Thread 101

The general idea is that the idle thread is used to turn on/off hardware/logging/etc and thread 100/101 will execute missions. When thread 100 is active a new mission can be loaded into thread 101 and vice-versa. In this way it is possible to toggle between the two threads and constantly updating the missions to run.

Executing missions

Go to this section to read up on how mission are constructed and how to utilise the sensors in missions.

When a mission is written, e.g.

const char * m1[2] = {    
    "vel=0.3,tr=0.01: turn=180",
    "vel=0, event=1" };

It is send to the missionSendAndRun function. This function will load the mission into the inactive thread and toggle the threads on the Teensy microprocessor which will cause the new mission to be executed.

 missionSendAndRun(m1, 2);

Whenever an event is sent from the Teensy, an eventFlag will be set and the event number is loaded into eventNumber. This can be utilised to monitor the robot and write larger missions in a state-machine manner as explained in the examples section.

Examples

Example 1: Driving a distance

This mission exemplifies how events, sent from the Teensy, is handled by the code running on the Raspberry Pi. The mission should cause the robot to drive one meter, turn 180 degrees and drive back again.

void UMission::runMission1()
{
  missionRunning = true;
  
  // First commands to send to robobot in given mission
  // (robot sends event 1 after driving 1 meter)):
  const char * m1[2] = {    
    "vel=0.5, acc=2 : dist = 1",
    "vel=0, event=1" };
  missionSendAndRun(m1, 2);

  // Primary loop for robobot mission:
  while(missionRunning)
  {

    // Handle events received from Teensy:
    if (bot->eventFlag)
    { 
      bot->eventFlag = false;
      
      switch (bot->eventNumber)
      { 
        // Event 0 indicates that Teensy have been stopped, therefore stopping the mission too. 
        case 0: {
          missionRunning = false;
          printf("--- Mission complete - stopping program!\n");
          break;
        } 

        // Event 1 is in this case received when robobot has driven 1 meter.
        case 1: {
          const char * m2[3] = {
            "vel=0.3,tr=0.01: turn=180",
            "vel=0.5, acc=2 : dist=1",
            "vel=0,event=0:dist=1" };
          missionSendAndRun(m2,3);
          break;
        }
      }
    }
  }
}


Example 2: Acting on events

This mission shows how a sensor event can terminate the program through the code running on the Raspberry Pi. The robot will begin by turning 180 degrees and drive forward until an obstacle is detected by the front facing IR sensor.

void UMission::runMission2()
{ 
  missionRunning = true;
  
  // First commands to send to robobot in given mission
  // (robot sends event 1 after turning 180 degrees): 
  const char * m1[2] = {    
    "vel=0.3,tr=0.01: turn=180",
    "vel=0, event=1" };
  missionSendAndRun(m1, 2);

  // Primary loop for robobot mission:
  while(missionRunning)
  { 

    // Handle events received from Teensy:
    if (bot->eventFlag)
    { 
      bot->eventFlag = false;
      
      switch (bot->eventNumber)
      { 
        // Event 0 indicates that Teensy have been stopped, therefore stopping the mission too. 
        case 0: {
          missionRunning = false;
          printf("--- Mission complete - stopping program!\n");
          break;
        } 

        // Event 1 is in this case received when robobot has turned 180 degrees.
        // Will hereafter drive until a wall or obstacle is detected by IR sensor.
        case 1: {
          const char * m2[2] = {
            "vel=0.5,acc=2 : ir1<0.2",
            "vel=0.0, event=0 : dist=1" };
          missionSendAndRun(m2,2);
          break;
        }
      }
    }
  } 
}

To execute these selected missions, connect to the Raspberry Pi through ssh. Make a function call to the wanted mission in the robobot main file. Thereafter navigate to:

 cd robobot/build 

Compile the newest version of the program:

make

And finally run the code with:

./robobot
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox