Zyphht! Robot World

October 29, 2010

More Arduino code.

Filed under: Uncategorized — admin @ 3:35 pm

I’m really getting to like this arduino..

Want to control a motor? Read a temperature sensor? Know where you are in the world?  Build a robot? Open/Close a door? buld a Christmas display worthy of a CNN segment?

Grab an arduino, spend something like 10 minutes in research and go build it. It is an amazing little tinker-toy.

I’m working on a little autonomous ‘bot that will have as it’s brain, an arduino Duelimanove. It will be mobile, tracked, contain a 7 seperate sensors, 3 motors, a built in video screen, a camera, and wireless internet connectivity. All based on a single, $29.00, processor that can be programmed with very little programming skill.

Think about that for a minute… As a guy that worked with Basic Stamps for years, controlling 7 separate sensors on one tiny little pic is….. well, it’s pretty cool, in a geeky way. Add motors, wireless, cameras, motors, etc., and you are in a realm where you needed (at best) a full-blown laptop a couple of years ago.

Now, couple that with open-source development and the ability to simply go online to find code examples for your needs, and you are opening the world of robotics, controllers, animatronics and anything else you can imagine to anyone with an internet connection and the ability to read. I’m completely geeked-out to see what comes of this little controller in the next several years!

OK – off of the soapbox; lets look at a little sample code: (controlling a motorized platform)

One thing to note: The ArduMoto controller comes in two versions, one that uses Pin 10 and one that uses Pin 3. The earlier version (uses Pin 10)  interferes with servos (which also need pin 10) and may need a modification if you intend to use servos with it. (I’ll actually discuss this mod in my next post) In the case of this application, I don’t need any servos, so pin 10 is fine as is.

The following code allows you to drive two seperate motors, controlling speed and direction, which will allow you to drive a bot base in any direction.

/*
v.2.0 Jerry Parker
piggy back the ArduMoto on top of the Arduino.

Connect a power supply to the Power connector. and hook up a dc motor to pins
1 and 2, and pins 3 and 4 on the OUTPUT of the ArduMoto. No other conenctions are necessary

Enter 1,2,3,4,5,6,7,8,9 for Speed setting (1 = LOW, 5=MED, 9=HIGH)
then enter motor Control Character
Q-W-E          Forward Left – Forward – Forward Right
A-S-D          Rotate Left – ALL STOP – Rotate Right
Z-X-C          Reverse Left – Reverse – Reverse Right
*/

// defines for ArduMoto
#define MotorAPin 10
#define MotorBPin 11
#define MotorADirection 12
#define MotorBDirection 13

// variables needed by the sketch
int Command;            // raw user input
int MotorSpeed = 0; //set speed to LOW
//use the following setting to balance your motor speed when turning (drifting) left or right

float InsideMotorSpeedAdjust = .5;

void setup()
{
// motor pins must be outputs
pinMode(MotorAPin, OUTPUT);
pinMode(MotorBPin, OUTPUT);
pinMode(MotorADirection, OUTPUT);
pinMode(MotorBDirection, OUTPUT);
Serial.begin(9600);   //Start serial console
HelpMenu();              // and display the menu
}

void loop(){
// wait for serial input
Command = 0;
if (Serial.available() > 0) {  //Wait for Serial port to come ready
Command = Serial.read();   //read incoming byte
// Read a character from the serial port, and act accordingly.
// Characters read in this way come in as ints, and need to be converted to their ascii equivalent.
// there is a great Arduino character chart here:
// http://www.arduino.cc/en/Reference/ASCIIchart
if (Command == 63) {      // entered “?”, show menu
HelpMenu();
}
if (Command == 49) {      // entered 1; SPEED 10%
MotorSpeed=25;
}
if (Command == 50) {      // entered 2; Speed 20%
MotorSpeed=51;
}
if (Command == 51) {      // entered 3; Speed 30%
MotorSpeed=76;
}
if (Command == 52) {      // entered 4; Speed 40%
MotorSpeed=102;
}
if (Command == 53) {      // entered 5; Speed 50%
MotorSpeed=127;
}
if (Command == 54) {      // entered 6; Speed 60%
MotorSpeed=153;
}
if (Command == 55) {      // entered 7; Speed 70%
MotorSpeed=178;
}
if (Command == 56) {      // entered 8; Speed 80%
MotorSpeed=204;
}
if (Command == 57) {      // entered 9; Speed 90%
MotorSpeed=229;
}
if (Command == 48) {      // entered 0; Speed 100%
MotorSpeed=255;
}
// Following are the MOVE commands
if (Command == 83) {      // entered S; Stop All
ProcessCommand(0);
}
if (Command == 81) {      // entered Q; Left Forward
ProcessCommand(1);
}
if (Command == 87) {      // entered W; Forward
ProcessCommand(2);
}
if (Command == 69) {      // entered E; Forward RIGHT
ProcessCommand(3);
}
if (Command == 65) {      // entered A; Rotate Left
ProcessCommand(4);
}
if (Command == 68) {      // entered D; Rotate Right
ProcessCommand(5);
}
if (Command == 90) {      // entered Z; Reverse Left
ProcessCommand(6);
}
if (Command == 88) {      // entered X; Reverse
ProcessCommand(7);
}
if (Command == 67) {      // entered C; Reverse Right
ProcessCommand(8);
}
}
}

// process a command string
void ProcessCommand(int Command) {
Serial.print(“Speed: “);
Serial.println(MotorSpeed);
// check commands
switch(Command) {
case 0:
//all stop
Serial.println(“All Stop”);
analogWrite(MotorAPin, 0);
analogWrite(MotorBPin, 0);
break;
case 1:
Serial.println(“FORWARD LEFT”);
analogWrite(MotorAPin, (MotorSpeed));
digitalWrite(MotorADirection, LOW);
analogWrite(MotorBPin, (MotorSpeed*InsideMotorSpeedAdjust));
digitalWrite(MotorBDirection, HIGH);
break;
case 2:
Serial.println(“FORWARD”);
analogWrite(MotorAPin, (MotorSpeed));
digitalWrite(MotorADirection, LOW);
analogWrite(MotorBPin, (MotorSpeed));
digitalWrite(MotorBDirection, HIGH);
break;
case 3:
Serial.println(“FORWARD RIGHT”);
analogWrite(MotorAPin, (MotorSpeed*InsideMotorSpeedAdjust));
digitalWrite(MotorADirection, LOW);
analogWrite(MotorBPin, (MotorSpeed));
digitalWrite(MotorBDirection, HIGH);
break;
case 4:
Serial.println(“Rotate LEFT”);
analogWrite(MotorAPin, (MotorSpeed));
digitalWrite(MotorADirection, LOW);
analogWrite(MotorBPin, (MotorSpeed));
digitalWrite(MotorBDirection, LOW);
break;
case 5:
Serial.println(“Rotate RIGHT”);
analogWrite(MotorAPin, (MotorSpeed));
digitalWrite(MotorADirection, HIGH);
analogWrite(MotorBPin, (MotorSpeed));
digitalWrite(MotorBDirection, HIGH);
break;
case 6:
Serial.println(“REVERSE LEFT”);
analogWrite(MotorAPin, (MotorSpeed));
digitalWrite(MotorADirection, HIGH);
analogWrite(MotorBPin, (MotorSpeed*InsideMotorSpeedAdjust));
digitalWrite(MotorBDirection, LOW);
break;
case 7:
Serial.println(“REVERSE”);
analogWrite(MotorAPin, (MotorSpeed));
digitalWrite(MotorADirection, HIGH);
analogWrite(MotorBPin, (MotorSpeed));
digitalWrite(MotorBDirection, LOW);
break;
case 8:
Serial.println(“REVERSE RIGHT”);
analogWrite(MotorAPin, (MotorSpeed*InsideMotorSpeedAdjust));
digitalWrite(MotorADirection, HIGH);
analogWrite(MotorBPin, (MotorSpeed));
digitalWrite(MotorBDirection, LOW);
break;
}
}

void HelpMenu() {
Serial.println(“Arduino MINI_BOT Robot Controller V2.0 by Jerry Parker”);
Serial.println(“Menu. Enter letter to execute”);
Serial.println(“? – Help Menu”);
Serial.println(“—-Motor Commands—-”);
Serial.println(“1-0 – Motor Speed in percent (0=100)”);
Serial.println(“Q-W-E – Forward LEft – Forward – Forward Right”);
Serial.println(“A-S-D – Rotate Left – STOP – Rotate Right”);
Serial.println(“Z-X-C – Rev Left – Reverse – Rev Right”);
}

October 20, 2010

A new robot Project!

Filed under: Uncategorized — admin @ 5:05 pm

I’ve teamed up with Zagros Robotics (www.zagrosrobotics.com) to create a new robot application on the Arduino Platform. Check out their bbs for more info @ www.zagrosrobotics.com/bbs

I’ll be posting bits and pieces of the work here, as this platform is built, so check back for source code and assembly tips and the like!

March 11, 2010

Using the Arduino vs Basic Stamp

Filed under: Uncategorized — Tags: , , , — admin @ 5:00 am

Ok – I admit it, I’m a bit late to this Arduino thing. I’ve been using Parallax Basic Stamps for years to do little projects. It’s been an invaluable tool. I’ve built controllers of all sorts using it, from sensor controllers to LED sequencers to, well, everything in between. The basic stamp is quite a little controller. So, I was a little slow to pick up the Arduino. It was like my favorite sneakers. Comfortable, well suited to me. I didn’t need the learning curve associated with the Arduino, because I could do all the stuff it did using stamps.

Well, Move Over, Stamp-Boy….. There’s a new kid in town.

I picked up a couple Arduinos (25 bucks… Are you kidding me?), and decided to bite the bullet and see what all the fuss was about. I had built a sonar ranger using a servo and an SRF08 ranging sensor using the stamp, so I thought I’d spend some time duplicating it on the Arduino.

To illustrate the differences, lets look at a servo move program on the stamp:

#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
T1200       CON     813
T2400       CON     396
T9600       CON     84
T19K2       CON     32
T38K4       CON     6
#CASE BS2SX, BS2P
T1200       CON     2063
T2400       CON     1021
T9600       CON     240
T19K2       CON     110
T38K4       CON     45
#CASE BS2PX
T1200       CON     3313
T2400       CON     1646
T9600       CON     396
T19K2       CON     188
T38K4       CON     84
#ENDSELECT
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     T9600 + Inverted
‘ Above is a standard Basic Stamp Header,
‘ I use these in all code, allows use across all stamp models
PanServo PIN 14
TiltServo PIN 15
LOW PanServo
LOW TiltServo
‘Move Servo’s all the way to one extreme

FOR T = 1 1 to 100
FOR i = 0 to 20
PULSEOUT TiltServo, 300
PULSEOUT PanServo, 300
PAUSE 18
NEXT
PAUSE 1000 ‘wait one second
‘Move to other extreme
FOR i = 0 to 20
PULSEOUT TiltServo, 1200
PULSEOUT PanServo, 1200
PAUSE 18
NEXT
NEXT

Phew…. That’s a mouthful, but it’s not so bad when you look at it.. Basically, the code is initilaized, then simply using the PULSEOUT command to send a sting of pulses to move the servo to the desired position. I’m not going to pick this code apart here, it’s pretty well commented and you should follow it pretty easily. It’s not pretty, or elegant, but it works, and it shows you what you need to do.

Now lets contrast that to the Arduino.

#include <Servo.h>

Servo panServo;   // create servo object to control Pan Servo
Servo tiltServo;  // create servo object to control Tilt servo
void setup {
Wire.begin(); // setup IC2 serial Interface for other sensors
panServo.attach(8); // attached pan servo to pin 8
tiltServo.attach(9); // attached tilt servo to pin 9
}
void loop {
panServo.write(0);
tiltServo.write(0);
delay (1000);
panServo.write(180);
tiltServo.write(180);
delay(1000);
}

Quite a difference in code, but both do the same thing; simply move servos from one position extreme to the other. Two things strike me with the Arduino Code set:It’s simpler to read, and it’s shorter. To be fair, a LOT of work is done on the include file Servo.H, but programming is very simple. Move a servo to a position (in degrees) between 1 and 180. On the Stamp, you have to actually determine the PWM timing (note the positional statements 300 and 1200). These correspond to the pulse widths. I find it much easier to say “Servo, Move to 45 degrees” then to have to figure out the math to determine that I want to send a string of pulses created by the PULSEOUT (750) command. In fact, I never actually *do* the math. I always use trial and error, or simply incrementally move the servo by changing the value of the PULSEOUT command in code. There are lots of references out there to help you determine the actual values of the PULSEOUT argument, google it and you’ll see them.
For me, however, I’m converting 100% of my servo needs to Arduino.
Not just for servos, either. Check Back….I’ll post a whole block of code up here where you can see how ONE Arduino is controlling Pan/Tilt, Ranging, Compass, GPS, and a slew of other stuff, too!

March 10, 2010

Welcome to the new Blog

Filed under: Uncategorized — admin @ 11:38 pm

Hi Everyone.

Managing all the information about the bits-n-pieces of Zyphht Construction was getting to be downright unruly, so I’ve decided to switch to this format instead.

Here you’ll find general discussions on code, devices, systems, subsystems, parts, pains, triumphs, and just about anything else I think you might like to read about. I’ve done a lot of work on Zyphht, and an interested in sharing with you all so that you might share with me some of your ideas.

To Date, I’ve added to Zyphht:

  • remote control from the web – you can view live video, pan and tilt the camera, and even drive Zyphht around the place exploring. (as long as I have the main drive enabled)
  • Sensors, including Compass, GPS, Sonar (x3), Light Sensor, accelerometer and tilt sensors
  • Arduno (2 of them) – Man, I like these, I’ll share the reasons why in another post, but for now – go get one!!!!
  • a rudimentary arm (this is VERY rudimantary)

Things still to do:

  • Update the web page to give better feedback from the platform
  • Build an entirely new software package giving realtime control
  • built the sub-bot (more on this later)
  • More work on the Arduino control software
  • replace the HC11 system with yet another arduino
  • build the robot chassis from aluminum stock
  • implement more visual functions, such as mappng and nagivating through a room
  • and more!

Zyphht is an experimental platform, so things change. features and functions that are up today could be completely removed tomorrow, and replaced with something entrely different.

If you are interested in the remote control page, look here. I’ll require registration, but I won’t use your for anything other than to track your behavior with the ‘bot, and to enable/disable any abusers. Zyphht tells me when you connect, so please be respectful.

Powered by WordPress