Tuesday, July 19, 2016

vision - and the rest of the plan for upcoming days/weeks

my pi now has an eye!

the camera noir is connected up and ready to help navigate the land.  Once I have the room on the sd card, I'll be trying to install opencv 3 and seeing if I can get the camera to recognize when there is any face visible.  Shouldn't be too hard.

the following stage of opencv development will be finding facial recognition clues and adding them to a db, hopefully autonomously, but worst case I do it by hand.  Then it's time to address people by name.

"Speaking" of names, before I totalled my raspbian install, I had installed, supposedly successfully, the node modules to handle speech to text using a gui-less stub of the chromium environment.  However it didn't get the change to find out of it worked before I killed the os.  Initial attempts failed, but I hardly started diagnosing things when it went wrong.

So, order of priority:
- play with neato bot a bit to ensure it works reliably
- quickly try connecting current (borked) pi raspbian install to neato xv via mini usb and see if I can control or at least read info from the bot using python.
- further steps include:

  • format sd card
  • install rapsbian lite (only, no xwindows needed currently on bot)
  • update os thoroughly
  • set static ip and ensure I can ssh
  • BACKUP SD CARD
  • disable default audio hardware
  • install new usb audio device and make sure it boots to it consistently
  • install node 5
  • BACKUP SD CARD
  • get camera working
  • install the node module for the ultrasonic sr04 sensor (I'll still need this, and it also ensures I haven't missed anything along the way to get this all working, such as gpio)
  • try to remember what node serial module I installed that worked (go through my code...)
  • get that serial module running since I will likely need it eventually
  • try to talk to Neato from node... focus on this for as long as it takes until it works
  • try to get Speech to Text working in node
  • BACKUP SD CARD
  • If all of this is good so far, we have some serious stuff ready to do!
  • try to implement wavefront.js stuff I wrote into a meaningful, working robot mapping system using LiDAR data for basic angles
  • try to turn robot 90 degrees and move correct distance to match invisible grid of the wavefront map
  • get voice control to tell it what to do (go to room a, room b, room c, with designated targets in each room (for now))
  • install chatbot that integrates with these voice controls when asked
  • get female good quality voice output to respond to everything

Roombas are strong and have robust connectivity, but are dumb and blind

Enter.... the Neato XV series robotic vacuum!

I grabbed one super cheap and will sell my parts roomba to make up the price.  This Neato xv-11 works perfectly, apparently, I saw it running.  It has usb port, current-ish firmware (3.2), later revision board (64?), and decent battery.

So time to use a smarter base for my bot.  LiDAR will be vital to my navigation, and the motors in the Neato are geared, not belt driven, and have encoders to return distance travelled and hopefully are more accurate than the roomba motors.

Nice side bonus - there is an accelerate setting for the motors.

So I'll be trying to connect my pi to this (using mini-usb cable) to see if I can run it from python.  I have python script already to control it if everything works right, just to test.

If it DOES work, I'll start my node wavefront code move to neato instead of roomba control.

This should be a fun change!

Pi problems : noobs, raspbian(linux) permissions, sdcard partitions... etc

So I hosed my raspbian jessie install yesterday.  What happens when you get tired of having to sudo your node execution all the time?  you do stupid, sloppy things to your permissions.

I, unfortunately, did stupid, sloppy things to not only permissions but file ownership... in /usr/bin hahaha

oops

so now sudo no longer works, and there is no simple way to fix this, possibly no way at all.

But ya know what?  that's fine :-)


  • I backed up my /home/pi folder (several hundred megs!!) to my macbook through ftp, so I have all my source code.
  • Noobs was how I installed in the first place, and it's stupid partition structure prevents me from expanding my main partition on my larger sd card.  My sd card can't be mounted read/write on my macbook booting into linux running gparted (phew!) for some unknown but apparently common reason, so I can't solve the problem.
  • So the sd card will be formatted, partitions removed, and a lite raspbian jessie image will be installed and will take up all 16gb :-)

Then I just have the fun of setting it up again from scratch, ensuring my ssh goes to that ip, oh yea, setting static ip, setting up servers for remote everything, installing node 5 and getting it to run, setting up a working audio interface (this one is nutso hard and unstable from my experience), ...

... and then I will copy back my source code, and return to my project.

Hopefully will be solved tonight, but might take another extra day or two.

Monday, July 11, 2016

Roomba plus sr04 motion control autonomy V1

In brief. .. check it out.  



This code was my own creation in Python . ... a language which i really dislike now.

Currently trying to learn how to do serial port stuff in Node JS so i can port the working Py Roomba library to JavasScript. ... so far all node Roomba libraries don't work with my Roomba or have requirements that don't build in my Arm 7 version of Node.  Fun (not!)

This will be a slow progress time while I learn Node's module system, hardware communication system, and other architecture.

Fortunately I'm primarily a JavaScript developer by day and have been for many eons, so once I get the Node specific oddities working, I'll start making great progress.

Event driven logic is ideal for robotics and I'll be able to focus on this advantage of JS.

Friday, July 8, 2016

Ultrasonic distance and a Pi...

Looking around itself... well, at least like a bat might!



I had stuff lying around, partly from old robotics experiments, partly from gifts from friends/coworkers, and partly because I bought them to build this robot.

This sensor is one of the latter - spent literally pocket change to get a 4 pin SR04 ultrasonic range finder.  It pings a series of sounds at 40k and waits to hear them back, you measure time difference and do the math knowing speed of sound (at water level etc).

I've used something similar to this in the past (back around 1998!) in a robot, so know it can work quite well, however I know a lot more now than I did then.  Also, I'm not using a stamp micro controller as a brain any more... the RPi is a ridiculous improvement in computing power.

So yea, this sensor is meant for 5v use, the pi GPIO is 3.3volt, so I built a resistor voltage divider.  I went through my bag of resistors looking for suitable color codes, found 3 (two are in series to make the lower resistance needed), and voila, my 5v output echo pin from the SR04 now returns 3.3v (3.2, really) to the PI GPIO.

I wired it up but had to go to work, so I Puttied in from the office at lunch to see if I could get a measurement.

Initial code was in python, but I am growing rapidly to despise the language so instead used node.js to do this in the code I know best - JavaScript.

I can now loop (without holding up the cpu cycles, like in python....) over a call to the sensor and get the distance....



.... from the rear of the roomba.

Why the rear?  Because I just left it sitting on a tiny breadboard (with resistor network) pointing into my living room at home while the robot is parked on it's dock, facing the wall (under my low mantel).

I wanted something other than 3cm readings constantly, figured this would be more fun.  well, it's not.  But I do have something coming back from it:


I made a little ascii bar chart to help with visuals.

that runs 10 times per second right now (I set it for that frequency).

the most common distance around 390cm makes sense... should be that far to the couch across the room.

regular half distance measurements are interesting... maybe something small on floor it's hitting, maybe edge of the throw rug is actually being returned at times (it's a shag so has some height).  Who knows.

once in a while it doesn't find anything, and I set it to say ERR and the actual number in cm (which is infinite fallback in the sensor) if that happens.  Not sure why it happens, but it does.  maybe won't happen with more close up stuff.

Now I will have to "debounce" this output in the actual robot or it will behave erratically... erm, more erratically than necessary ;-)

if I run this multiple times per second and it sees something close once then it's gone again, the robot could ignore it possibly, or maybe slow down briefly to make sure it's done before speeding up.

If it gets no result back it should treat that as acceleration to full speed but not instant jump to full speed, ya know?  in case it's reading 10cm 10cm 10cm 3380cm, it shouldn't go 5% speed 5% speeed 5% speed 110% speed instantly LoL.

So yes, that is one point to think about in my next coding exercise - I must remember to accelerate smoothly up to a speed and down to a speed, not instantly, unless it sees an obstacle suddenly that lasts more than 1 test in a row.  2 in a row?  slow down FAST.  3 in a row?  STOP!!  or something like that.

So.... the next coding exercise is.....

To put the sensor on front and make this thing start to run around my house without hitting anything, choosing random directions (for now).

- needs to move forward if nothing in it's way.
- needs to turn one way or another about 90 degrees if something in it's way.
- needs to accelerate and decelerate smoothly respecting general ideas I pointed out above
- needs to read the bump sensor in the roomba and respect that as instant stop followed by normal turn and retest code of mine.

Basic autonomy.... This will be tonight/tomorrow morning!

Thursday, July 7, 2016

An old Roomba, an RPi 3, some history, and the birth of an idea

Ok, let's be honest!  

Who has NOT dreamed of building an intelligent, autonomous robot friend/servant?  

If you have had that dream, then you're in the right place!

I'm finally making my dream come true.

Why now?  in my 40s?

- I'm an experienced software developer by day, which will help a lot
- There are finally robots in the used market that can take us part of the way there, without any modifications (Roombas, Neatos, Braava/Mints, RoboMows, Mirras)
- Computing power has gotten cheap, fast, low voltage/current, solid state (Raspberry Pi, Arduino)
- Computing code has become free and easy to get access to (Open Source, GitHub, Web)
- Information and Education has become free and easy to get access to (Instructables, ebooks, web)

What does that bring me?

  • Roomba:  old, works fine, has SCI serial port for controlling in real time.
    • Source: Craigslist: Roomba discovery, $50, came with almost new replacement battery and claim of working perfectly, and dock/charger.  at first I wasn't convinced it worked, but with some minor fixes/updates and reset of charging state/battery, it honestly does work perfectly!  got a 2nd one for a speck more that needs a battery but has the virtual walls, another dock/charger, etc, needed more physical work but works fine now.  just need battery for it.  one for vacuuming, one for robot, or one for replacement parts for robot possibly.
  • Raspberry Pi 3: new, with case, power supply, card, etc from various sources
    • Source: Amazon, case and card from local stores. Gift from my wife (I love her!)
  • SCI to usb cable: custom made, from plans on net, to connect computer to Roomba
    • Source: internet info (lots of it), 8 pin minidin plug for roomba from local electronics parts store, usb-ttl(serial) converter from local craigslist seller of arduino type parts
  • 5v regulator to power RPi off Roomba battery: car usb cell phone charger for lighter socket
    • Source: my car.  had one I hardly use.  Original source, Save On Foods, $6, cheap junk that contains a switching 5v regulator, mini transformer, well put together.  tested other options including a 5v regulator board for this purpose but it wasn't regulated so couldn't deliver the goods despite specs claiming it could.  Pi wouldn't run reliably.  This cheapo car charger works as well as the ac 2Amp psu I was using before.
  • Remote control of Pi to program it without needing dedicated hardware
    • Source: my macbook, my work pc, anything.  the Pi is on internet, has permanent access remotely through freely available interfacing apps/software/tools.  Microsoft remote desktop is used on laptop to control the pi.  works great. Graphical Raspbian (debian for pi) gui is easy to use, or you could go low level with putty if you prefer.
  • Code to run the Roomba from the RPi
    • Source: open source (pyrobot2.py library for python), and my own code file which includes pyrobot2 and actually handles the control logic and main loop.  When I get a nice short demo script prepared with comments I will post it here.
Result of this?  it cost me, personally (due to gifts etc), $50 for roomba, $4.50 for mini din connector, $4 for usb/ttl converter, $6 for case for pi.  Rest of it I had lying around or were gifts.



I mentioned the "Birth of an Idea" in the title of this blog post....  Well here it is.   

What if I...
  • Can make a robot that knows it's way around my house and can go to any specific room on command?
  • Can make that robot respond to voice control?
  • Can make that robot respond verbally to us?
  • Can make that robot carry things?  Snacks, drinks?  Garbage?
  • Can make that robot automatically charge itself and keep itself charged forever?
  • Can make that robot perform scheduled tasks that I don't like to do or forget to do?
  • Can make that robot have a personality and verbal interaction good enough to converse with?
  • Can make that robot answer the phone, take messages, let us know who called?
  • Can identify who is facing it and talking to it?
  • Can answer the door (verbally only with door closed, for safety, to find out who it is, who they want to see, and then confirm with resident if they want to answer door?)
  • Can take photos and video of a moment on demand while focusing on the action, then uploading to cloud?
  • Teach family members answers from internet when asked?
What if?  Is any of that possible?  Do YOU think it is possible?

I THINK IT IS POSSIBLE.

Some of it I have experimented with enough to know that it is possible.  Other things I have tried and partially failed, previously.

With this series of blog posts, I intend to track the progress of my robotic project(s) to see how far I can get through these types of ideas.

This may take a while....