Thursday, November 17, 2011

Using Cellphones as Robotic Control Platforms - Cellbots.com

http://hk.myblog.yahoo.com/robot-builder/article?mid=210
網誌日期:2010-04-08 00:06
http://www.cellbots.com/about/

I agree that it is possible to control the low level devices such as Arduino or PIC from cell phone by just using serial port or bluetooth connection. you just design the serial protocols and it can control the devices on the fly.

I designed M-proxy which will do the similar job by using Nokia N82. But it is not limit to use Iphone and Android phone.

m_proxy version 0.1

http://hk.myblog.yahoo.com/robot-builder/article?mid=183
網誌日期:2010-03-01 00:49
Today, most smart phones ( such as Nokia, iphone, Google Android ) have high resolution camera, Wifi, 3G, HSDPA, 3D tile sensors, GPS and compass functions). Did you think you can turn the smart phone into robot brain? The answer is Yes. I designed m_proxy which will make use of these functions and will let you to control your robot from any place of the earth. You and the robot just need to have Internet access. To implement the m_proxy, I use a cheap 27Mhz RC tank, Arduino, Nokia N82 to build the prototype and test the performance. The target is to make a semi-auto surveillance mobile robot and perform some tasks.

Please refer to the following url for the construction of the robot.
http://picasaweb.google.com/103004795864513293020/M_proxy#slideshow/5443335185983998850

m_proxy

Motor Module

http://hk.myblog.yahoo.com/robot-builder/article?mid=79
網誌日期:2008-05-29 00:29
In this part, I would like to describe the structure of the M-Blocks, both hardware and software, via the Motor Module.

1. Hardware side

Motor module consists of  following common interfaces and it's specific interfaces:


see large picture

a. Common interfaces ( yellow blocks )
1. ISP Programming port
2. ON/OFF Switch
3. UART Serial port
4. M-Blocks Bus which have the following standard.

------------------------------------------
Vin - Input Voltage from battery
Vcc - Regulated 5V
3.3V - Regulated 3.3V
SCL  - I2C  Clock  Bus
SDA - I2C Data Bus
S3, S2, S1 - Slave select for SPI bus
MOSI, MISO, SCK - for SPI bus only
( SPI bus is left for further use, I have not develop any sensors or devices through SPI communication )
TX - Transmitter for UART - connected to PC for debug only
RX - Receiver for UART - connected to PC for debug only
-------------------------------------------

b. Specific interfaces for Motor Module
1. SN754410 H-Bridge
2. External Power Input
3. Motor Connectors 1-4



2. Software side
Except the Controller Module which is a master I2C device, all other modules are slave I2C  devices. The design  of  the program  is divided  into three parts: 

   --------------------------
   |  I2C                         |   
   --------------------------
   | UART                    |   
   --------------------------
   | Functional Logic  |
   --------------------------

1) I2C communication among the modules,
2) UART serial communication for debug only ,
3) The functional logic for controlling devices such as motors or servos.

I developed the program in WinAVR and built the hex file using avrdude. If you are interesting in the program, please download here. motor-module.zip

Schematics and board layouts for Eagle


see large picture.

I use atmega8 to make all the communication and controlling. Atmega8 have three timers providing three PWM Channels. It is able to control the width of the PWM to the SN754410 H-Bridge IC by controlling the values of  OCR1A ( motor 1 PWM) ,OCR1B (motor 2 PWM) and OCR2 (motor 3 PWM).

For the detailed information of Atmega8, please refer to the data sheet.


The protocol is very simple.

[ch][dir][low-power][h-power] , 1 byte each

[ch] set the motor channel , value = 0,1,2
[dir] set the forward direction or backward direction of the motor, value = 0,1
[low-power] and [high-power] set the speed of the motor, value = 0-255

Example: 00FF -> set ch 0 (left motor), dir 0 (forward), power = FF = 256.

The routetime set_power(uint8_t ch , uint8_t dir,uint8_t power) control the motor, direction and speed of the motor.

As I am not a master in programming micocontroller, many of the coding, especially the hardware configuration, or library are "borrowed" from other's projects.

The I2C library is borrowed from http://tuxgraphics.org/electronics/200705/article07051.shtml
and the PWM control is borrowed from another website but I forgot the author's website.

So far, the Motor Module is working. It received commands from Controller Module and run set_power() routine to generate the PWM for the H-Bridge and control the speed of the Motors. My final version is to make the device which provide  feedback parameters to the Controller Module. To make it as a close-loop control. I will borrow the design from the controller board of  the openservo project. The controller board is a I2C slave device and it have feedback parameters to the controller board. All the parameters are saved in the registers ( flash memory ) of the micro-controller ( atmega8 or atmega168 ) and
permanently  in the EEROM as in the following diagram.

   --------------------------
   |  EEROM                 |
   --------------------------
   |  I2C                         |   
   --------------------------
   | UART                    |   
   --------------------------
   | Functional Logic  |
   --------------------------


Reference websites:
1. Dr. Pascal Stang have contributed to the programming and design of the hardware. It is worthly to study his design if  you want to learn avr-gcc programming and hardware design. I have implement the I2C master device from his design.
http://hubbard.engr.scu.edu/embedded/

2. Openservo project, the opensource servo controller is based on atmega8 or atmega168 and avr-gcc. The design is very good.
http://www.openservo.org

3. Paparazzi UAV project
Paparazzi is a free and open-source hardware and software project intended to create an exceptionally powerful and versatile autopilot system by allowing and encouraging input from the community. I implement the PPM decoding for my 6 channels Radio Transmitter by referring to the UAV project.

M-Blocks Application

http://hk.myblog.yahoo.com/robot-builder/article?mid=60

網誌日期:2008-05-09 00:45
This is the robot I built for the M-Blocks Modules. It is a Lego tank with a video camera attached to two servos. I built this robot aim to develop the protocols for communication among the modules. In the first phase, I think the protocol is not very efficiency and need improvement. Anyway. I can now use either radio transmitter, PC terminal, or Nokia N82 to control the robot. It is quite interesting! I think it is possible to add other control interfaces such as PS2 controller and IR Remote.






Construction of the robot with M-Blocks

Control M-Blocks by Radio Control

Control M-Blocks by PC

Control M-Blocks by Nokia N82

Design of M-Block

http://hk.myblog.yahoo.com/robot-builder/article?mid=56

網誌日期:2008-05-07 21:43

1. Why design  M-Blocks?

Having experience in programming with atmega8  ( 8K Bytes flash program memory, two 8-bit timer, one 16 bit timer , 6-8 ADC, 1 UART, 1 I2C, 1 SPI ). I figured out it is quite limit if you need to build a robot with many sensors and accumulators. That  comes to my mind and think  it is  possible to build stack blocks of atemega8 and connect them together. Each block perform it's own function. The challenge is to design the protocol to communicate among the blocks.

The following figure outlines the design. The I2C Master device called Controller Module (CM). CM  perform its task by receiving commands from Radio Control, Bluetooth serial port or PC serial port. Then, it sends I2C commands to the slave devices and receive response from these devices. When the salve devices receive the commands, they will perform its own tasks. It is possible to write a autonomous logic. For example, Motor Module will turn on and turn off the H-bridge, Servo Module will move the servos, Sensor  Module will acquire data and response to CM.  That is it!. It seems all the above functions can be carried out in a single board computer. But if you need to extend the number of sensors (say 20 more) or number of accumulators (say control 4 motors more). Single board computer cannot achieve the goal.

(M)     (S1)    (S2)     (S3)     (S4)   ...... (Sn)
CM    SM1   SM2    MM1   MM2  .....            M-Blocks
  |          |           |           |           |
------------------------------------------------  I2C Bus

Lets see how I2C works.
http://www.esacademy.com/faq/i2c/general/i2cproto.htm
http://www.robot-electronics.co.uk/htm/using_the_i2c_bus.htm

www.robot-electronics.co.uk sells Compass sensors, Servo Controller, Ultrasonic Sensor, Thermal Sensors , Text to Speech Synthesizer. All have interface to I2C.

If it is possible to develop efficiency I2C protocols for communication among the salve modules and the mater module, it is possible  to extend the system by adding new modules.


2. What is the Pro and Cons of M-Block?
Pros:
1. Multitasking, each module perform  its own task, for example, controller in Motor Module only service to control the H-bridge.

Cons:
1. All modules are connected through I2C bus. If the bus hanged, the system will not work.
2. All the control is carried out through Controller Module as a proxy by sending commands to  the Slave Modules. This turn out to be quite inefficiency in control.


3. M-Blocks structure

a. Controller Module - I2C Master module to control slave devices

b. Motor Module - I2C slave device to control two SN754410 H-Bridge Motor Driver 1A

c. Servo Module - I2C slave device having 12 channels for controlling stanard  analog servo .e.g. Futaba S3003.

d. Sensor Module - I2C slave device with  ADC conversion for connecting Ultrasonic Range Finder - Maxbotix LV-EZ0 and Infrared Proximity Sensor - Sharp GP2Y0A21YK

e. Radio Module - 6 channels Radio receiver and transmitter detached from damaged electric helicopter. It connect to Controller Module and ICP to decode PPM signals.

f.  Bluetooth Module - As a bluetooth serial port  Bluetooth Modem - BlueSMiRF Silver connected to Controller Module's UART serial port. The bluetooth serial port will let you control the robot from PC terminal or custom build programe. It is possible to control the robot from bluetooth smartphone such as Nokia N73 or Nokia N82.

Download


http://hk.myblog.yahoo.com/robot-builder/article?mid=45

網誌日期:2008-04-30 00:04

1. M-Blocks schematics and board layouts ( Updated on 30.4.2008 )
M-Blocks.zip consists all the schematics and board layouts for Eagle ( http://www.cadsoft.de/ ). To view the files, you can just install Eagle and unzip the files in the "Projects" folder of Eagle.

M-Blocks PCBs

http://hk.myblog.yahoo.com/robot-builder/article?mid=8

網誌日期:2008-04-26 01:46
I started the project called "M-Blocks" on April 05 and the first phase was completed on Dec 06. Later  I started another project and did not have time to continue the development of the M-Blocks.

Here I would like to share the design, construction and coding of M-Blocks. But today is 26.4.2008. I have to recall my memory to fill out the content. I hope to make it as accuracy as possible and the content will be revisited if i found it is incorrect. Sorry for that.

What is M-Blocks? Look at the following notebooks. I think only me can understand what it means?

M-Blocks are modules which can be stacked together to perform a system for mobile robot.

For the first phase. I designed:

1. Controller Module (CM)
2. Motor Module (MM)
3. Servo Module (SM)
4. Radio Module (RM)
5. Bluetooth Module (BM)

All the modules are connected via I2C bus and they all can be debugged through serial port individually (UART).
Each module have a atmega8, atmega168 or atmega32 for the mcu.

   | --- BM ( Serial )
   | --- RM ( PPM )
   |       
 CM    MM    SM   
   |          |          |       
-------------------------------------------------  I2C bus

I designed the schematic and boards in Eagle and write C code in gcc-avr.








Schematic and circuit board  for Servo Module.




The printed PCB. I use toner transfer method to make the double sided PCB. I use the following type of paper. It called "Glossy Photo Paper".


The steps are as same as that in the following video.
http://www.youtube.com/watch?v=urv6jArKp6M&feature=related

Each PCB have top and bottom print out from the glossy photo paper. And one bottom layer from transparent. Totally three print out. The transparent print out is used for alignment purpose.


Alignment of the top and bottom layers to make double sided PCB.


PCB Etching. I use Ferric chloride (FeCl). It is very dirty but can be reused.


Then drill holes.


The completed PCB.


Put in components , compete soldering and test the circuit board.
This is the Sensor Module. The mcu is either atmega8 or atmega168.


This is the another Controller Module. I created the first Controller Module with atmega8. But I found out there is not enough space to coding the "Brain" of the robot. Then, I created another Controller Module with atmega32 which provide more space (32 Kbytes) for coding.



M-Blocks Modules completed.


Stacks of M-Blocks



Next. I will show the application of the M-Blocks.

Control RC Tank from Nokia N82 or PC

http://hk.myblog.yahoo.com/robot-builder/article?mid=129

My idea is to make a universal controller for Radio Control Toys. From my previous post, I described how to make the receiver and transmitter from a hacked RC car. Now I am going to decode the Radio Signals for the following RC Tank and use Nokia N2 or PC to control the tank.
http://www.henglongtoys.net/eng/ShowProduct.asp?id=568



Lets watch how I control the tank from Nokia N82.



And the source codes:
http://universalrccontroller.googlecode.com/files/rc_controller_v0_1.zip

If you want to know the details on the controlling, please see the explanation blew.

By measuring the width of the pulses , I got the following results (for the details, please see the figure from oscilloscope):

Start High pulse width: 1000us (microseconds)
Start Low pulse width: 600us (microseconds)
Long pulse width: 260us (microseconds)
Short pulse width: 140us (microseconds)

And the Logical Bit 0 and Bit 1 can be made from the following combination:

Bit 1 = short high pulse (140us) + long low pulse (260us)
Bit 0 = short high pulse (140us) + short low pulse (140us)

And Start High pulse and Start Low pulse have to be sent at the start of each command.




Connecting the required components (Transmitter, Bluetooth serial module, Arduino and Nokia N82), uploading programe for Arduino and N82, I can now control the RC Tank from my N82.

Each command have three bytes, but the size of the actual command is less than three bytes. It has 17 bits only. e.g. (00000000111101000). I use a  variable called MASK_BITS to mask the active bits. In this way, I can use the Arduino to stimulate the signals as the factory transmitter do.


const int COMMAND_LENGTH = 3;   
const byte MASK_BITS[]       = {B11111111, B11111111, B10000000}; // mask control the active bits
// the  commands
const byte STOP[]            = {B00000000, B11110100, B00000000}; // 00000000111101000
const byte TURBO[]           = {B10110000, B01010100, B00000000}; // 10110000010101000
const byte FORWARD[]         = {B10110000, B01010100, B00000000}; // 10110000010101000
const byte BACKWARD[]        = {B10110000, B01010100, B00000000}; // 10110000010101000
const byte LEFT[]            = {B00010000, B01100100, B00000000}; // 00010000011001000
const byte RIGHT[]           = {B00010000, B10010100, B00000000}; // 00010000100101000
const byte RIGHT_FORWARD[]   = {B00010000, B00010100, B00000000}; // 00010000000101000
const byte RIGHT_BACKWARD[]  = {B00010000, B00100100, B00000000}; // 00010000001001000
const byte LEFT_FORWARD[]    = {B00010000, B01000100, B00000000}; // 00010000010001000
const byte LEFT_BACKWARD[]   = {B00010000, B10000100, B00000000}; // 00010000100001000
const byte CANNONRIGHT[]     = {B00011000, B00000100, B00000000}; // 00011000000001000
const byte CANNONLEFT[]      = {B00010100, B00000100, B00000000}; // 00010100000001000
const byte CANNONUP[]        = {B00010001, B00000100, B00000000}; // 00010001000001000
const byte CANNONFIRE[]      = {B00010010, B00000100, B00000000}; // 00010010000001000

For the PyS60, it senses the orientation (X,Yand Z axis) of the phone and use the following simple protocols to transfer commands.


The simple protocols sent from PyS60 
        msg = bytecmd(65) # "A" the sync byte
        msg +=bytecmd(mode) # mode [ 0: moving directing, 1: moving turret ]
        msg +=bytecmd(x_val) # x-axis [ -127 to  127 ]
        msg +=bytecmd(z_val) # z-axis  [
-127 to 127 ]

// decode the protocols in the Arduino
loop until the byte matches the sync byte

int findPacketHead() {
    while(1) {
        while(Serial.available() == 0) select_command() ;
        if(Serial.read()=='A') { // "A" is the sync byte
            break;
        }
    }
}

if the value is grater than 127, it means it is a negative number

    cmd[0] = receiveByte(); // mode
    cmd[1] = receiveByte(); // x-axis
    if (cmd[1] > 127) cmd[1] = cmd[1] -256;   // if is it larger than 127, it is negative  number
    cmd[2] = receiveByte(); // z-axis  
    if (cmd[2] > 127) cmd[2] = cmd[2] -256;    

According to the following table, the select_command() will select the command. ? means don't care the number.
Mode
cmd[0]
Z-axis
cmd[2]
X-axis
cmd[1]
Command
0
?
>30
Backward
0
?
<-30
Forward
0
30
?
Right
0
<-30
?
Left
0
>30
>30
Forward_right
0
<-30
>30
Forward_left
0
<-30
<-30
Backward_right
0
>30
<-30
Backward_left
1
>30
?
Turret_right
1
<-30
?
Turret_left
1
?
>30
Cannon_up
1
?
<-30
Fire
?
<30
<-30
Stop


If you don't have the bluetooth serial module and Nokia N82, you can directly control the tank by just a PC.

The easy way is to read the command (byte) sent from keyboard and directly map the key to it's related command. Please see the following select_command() for details.

int select_command(){
     delay_time=25;
    if(cmd[0] == '8') { // key 8
        send_command(FORWARD);       
    }else if(cmd[0] == '2') { // key 2
        send_command(BACKWARD);               
    }else if(cmd[0] == '4') { // key 4
        send_command(LEFT);       
    }else if(cmd[0] == '6') { // key 6
        send_command(RIGHT);      
    }else if(cmd[0] == '7') { // key 7
        send_command(LEFT_FORWARD);
    }else if(cmd[0] == '9') { // key 9
        send_command(RIGHT_FORWARD);
    }else if(cmd[0] == '1') { // key 1
        send_command(LEFT_BACKWARD);
    }else if(cmd[0] == '3') { // key 3
        send_command(RIGHT_BACKWARD);
    }else if(cmd[0] == '5') { // key 5
        send_command(STOP);
    }else if(cmd[0] == 'q') { // key q
        send_command(CANNONLEFT);
    }else if(cmd[0] == 'w') { // key w
        send_command(CANNONRIGHT);
    }else if(cmd[0] == 'a') { // key a
        send_command(CANNONUP);
    }else if(cmd[0] == 's') { // key s
        send_command(CANNONFIRE);
    }   
}

First Arduino project - Serial to Radio Control Transmitter (27Mhz)

This post was copied from the following url
http://hk.myblog.yahoo.com/robot-builder/article?mid=104

Recently, I have free time to play with electronics and robot again. And I found Arduino is a very good device for bringing your imagination into reality. There will be tons of projects created with this microcontroller board. It is cheap but powerful. You can use it to control many low level devices.

I have a lot of cheap Radio Control Toys such as UFO, Mimi Cars, Tanks... Most of them are controlled by transmitters running in 27Mhz. I wonder the functions of the transmitters for these toys are very simple. Most of them have forward, backward, turn left, turn right, turbo and stop functions. If I can decode the signals( from the transmitters) and store the encoded pulses inside the Arduino and send out again, it is possible to control these toys from other devices having serial connection.

Nokia N82 <--------->   Arduino + RC  transmitter     ---------------->   RC Toys
                    Bluetooth                                                  Radio Control        

PC <--------->   Arduino + RC  transmitter     ---------------->   RC Toys
          Bluetooth                                                  Radio Control        



After reading the following websites, i wounder it is possible to builder a RC Controller from Arduino.

1. Building a Universal Remote with an Arduino
http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
2. iPhone controlled R/C car
http://www.youtube.com/watch?v=i29u92qg40E
3. ShakerRacer: Real RC car controlled with the N95 acceleration sensor
http://blogs.forum.nokia.com/blog/andreas-jakls-forum-nokia-blog/2007/11/27/shakerracer
4. How Radio Controlled Toys Work
http://electronics.howstuffworks.com/rc-toy2.htm

For my first testing, I used a Nokia N82 mobile phone to control a mini RC Car. Nokia N82 have a 3D title sensors ( accelerators)  which will provide the orientation of the phone. Changing the orientation will send out commands for controlling the toys. OK. Lets see the videos.





Let see the required equipments and software:

1. Parallax oscilloscope ( For decoding the pluses which are sending from transmitter)
http://www.parallax.com/Store/Accessories/Tools/tabid/162/ProductID/46/List/0/Default.aspx?SortField=ProductName,ProductName
2. Non-used RC toys ( I need the transmitter and receiver, running at 27Mhz)
3. Arduino Diecimila ( The microcontroller board)
http://www.arduino.cc
4. Bluetooth serial port  ( From sparkfun, use to connet between Arduino and Nokia N82)
http://www.sparkfun.com/commerce/product_info.php?products_id=582
[ This bluetooth module is quite expensive (~HKD480). I know that there may be a cheaper version from taoboa  http://www.taoboa.com.]
5. Nokia N82 ( Installed with Pys60 which will get the orientation of the phone and send out commands , to play with Pys60, you need to know programming Python)
http://wiki.opensource.nokia.com/projects/PyS60
http://www.python.org

I need the transmitter and receiver , which are taken from the following non-used RC car

The mimi RC car, The receiver was taken out.

The red wire pin (SI) was connected to oscilloscope, then measure the width and number of pluses. or please see the spec. of  the receiver (http://www.utc-ic.com/spec/RCR2C.pdf)

The stuff inside the orange box is the 27Mhz transmitter. To stimulate the encoded pluses, it need to connect the output pin of the Arduino to the (SO) pin of the transmitter.

The spec. is  matching the following remote control I.C. ( transmitter)
http://www.utc-ic.com/spec/RCT02.pdf


Now. It is time to decode the signals of the RC car, which is also running in 27Mhz

I got the following result (For forward direction), it just need to measure the width of the pluses and number of repeated pluses for different directions (i.e. forward, backward, turn left, turn right, turbo, stop) and use Arduino to stimulate the signals.
.
From the outputs, I got the following signals


1. Forward : 4 long pluses, then following 10 short pluses
2. Backward :4 long pluses, then following 40 short pluses
3. Forward +Turn Left: 4 long pluses, then following 28 short pluses
4. Forward +Turn Right : 4 long pluses, then following 34 short pluses
5. Backward+Turn Left: 4 long pluses, then following 46 short pluses
6. Backward+Turn Right : 4 long pluses, then following 52 short pluses
7. Turbo: 4 long pluses, then following 22 short pluses

Now making a PCB which connect the transmitter and the Arduino. loading the programme for  Arduino and Nokia N82. It is now able to control the cheap radio control car from the N82..




If you are interesting in the software. please download here ( sorry for few comments):
1. Wire programme  for Arduino
http://freespace.webtracker.hk/remote_mimi_car2.pde
2.PyS60 programme  for N82 (based on Jouni Miettunen's Sensor Analyzer)
http://freespace.webtracker.hk/bt_controller_v_1.0.py

Using similar techniques, it is possible to decode another Radio Control Toys( running 27Mhz) with out hacking the hardware.. I will try another toys soon....