Talk:Cheesoid: Difference between revisions

From Nottinghack Wiki
Jump to navigation Jump to search
Line 275: Line 275:
* cylinder case mods
* cylinder case mods
** speakers in mouth plate/grill
** speakers in mouth plate/grill
*** possible replacement speaker: USB rechargeable single speaker $6.38
*** http://lightake.com/detail.do/sku.Audio_Artist_Hamburger_Mini_Speaker___Black-41485
** side mount for MCU1 and support boards (temporary?)
** side mount for MCU1 and support boards (temporary?)
** top for beacon - keep on side for now
** top for beacon - keep on side for now
** mounting of cylinder on chassis  
** mounting of cylinder on chassis -- 2x panel circular base (inner diameter of shell) cut with jigsaw


* motor mountings
* motor mountings

Revision as of 19:38, 14 October 2011

Interaction Goals

Cheesoid is intended to be a fully autonomous mobile robot that interacts with people and objects in its environment. Human-Robot interaction is a massive subject but I intend to get some rudimentary (and comedic) speech and general input features in place as soon as possible. The environment interactions will develop as I learn more about sensing and mapping. Since the robot will live at Hackspace I have two basic goals for comedy value: -

  • interact with the fridge for cheese status
  • interact with the petrol pump for petrol status

So...

  • it needs to know where they are to go and talk to them
  • the status needs to be stored and needs to be set - Xino at each? Via IRC bot? Some web interface?
  • it need to be able to read the status from the fridge and the petrol pump - what sort of interface? IR remote control?

Petrol status

  • just a number!

Cheese status

  • many cheese types - each with use by date
  • Primula status is "in tube"

Human - Robot Interactions: speech

With the eeePC I have a very capable processor on board and I'm taking full advantage of that: -

  • using espeak for text to speech
  • using sphinx for speech recognition

Text to Speech with espeak

http://espeak.sourceforge.net/

The espeak voices aren't really robotic enough but can be made more so by creating a custom voice

speech recognition with sphinx

http://cmusphinx.sourceforge.net/wiki/tutorialconcepts

The sphinx packages

p    --\ sphinx2-bin                                                                                                                    <none>     0.6-2.1
  Description: speech recognition utilities
    Sphinx 2 is a real-time, speaker-independent speech recognition system.

    This package contains examples and utilities that use Sphinx. It also includes a sample language model that is capable of recognizing simple commands
    like "go forward ten meters" and other commands one might use to tell a robot where to move.
  Priority: optional
  Section: universe/sound
  Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
  Compressed size: 129k
  Uncompressed size: 500k
  Source Package: sphinx2
  --\ Depends (3)
    --- libc6 (>= 2.4)
    --- libsphinx2g0 (>= 0.6) (UNSATISFIED)
    --- sphinx2-hmm-6k (UNSATISFIED)
  --\ Packages which depend on sphinx2-bin (0)
  --\ Versions of sphinx2-bin (1)
p    0.6-2.1

Good examples of the use of sphinx: -

If Sphinx 4 works on the eeePC (try the demos) then go ahead and use it from Java.

Conversations and dialogue

In order to have a meaningful (preferably amusing and slightly uncanny) interaction with humans there needs to be a dialogue and some involvement of non-verbal communications: perhaps some shared experience, empathy, etc. We can fake a lot of things to push the human participant closer to the goal!

Mobility

  • motors
  • wheels
  • chassis
  • motor power
  • motor control circuitry
  • big battery

Drive motors: I now have my 12V 150RPM gearmotors from China


OK, motors tested with a two motor circuit...

Motor Test sketch (non-PWM)

int motor_left[] = {
  2, 3};
int motor_right[] = {
  7, 8};
const int ledPin = 13;      // LED 
const int switchPin = 10;    // switch input
const int enablePin = 9;    // H-bridge enable pin


// ————————————————————————— Setup
void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(switchPin, INPUT); 
  pinMode(enablePin, OUTPUT);


  // Setup motors
  int i;
  for(i = 0; i < 2; i++){
    pinMode(motor_left[i], OUTPUT);
    pinMode(motor_right[i], OUTPUT);
  }
  check_enable();
  // blink the LED 3 times. This should happen only once.
  // if you see the LED blink three times, it means that the module
  // reset itself,. probably because the motor caused a brownout
  // or a short.
  blink(ledPin, 3, 100);

}


void check_enable(){
  digitalWrite(enablePin, digitalRead(switchPin));
}
// ————————————————————————— Loop
void loop() {

  drive_forward();
  delay(1000);
  motor_stop();
  Serial.println("1");

  drive_backward();
  delay(1000);
  motor_stop();
  Serial.println("2");

  turn_left();
  delay(1000);
  motor_stop();
  Serial.println("3");

  turn_right();
  delay(1000);
  motor_stop();
  Serial.println("4");

  motor_stop();
  delay(1000);
  motor_stop();
  Serial.println("5");
}

// ————————————————————————— Drive

void motor_stop(){
  check_enable();
  digitalWrite(motor_left[0], LOW);
  digitalWrite(motor_left[1], LOW);

  digitalWrite(motor_right[0], LOW);
  digitalWrite(motor_right[1], LOW);
  delay(25);
}

void drive_forward(){
  check_enable();
  digitalWrite(motor_left[0], HIGH);
  digitalWrite(motor_left[1], LOW);

  digitalWrite(motor_right[0], HIGH);
  digitalWrite(motor_right[1], LOW);
}

void drive_backward(){
  check_enable();
  digitalWrite(motor_left[0], LOW);
  digitalWrite(motor_left[1], HIGH);

  digitalWrite(motor_right[0], LOW);
  digitalWrite(motor_right[1], HIGH);
}

void turn_left(){
  check_enable();
  digitalWrite(motor_left[0], LOW);
  digitalWrite(motor_left[1], HIGH);

  digitalWrite(motor_right[0], HIGH);
  digitalWrite(motor_right[1], LOW);
}

void turn_right(){
  check_enable();
  digitalWrite(motor_left[0], HIGH);
  digitalWrite(motor_left[1], LOW);

  digitalWrite(motor_right[0], LOW);
  digitalWrite(motor_right[1], HIGH);
}

/*
    blinks an LED
 */
void blink(int whatPin, int howManyTimes, int milliSecs) {
  int i = 0;
  for ( i = 0; i < howManyTimes; i++) {
    digitalWrite(whatPin, HIGH);
    delay(milliSecs/2);
    digitalWrite(whatPin, LOW);
    delay(milliSecs/2);
  }
}

This sketch is a munge of http://letsmakerobots.com/node/2074 and http://itp.nyu.edu/physcomp/Labs/DCMotorControl

OK, after a couple of nights at Hackspace I now have the motors mounted and coupled to the wheel assemblies but the whole thing is way too weak to drive the wheels when using the big 12v lead-acid batteries I have. It's a little better with the bench power supply at 12v and it's how I'd want it with the bench supply at 14v. I think there's multiple problems here: the wheel assemblies are heavy and the shed-built motor brackets are inaccurate, as are the polymorph couplings (an idea borrowed from here http://letsmakerobots.com/node/15354). I thought that the wheel assembly would be necessary to take some of the load off the motor axles but I see quite a lot of setups with the wheels attached directly to the motors as in this example that also uses 38mm motors: http://www.pololu.com/catalog/product/730

I'm tempted to redesign around some direct wheel couplings and purchased wheels even though I love the CD wheel idea.

I've joined the letsmakerobots.com forum and I'm going to ask some advice there.

--Michael Erskine 09:18, 8 October 2011 (EST)

MCU1 Motor Control

MCU1 will drive each motor via the SN754410 with three signals: Motor_Logic_1, Motor_Logic_2, and Motor_Enable (corresponding to the SN754410 pins). The Motor_Enable signals will be PWM thus using in total 2 PWM outputs plus 4 digital outputs. This allows a simple interface to the SN754410.

Control is via serial from the eeePC giving parameters of direction and speed for both motors at once. The motors can be put in hold with a stop command. The messages need to be quick for MCU1 to read and interpret but also easily human-readable.

 D[L-dir][L-speed][R-dir][R-speed]
 
 direction = 1 char, 'F' = forwards, 'B' = backwards, 'X' = hold
 speed = 3 ASCII decimal digits in range 000 to 255 left zero padded 

Examples: -

  • DF255F255 = full speed ahead
  • DF127F127 = half speed ahead
  • DF000F000 = freewheel?
  • DX000X000 = hold stop
  • DB255F255 = fast rotate left
  • DF255B255 = fast rotate right
  • DX000F255 = fast pivot left

The PWM will continue unless stopped so we should have a timeout on MCU1

Bodywork

  • battery regulation: http://letsmakerobots.com/node/3880
  • battery mounting - where?
    • chassis strong enough to carry those batteries? !!!!
    • aluminium cross bracing?
    • perhaps move to 2x 6V - keep it flexible

Motor shaft couplings being the most annoying thing right now

  • I really need some well made couplings like these

Small hose clips may be the thing.

Brains

The current design makes use of a few processors: the small cheap eeePC 701 4G netbook and a couple of inexpensive (£7) Xino Arduino micros.

MCU1 and MCU2

Xino devices

MCU1 PIN usage summary table here on Google Docs

MCU1 software

/*******************************************************************/
/*                          CHEESOID MCU1                          */
/*******************************************************************/

// I/O Pin definitions...
// The mode switch is on a digital input...
const int PIN_MODESW = 4;
// Two LEDs are used for eyes on two digital pins...
const int PIN_EYE1 = 7;
const int PIN_EYE2 = 8;
// Built-in LED on pin 13 used for watchdog status...
const int PIN_WDLED = 13;
// Motor enable/speed PWM outputs...
const int PIN_M1SPD = 9;
const int PIN_M2SPD = 10;
// Motor control logic digital outputs...
const int PIN_M1C1 = 14;
const int PIN_M1C2 = 15;
const int PIN_M2C1 = 16;
const int PIN_M2C2 = 17;
// Bumper inputs...
const int PIN_BMP1 = 18;
const int PIN_BMP2 = 19;
// Soft serial to MCU2...
const int PIN_MCU2TX = 11;


// Last watchdog time tracking...
unsigned long wdoglast = 0;
// main loop has 10ms sleeps...
const int naptime = 10;
// the eyes flash every 60 loops = 600ms...
int eyefreq = 60;
// info is sent out on the serial port every 90 loops = 900ms...
int reportfreq = 90;
// a simple loop counter is used to decide what to do...
unsigned int loopcounter = 0;
// mode switch state...
int mode = 0;

// System counters...
// Max number of bytes read in one go...
#define CTR_MAXREAD 0
// number of buffer overflows avoided...
#define CTR_OVERFLOW 1
// Number of bytes received...
#define CTR_BYTES 2
// Number of unknown message commands...
#define CTR_UNKMSG 3
// Number of unknown message commands...
#define CTR_WDOGTO 4
static int counters[4];
// watchdog timout in millis...
#define WDOG_TIMEOUT (long)7000
// size of our incoming message buffer...
#define MAXMSG 50

void setup() {
  Serial.begin(9600);
  pinMode(PIN_MODESW, INPUT);
  pinMode(PIN_EYE2, OUTPUT);
  pinMode(PIN_EYE1, OUTPUT);
  pinMode(PIN_WDLED, OUTPUT);
  //
  pinMode(PIN_M1SPD, OUTPUT);
  pinMode(PIN_M2SPD, OUTPUT);
  pinMode(PIN_M1C1, OUTPUT);
  pinMode(PIN_M1C2, OUTPUT);
  pinMode(PIN_M2C1, OUTPUT);
  pinMode(PIN_M2C2, OUTPUT);
  // TODO soft serial link to MCU2
  pinMode(PIN_MCU2TX, OUTPUT);
  //
  pinMode(PIN_BMP1, INPUT);
  pinMode(PIN_BMP2, INPUT);
    
  // announce startup...
  flasheyes(200);
  Serial.println("\n=== CHEESOID ===");
  // TODO: piezo buzzer to play a tune
  mode = digitalRead(PIN_MODESW);
}

void flasheyes(int zeds) {
  for(int i=0;i<6;i++){
    int onoff = i % 2;
    digitalWrite(PIN_EYE2, onoff);
    digitalWrite(PIN_EYE1, onoff);
    delay(zeds);
  }
}

void loop() {
  static int act;
  do_switch();
  do_eyes();
  act = do_report();
  act += do_serialinput();
  if(!act)
    delay(naptime);
  loopcounter++;
}

void do_switch() {
  // button debounce: state must remain stable for N samples.
  // This is just a lightweight debouncer
  // used if we want to avoid the more general purpose 
  // but heavyweight Bounce library.

  const int debouncesamples = 5;
  static int lastsample = 0;
  static int steadycount = 0;
  static int debounced = 0;
  // if the value is steady for 
  int sample = digitalRead(PIN_MODESW);
  // a change of value - restart the steady count...
  if(sample != lastsample){
    lastsample = sample;
    steadycount = 0;
    return;
  }
  steadycount++;
  if(steadycount < debouncesamples)
    return;
  steadycount = debouncesamples;
  debounced = sample;
  // set the actual mode switch value
  mode = debounced;
}

void do_eyes() {
  static int eyestate = 0;
  if(loopcounter % eyefreq != 0)
    return;
  eyestate = !eyestate;
  digitalWrite(PIN_EYE2, eyestate);
  digitalWrite(PIN_EYE1, !eyestate);
}

int do_report() {
  if(loopcounter % reportfreq != 0)
    return 0;
  Serial.print("CHEESOID: mode = ");
  Serial.print(mode);
  //~ Serial.print(" | eye = ");
  //~ Serial.print(onoff);
  Serial.print(" | loop = ");
  Serial.println(loopcounter);

  // also timeout the watchdog if set...
  // this activity is limited by the reportfreq
  if(wdoglast != 0){
    long now = millis();
    if(now - wdoglast > WDOG_TIMEOUT){
      digitalWrite(PIN_WDLED, LOW);
      counters[CTR_WDOGTO]++;
      wdoglast = 0;
    }
  }
  return 100;
}

int do_serialinput() {
  // can we avoid buffer overflows when using the 
  // standard serial library at a 10ms read rate at 9600 baud?
  // Well, 9600 8-n-1 is 960 bytes per sec or 9.6 per 10ms
  // The standard serial receive buffer holds 128 bytes so we're fine
  // already nulled by compiler - we leave the final char alone!
  static char msgbuf[MAXMSG+2];
  static int len = 0;
  // any data waiting?
  int ba = Serial.available();
  if(!ba)
    return 0;
  if(ba > counters[CTR_MAXREAD])
    counters[CTR_MAXREAD] = ba;
  for(int i = 0; i < ba; i++){
    int c = Serial.read();
    Serial.print("GOT:");
    Serial.println(c, DEC);
    // upon LF, process message...
    if(c == 0x0A){
      // NB: ignore incoming char - now looking at the buffer...
      c = msgbuf[0];
      if(c == 'E'){
        flasheyes(50);
        Serial.println("I OBEY: FLASH EYES!");
        len = 0; // reset message
        continue; // ignore rest of message!
      }
      // watchdog kick - proof that PC is alive
      if(c == 'W'){
        // LED on for a while (needs timeout)
        // lastkick var
        Serial.println("Watchdog!");
        digitalWrite(PIN_WDLED, HIGH);
        wdoglast = millis();
        len = 0; // reset message
        continue; // ignore rest of message!
      }
      // Drive command...
      if(c == 'D'){
        DriveInterpret(msgbuf, len);
        len = 0; // reset message
        continue;
      }
      // Test commands...
      if(c == 'T'){
        int testmode = msgbuf[1];
        if(testmode == 'D') {
            TestMotors();
            len = 0;
            continue;
        }
        len = 0; // reset message
        continue;
      }
      counters[CTR_UNKMSG]++;
      continue;
    }
    // check for and avoid overflow...
    if(len > MAXMSG){
      counters[CTR_OVERFLOW]++;
      len = 0; // reset message
      continue;
    }
    // add msg to end of buffer and carry on...
    msgbuf[len] = c;
    len++;
    // null terminate for debugging - OK to do if buffer len is MAXMSG+2!
    msgbuf[len] = '\0';
  }
  return ba;
}

/*******************************************************************/
/*                  Motor drive control messages                   */
/*******************************************************************/
// 
//~ D[L-dir][L-speed][R-dir][R-speed]
//
//~ direction = 1 char, 'F' = forwards, 'B' = backwards, 'X' = hold
//~ speed = 3 ASCII decimal digits in range 000 to 255 left zero padded 
// 
// Each message is 9 chars long.
//
//~ Examples: -
//~ DF255F255 = full speed ahead
//~ DF127F127 = half speed ahead
//~ DF000F000 = freewheel?
//~ DX000X000 = hold stop
//~ DB255F255 = fast rotate left
//~ DF255B255 = fast rotate right
//~ DX000F255 = fast pivot left
//~ The PWM will continue unless stopped so we should have a timeout on MCU1
/*******************************************************************/
void DriveInterpret(const char* msg, int len)
{
  int pwm1, pwm2, motor1_c1, motor1_c2, motor2_c1, motor2_c2;
  // Validate input
  if(msg == 0 || len < 9)
      return;
  pwm1 = ((msg[2]-'0')*100) + ((msg[3]-'0')*10) + (msg[4]-'0');
  pwm2 = ((msg[6]-'0')*100) + ((msg[7]-'0')*10) + (msg[8]-'0');
  // the motor directions are rather arbitrary as they 
  // can be easily wired as necessary
  if(msg[1] == 'F'){
    motor1_c1 = HIGH;
    motor1_c2 = LOW;
  } else if(msg[1] == 'B'){
    motor1_c1 = LOW;
    motor1_c2 = HIGH;
  } else { // default to hold
    motor1_c1 = LOW;
    motor1_c2 = LOW;
  }
  if(msg[5] == 'F'){
    motor1_c1 = HIGH;
    motor1_c2 = LOW;
  } else if(msg[5] == 'B'){
    motor1_c1 = LOW;
    motor1_c2 = HIGH;
  } else { // default to hold
    motor1_c1 = LOW;
    motor1_c2 = LOW;
  }
  DriveMotors(motor1_c1, motor1_c2, pwm1, motor2_c1, motor2_c2, pwm2);
}

void DriveMotors(int motor1_c1, int motor1_c2, int pwm1, 
    int motor2_c1, int motor2_c2, int pwm2)
{
    // TODO timeout and bumpers!
    digitalWrite(PIN_M1C1, motor1_c1);
    digitalWrite(PIN_M1C2, motor1_c2);
    analogWrite(PIN_M1SPD, pwm1);
    digitalWrite(PIN_M2C1, motor2_c1);
    digitalWrite(PIN_M2C2, motor2_c2);
    analogWrite(PIN_M2SPD, pwm2);
}

// TODO Test motors forever!
void TestMotors()
{
    
    
}


MCU2 software

  • drives LCD display
  • needs serial in from MCU1
  • status LED to panel

eeePC mods

Hardware and system mods to support "isolated usage".

  • soldered in an external power button cable
    • PWR button sub-assembly with safety keyswitch - mount on side panel
    • TODO LED in "Micro" and other nice illuminated buttons
    • Monostable/bistable startup flasher circuit for "Micro" switch?
  • "pizza box" container
    • power port extension
    • USB extension - USB hub - still powering MCU1 from USB - much drain?
#!/bin/sh
LID_STATE=`cat /proc/acpi/button/lid/LID/state | awk '{print $2 }'`

if [ $LID_STATE = "closed" ] ; then
#    /etc/acpi/suspend2ram.sh
        /bin/su user -c "/usr/bin/xrandr --output VGA --mode 800x600 --output LVDS --off"
fi
if [ $LID_STATE = "open" ] ; then
        /bin/su user -c "/usr/bin/xrandr --output LVDS --preferred --output VGA --off"
fi
exit 0

This is not enough: the eeePC will not power on with the lid closed so I had to disable the lid closed sensor by removing the magnet from screen section of the case

# minimal brightness
echo 0 > /sys/devices/platform/eeepc/backlight/eeepc/brightness"
# screen off after 2 minutes
xset dpms 0 0 120

eeePC problems

  • unionfs inode depletion causing "No space left on device" but df shows plenty of space!
  • running out of space due to other errors ~/.Xsession-errors
  • firefox won't start - oh well!

eeePC Software

  • console read and process
  • speech module
    • speech commands from stdin
    • speech thread - busy flag and job queue management
  • motor module
    • motor control input from STDIN
  • sensor module
    • camera module - look at Java interaction with V4L or whatever is in use
    • mic input - and speech recognition
    • GUI interface port and GUI app

One annoyance is having to open the eeePC to find out its IP address to get back in via SSH. My proposed solution is to display the eeePC wlan IP address on the LCD on MCU2.

Get IP address to report on LCD

package com.tecspy.util;

import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class NetUtils {
    static Logger log = Logger.getLogger(NetUtils.class);
    
    public static String getIps() {
        
        StringBuilder buf = new StringBuilder();
        char div = '|';
        
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            NetworkInterface ni = NetworkInterface.getByInetAddress(localHost);
            Enumeration<InetAddress> ia = ni.getInetAddresses();
            while (ia.hasMoreElements()) {
                InetAddress el = ia.nextElement();
                buf.append(div);
                if (el instanceof Inet6Address) {
                    buf.append("IPv6:");
                } else {
                    buf.append("IPv4:");
                }
                buf.append(" hostname:");
                buf.append(el.getCanonicalHostName());
                buf.append(" address:");
                buf.append(el.getHostAddress());
            }
        } catch (NullPointerException e) {
            log.error("Error: " + e.getMessage(), e);
        } catch (SocketException e) {
            log.error("Error: " + e.getMessage(), e);
        } catch (UnknownHostException e) {
            log.error("Error: " + e.getMessage(), e);
        }
        return buf.substring(1);
    }
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        BasicConfigurator.configure();
        String ips = getIps();
        log.info(ips);
        
    }
    
}

Additionally I'll make use of some of my remote servers to track IP addresses posted by cheesoid...

Additional

Range Sensors

Rotary Encoders for wheels

  • an easily available "obsolete" ball type PS/2 mouse
  • Microsoft "Mouse Port Compatible Mouse 2.0A"
  • using the serial output from the mouse circuitry
  • encoder usage in daylight
  • mounting encoder wheel to axle