Society of Robots: the book

So far the book will be a book of algorithms . People will write articles and submit them to me or perhaps to another person who is willing to join me in the publication of this book.

If the articles are acceptable then they will make their way into this book.

 


It will first be a free ebook and then I will try to arrange it to become a paperback book. Not sure how the whole for-profit thing will work out , but I promise I will not publish a book without the consent of the authors.

 

 

 

If you want to write an article either email me or write down your article title in this post :

http://www.societyofrobots.com/robotforum/index.php?topic=4060.msg31909#new

 

Here are the subjects for the book:

1. Sensor-specific algorithms - This would be the algorithm needed to take a reading from a sensor and make it usable in the program.

Example: For the PING sensor you need to send a pulse on the pin and then take a reading . Then you have to apply a mathematical formula to convert the digital reading you received into centimeter/inches.

2. Generic Sensor Algorithms - This is not sensor specific algorithms, rather it applies for a majority of sensors that share a similar interface.

Example: Taking an Analog reading of a generic sensor and creating a matrix of readings.

3. Filtering and Control Algorithms - Algorithms relating to filtering of readings , etc.

Example : Kalman filter for sensors

4. Vision Related Algorithms - Algorithms relating to vision sensors ( a.k.a cameras, :P )

Example: Line following using CMUcam

5. Actuator Specific Algorithm - Algorithms relating to actuator control and interface

Example: Control of a DC motor using the L298 H bridge

6. Robot-Specific Algorithms - These algorithms relate to types of robots , such as bipeds , line followers, etc. There will be relatively little emphasis on sensor explanantion ( since that was detailed in the above articles) but more interface on method and procedure of the robot.

Example : Algorithm for (3 DoF per leg )bipedal robot to walk.

 

 

The layout of an article should be as follows.
1. Short summary of what the algorithm does, summary of sensors/parts used
2. How the algorithm works in regular english
3. Pseudo code of the algorithm
4. Sample circuit schematic to support algorithm on both a PIC and on an AVR

5. Code in BASIC and C

6. Which part(s) the code uses

7. Any cautions , etc.

 

 

For those who don't know BASIC and C , just post code in the language you do know and one of us will translate it to the language you don't know.

 

 

Here are the articles that were pledged to be written:

1. Line Following - Basic turns, sharp turns, breaks in the line to be written by airman00 ( me )

2. A* Star Pathfinding - to be written by benji

3. Color Sensing - to be written by TrikyNekro

4. Precision gripping - to be written by TrickyNekro

5. Kalman Filtering - to be written by sdk32285

 

 

PING Ultrasonic Rangefinder

The PING))) Ultrasonic rangefinder is a great sensor to add to a robot when the robot needs to know how far it is from an object or obstacle. The rangefinder takes up only one I/O pin on your microcontroller. Because it uses only a single I/O pin it needs a unique control algorithm. It sends out an ultrasonic signal from one of its ultrasonic transducers and measures how long it takes for that signal to bounce back to the 2nd ultrasonic transducer. The time can be converted to inches or cm.  More info can be found on the Parallax website.

 

Purpose of Sensor: Rangefinding

Details of Purpose: Range of 2cm to 3m( ~.75" to 10' )

Power Requirements: 4.5 - 6V @ 35mA draw

Pins needed : One I/O pin

 

Pseudo Code:

 Make the I/O pin an Output

Bring LOW the  pin that the PING rangefinder is connected

Bring the  pin HIGH for 5 microseconds

Bring the  pin LOW

Make the I/O pin an Input

Wait until the pin goes HIGH

Use a timer to see how much longer it takes for the pin to become LOW

The time it took to become low is now our raw distance ( in microseconds)

Divide Raw Distance by two since it includes the time for a return trip of the sonar

Raw distance * 2257 is our distance in cm

Raw distance * 889 is our distance in inches

 

 

 

BASIC Code:

'Where Ping is the alias for the  I/O port where the PING Rangefinder is connected to( e.g. PORTB.1)
Get_sonar:                                   ' we will call this subroutine Get_Sonar
  LOW Ping                                  'make trigger 0-1-0
  PULSOUT  Ping, 1                        'activate sensor
  PULSIN  Ping, 1 rawDist               'measure echo pulse  and store it in variable rawDist
  rawDist = rawDist * 10                    'convert to uS
  rawDist = rawDist / 2                          'remover return trip
                                'get sensor value                                                               
  inches = rawDist ** 889                 'multiply by 889 to convert to inches
  cm = rawDist **2257                     'multiply by 2257 to convert to centimeters
  Return                                           ' End subroutine

 

C Code:

Credit to Pomprocker

Uses the reset timer macro and "timer.h" - be sure to include that

//**************RESET TIMER**************
void reset_timer_0(void) {
//restart timer count
TCNT0=0x00;//clear timer
//clear timer0's overflow counter.
timer0ClearOverflowCount();
}
//***************************************

 

Note:  Pin used is PORTC.1 . For any other port , just change the pin # and also change the C in DDRC to the port you are using . For example for PORTE.0 use DDRE and change PingPin to 0.

int PingPin = 1;          // assign pin #1 o to the Ping Sensor
int PingVal = 0; // initialize and assign Ping Sensor Reading Value
PORT_ON(DDRC, PingPin); // Switch PingPin to OUPUT
// ------Trigger Pulse--------------
PORT_OFF(PORTC, PingPin); // Bring PingPin low before starting trigger pulse
delay_us(2); // Wait for 2 microseconds
PORT_ON(PORTC, PingPin); // Bring PingPin High for 5us according to spec sheet.
delay_us(5); // Wait for 5 microseconds
PORT_OFF(PORTC, PingPin);; // Bring PingPin Low and standby
//--------End Trigger Pulse---------------------
FLIP_PORT(DDRC, PingPin); // Switch PingPin to INPUT
loop_until_bit_is_set(PINC, PingPin); // Loop until the the PingPin goes high (macro found in sfr_def.h)
//clears timer, reset overflow counter
reset_timer_0(); //reset timer 0
loop_until_bit_is_clear(PINC, PingPin); // Loop until the the PingPin goes low (macro found in sfr_def.h)
//read timer0's overflow counter
//255 is count before overflow, dependent on clock
int elapsed_time=timer0GetOverflowCount()*255+TCNT0;
// The PING))) returns a pulse width of 29.033 uS per centimeter
PingVal = elapsed_time;