Thursday, June 21, 2012

A start to my Arduino-based robot controller

Utilizes a Solarbotics Freeduino, Parallax backlit 2x16 serial LCD w/ Speaker, a pair of Sparkfun XBee breakout boards w/ 1  mW XBee pair, and a Pololu mini Maestro servo controller. Basic functionality so far. Read wirelessly from Xbee connected serial terminal, print to LCD and back to terminal, and sending commands to the servos.


//RoboCon v.4a
// www.parallax.com (part #27977-RT)
// June/16/2012 Arduino ver: 023
// M. Ramirez "mannyr7" on Trossen Robotics forum
int i=0;


#include <NewSoftSerial.h>
NewSoftSerial maestroSerial(7, 5); 
// yellow wire Arduino tx to Mestro rx
// blue wire Arduino rx to Maestro tx
                                   
NewSoftSerial LCD(1, 2);
// second variable defines the tx pin to the LCD


NewSoftSerial xBee(3, 4); 
// yellow wire Arduino tx to Xbee rx
// green wire Arduino rx to Xbee tx                              


void setup()  
{
  LCD.begin(9600);  
// LCD dip switches set to 1=OFF, 2=ON for 9600 baud


  delay(100); // suggested delay from Parallax
  
  LCD.write(0x0C); // Clear display, move cursor to top-left
  LCD.write(0x19); // Display on, cursor on, char blink
  LCD.write(0x11); // LCD backlight on
  LCD.print("Arduino active");
  delay(1000);
  LCD.write(0x0C); // Clear display, move cursor to top-left
  LCD.print("LCD ready"); 
  delay(1000);
  
  xBee.begin(38400);
  delay(1000); //wait for xbees to pair up
  LCD.write(0x0C); // Clear display, move cursor to top-left
  LCD.print("Xbees paired");  


  maestroSerial.begin(9600);
  delay(1000); 
  settarget(0, 0); // servo port #, position in degrees
  settarget(1, 0);
  settarget(2, 0);
  delay(1000);
  settarget(0, 180);
  settarget(1, 180);
  settarget(2, 180);
  delay(1000);
  settarget(0, 90);
  settarget(1, 90);
  settarget(2, 90);  
  
  LCD.write(0x0C); // Clear display, move cursor to top-left
  LCD.print("Servos ready"); 
  
  // Play "Charge!!!"
  LCD.write(0xD2); // set note length to 1/16 note
  LCD.write(0xE6); // G note
  LCD.write(0xDF); // C note
  LCD.write(0xD3); // set note length to 1/8 note
  LCD.write(0xE3); // E note
  LCD.write(0xD4); // set note length to 1/4 note
  LCD.write(0xE6); // G note
  LCD.write(0xD3); // set note length to 1/8 note
  LCD.write(0xE3); // E note
  LCD.write(0xD5); // set note length to whole note
  LCD.write(0xE6); // G note
  
  delay(1000);
  LCD.write(0x0C); // Clear display, move cursor to top-left
  LCD.print("RoboCon v.4a"); 
}
void loop() // listen for keyboard and print to LCD and serial window
{
  char string='/0';
  xBee.listen();
  if (xBee.available())  
  {
    char c = xBee.read();
    LCD.write(0x0C); // Clear display, move cursor to top-left   
    LCD.println(c);
    xBee.println(c);
    i=0;
    delay(1000);
  }
  else
    {
    LCD.write(0x0C); // Clear display, move cursor to top-left      
    LCD.print(i+=1);
    delay(1000);
    }
}


//Send a Set Target command to the Maestro.
//Target is in units of quarter microseconds,
// so the normal range is 4000 to 8000.
void settarget(unsigned char servo, unsigned int target)
{
  target = map(target, 0, 180, 2400, 9500);
  maestroSerial.print(0xAA,BYTE); //start byte
  maestroSerial.print(0x0C,BYTE) ; //device id
  maestroSerial.print(0x04,BYTE); //command number
  maestroSerial.print(servo,BYTE); //servo number
  maestroSerial.print(target & 0x7F, BYTE);
//  LCD.print(target & 0x7F, BYTE);  
  maestroSerial.print((target >> 7) & 0x7F,BYTE);
//  LCD.print((target >> 7) & 0x7F,BYTE);  
}

Tuesday, September 6, 2011

More Chumby Hacks (Insignia Infocast)

I used Ultra Voice Changer, an Android app, to record some audio and alter it using the built-in robot filter preset. The alien presets are pretty cool too. Alternatively, you could use a text to speech website from AT&T Labs to generate some nice vocals for your Chumby. I plan to use these .wav files to indicate startup, shutdown, and a few other status changes. I saved mine in mono at 11 kHz to save on space. I then transferred my audio files by usb stick to the Chumby and placed them in a directory I made at /mnt/storage/sounds/ From there it's simply a matter of calling
aplay /mnt/storage/sounds/robotmode.wav
to call up our .wav files. If you prefer .mp3 format, use btplay instead.

Saturday, September 3, 2011

Chumby Hacks (Insignia Infocast)

First off, I could not ssh into my device from Putty or any other remote terminal as described in the Chumby Tricks wiki. So, I attached a USB keyboard to the Infocast, which automatically puts it in terminal mode. Then, I typed:
mount -o remount,rw /
putting the root filesystem into read,write mode.
Next, type:
passwd root
to create a root password. Enter it twice as prompted, then you should be able to ssh in remotely.
Unplug your keyboard and ssh into it from a remote computer!

Successfully connected? You should see the chumby logo in ASCII art.

Next, we'll have the sshd server always start upon bootup.
From your remote terminal app of choice, type:
touch /psp/start_sshd
That's all there is to it!


Following the directions at adafruit, I next installed the falconwing gcc toolchain. So far, so good!

Using directions from this page, install python! Here's how to install it: 

cd /mnt/storage 
wget http://files.chumby.com/languages/python/python2.6-­chumby.tgz 
tar -­xzf python2.6-­chumby.tgz 
python --­­help 

Great! Now I have all the programming environments necessary for more robotic tinkering in the near future.

Adventures in ChumbyLand!

Hello again! Been a long time since my last blog post, but I have been busy!
     This summer, I finally got around to hacking my Insignia Infocast 3.5", now discontinued :-( which I picked up after Christmas for $49. I made a lot of tweeks and hacks to it, to make it the brains of my next robot. Unfortunately, I went a little too far editing the boot sequence and bricked it! Being a dummy, I didn't back up the sdcard rom before messing with the device. But after much searching, I found the OEM rom image and a control panel update to my relief. BTW, a standard Chumby Industries falconwing nor a Adafruit Chumby Hacker Board rom image will work on the Infocast 3.5".
     So now I have it back up again, to factory original! This time I backed up the rom image, update.tgz, and will document all the hacks I do, in case I screw things up again!

Wednesday, May 11, 2011

Oh Noooooo!!!!!


I would hold off on that Rennbotics servo shield for now. I think I burned $1000 worth of servos connected to it! All servos were digital Hitec HS-5990tg and HS-7954sh with 6V pack as the supply and groung plugs confirmed. Prior to connecting them all, I verified operation via a Turnigy servo tester using the same 6V pack. While connected to the Freeduino via USB to my PC, they responded somewhat to commands from the keyboard but twitched and never realized full speed or range of motion. After disconnecting, I retested using the servo tester and saw mass failure! Some moved sluggishly and some not at all. I ordered a Hitech HPP-20 servo programmer in the faintest hope that maybe a board reset may be possible.

TWO WEEKS LATER.....


Some good news: 
Using a Hitec HP-20 servo programmer, I managed to revive all the digital servos and even the analog 645MG's! While I was at it, I turned on protection, which will halve the motors output in the event of a stalled situation and enabled 180 deg rotation instead of the as-shipped 60 degrees. Best $26 I ever spent!

Going through the old threads regarding PLM designs. I have settled on one easy enough for me to hack together in the garage using the basic hand tools at my disposal. So here's what I'm shooting for. The 45 deg brackets are Lynxmotion SES offset brackets I plan to drill holes into to allow attachment of the parallel link. I have not yet decided if the twin knee servos will be necessary as I am using HS-5990TG's for the upper and lower links.

Monday, April 25, 2011

Controlling a Picoswitch with Arduino

I had a viewer of my Youtube channel request the code accompanying this video. I made this video a long time back because I wanted to trigger a battery-powered airsoft gun from my robot. The Picoswitch is a solid state relay that works with pulse width modulation, same as a standard hobby servo. What this means is, you can supply power to the switch, and a load, such as an electric motor and you can toggle off and on any device up to 1 Amp from a standard R/C radio or microcontroller. If you need more current flow, try Dimension Engineering's Battleswitch. I know, the code says servo, but treat it exactly the same and it works.
Here ya go!

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int pulse; // variable to show pulse width
void setup()
{
Serial.begin(9600); // begins serial communication with the computer
myservo.attach(12); // attaches the servo on pin 12 to the servo object
}
void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
pulse = map(val, 0, 179, 750, 2250); // get a pulse width for current pot position
myservo.write(val); // sets the servo position according to the scaled value
Serial.print("degrees ");
Serial.print(val);
Serial.print(" pulse" );
Serial.println(pulse);
delay(15); // waits for the servo to get there
}

Friday, April 22, 2011

New Humanoid

I have 16 servos, 4 x HSR-5990TG, 6 HS-7954SH, and 6 HS-645MG. Brains will be provided by a SolarBotics Freeduino and Rennbotics servo shield supporting 16 servos. Both will be stuffed into a Freeduino project box with 9V cell providing juice for the Freeduino and a Tenergy 6V 2000 mAh pack for the servos. Control will be via Arbotix commander gamepad over Xbee to the Freeduino.

Hardware will be lasercut, .063" 5052 aluminum and possibly nylon block for servo mounts. The leg design will be a 4 DOF PLM layout, with a servo in each of the hip and ankle tilt locations and one more servo in each of the hip and ankle lift positions. None in the knee area, this is where the parallel links will attach. I will reserve one more servo for the hip rotate if needed. The torso will be solidly mounted to the lower body, meaning no waist rotate. The head will have no pan or tilt either.
For the feet, I have these beautifully machined delrin feet from "Quantum" over on the Trossen Robotics forum.



They are perfectly smooth and rigid, and should provide the perfect balance between traction and glide I'm looking for.  :-)

Here is the head I plan on using. Its a gear shift knob found in the automotive aisle of my local bigbox store.



For this build, I plan to add some sensory for autonomous events. I will mount a Maxbotics EZ1 sonar, Sharp GP2D12 IR, and tilt sensors to automatically trigger getup sequences.

As for project name, I am still undecided. I was leaning toward something military sounding like Corporal Punishment or Major Malfunction, just not Sgt Slaughter (been done already). Any ideas?