Wednesday, July 6, 2016

Obstacle avoiding with color recognition robot

           Obstacle avoiding with color recognition robot 


It is an intelligent robot which not only senses and overcomes obstacles on its path but also tells the color of the obstacle. The circuit assembly consists of IR Sensor, Ultrasonic sensor which together function as an input device to the robot. Basically, this robot senses the obstacle by using its 5 IR Sensor module and 1 ultrasonic sensor which feeds the data to the microcontroller (ATMEGA -2560) which process the raw data and provide output to the DC motors using motor controller Ic L298d and LCD display. We have used LCD display to display color sensed by robot of an obstacle .This simple technique can be incorporated in wheeled robots to keep away from damages and accidents.
                                  

                                                           PART LIST

Mechanical


           Components                                             
       1)      Acrylic sheet(for chassis)                                                                                                                      
        2)      Plastic  wheels                                                                                                                       
        3)      Caster wheels                                                                                                        
        4)      Motor mount heads                                                                                                                   5)      Nuts and bolts                                                                                                                         6)       Two-sided tape                                                                                                      
        7)      Hax saw blade                                                                                                          
        8)      Battery holder (4 cell)                                                                                                    
        9)      Hot glue gun                                                                                                             


Electronics

            
         Components                         Part Numbers                         
1)      color recognition sensor                       TCS3200                                             
2)      Arduino  board                                    ATMEGA 2560                                    
3)      Ultrasonic sensor                                 HC-SR04                                            
4)      IR Sensor module                                                                                            
5)      DC Motor(200 RPM)                                                                                     
6)      H  bridge                                              LM298D                                            
7)      PCB                                                                                                              
8)      Battery (9V)                                                                                                   
9)      Li-ion Battery(7.4v)                                                                                       
10)   LCD Display                                         JHD 162A                                        
11)   Soldering wire and flux                                                                                    
12)   Male and female headers                                                                               








Here is  the Arduino code for the robot  according to above specifications

 #include <TimerThree.h>
#include <LiquidCrystal.h>
#define trigPin 41
#define echoPin 43

#define S0     6
#define S1     5
#define S2     4
#define S3     3
#define OUT    2
int   g_count = 0;    // count the frequecy
int   g_array[3];     // store the RGB value
int   g_flag = 0;     // filter of RGB queue
float g_SF[3];        // save the RGB Scale factor


LiquidCrystal lcd(24, 9, 10, 26,11, 28);
 const int ir0=45;
 const int ir1=47;
 const int ir2=49;
 const int ir3=51;
 const int ir4=53;
 const int a1=30;
const  int a2=32;
 const int a3=34;
const  int a4=36;
int s[6];

//motor control
void motion(int l_speed, int r_speed)
{analogWrite(12,l_speed);
 analogWrite(13,r_speed);

}
void fwd()
{
   digitalWrite(a1, HIGH);digitalWrite(a2, LOW);//lft
 digitalWrite(a3, HIGH);digitalWrite(a4, LOW);//rt
  motion(200,200);Serial.print(" fwd\n");
 }

void rt_turn()
{ digitalWrite(a1, LOW);digitalWrite(a2, HIGH);//lft
 digitalWrite(a3,HIGH );digitalWrite(a4, LOW);//rt
  motion(255,100);
  Serial.print("rt turn\n");
}

  void lt_turn()
 {
   digitalWrite(a1, HIGH);digitalWrite(a2, LOW);//lft
 digitalWrite(a3, LOW);digitalWrite(a4, HIGH);//rt
 motion(100,255);Serial.print("lt turn\n");
 }
 void rev()
{
   digitalWrite(a1, LOW);digitalWrite(a2, HIGH);//lft
 digitalWrite(a3, LOW);digitalWrite(a4, HIGH);//rt
  motion(255,255);Serial.print(" rev\n");
 }
  void stop_()
{
   digitalWrite(a1, LOW);digitalWrite(a2, LOW);//lft
 digitalWrite(a3, LOW);digitalWrite(a4, LOW);//rt
  motion(0,0);Serial.print(" stop\n");
 }

 //ultrasonic sensor
long us()
{ int duration;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
 return (duration/2) / 29.1;


}

//color sensor
// Init TSC230 and setting Frequency.
void TSC_Init()
{
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(OUT, INPUT);

  digitalWrite(S0, LOW);  // OUTPUT FREQUENCY SCALING 2%
  digitalWrite(S1, HIGH); 
}

// Select the filter color 
void TSC_FilterColor(int Level01, int Level02)
{
  if(Level01 != 0)
    Level01 = HIGH;

  if(Level02 != 0)
    Level02 = HIGH;

  digitalWrite(S2, Level01); 
  digitalWrite(S3, Level02); 
}

void TSC_Count()
{
  g_count ++ ;
}

void TSC_Callback()
{
  switch(g_flag)
  {
    case 0: 
      /*   Serial.println("->WB Start");*/
         TSC_WB(LOW, LOW);              //Filter without Red
         break;
    case 1:
        /* Serial.print("->Frequency R=");
         Serial.println(g_count);*/
         g_array[0] = g_count;
         TSC_WB(HIGH, HIGH);            //Filter without Green
         break;
    case 2:
/*Serial.print("->Frequency G=");
         Serial.println(g_count);*/
         g_array[1] = g_count;
         TSC_WB(LOW, HIGH);             //Filter without Blue
         break;

    case 3:
      /*   Serial.print("->Frequency B=");
         Serial.println(g_count);
         Serial.println("->WB End"); 
         */
         g_array[2] = g_count;
         TSC_WB(HIGH, LOW);             //Clear(no filter)   
         break;
   default:
         g_count = 0;
         break;
  }
}

void TSC_WB(int Level0, int Level1)      //White Balance
{
  g_count = 0;
  g_flag ++;
  TSC_FilterColor(Level0, Level1);
  Timer3.setPeriod(500000);             // set 1s period
}

void colour_loop()
 { g_flag = 0;
delay(4000);
if( g_array[0]<25&&g_array[1]<25&&g_array[2]<25)
{ Serial.print("BLACK");
lcd.print("BLACK colour");
}
else if( g_array[0]>125&&g_array[1]>125&&g_array[2]>125)
{ Serial.print("WHITE");
lcd.print("WHITE colour");
}
 else if( (g_array[0]>80&&g_array[0]<255)&&g_array[1]>50&&g_array[1]<100&&(g_array[2]>80&&g_array[2]>80)&&(g_array[2]>80&&g_array[2]<149))

{ Serial.print("pink");
lcd.print("PINK colour");
}
else if( g_array[0]>g_array[1]&&g_array[0]>g_array[2])
 {Serial.print("RED");
 lcd.print("RED colour");
 }
 else if( g_array[1]>g_array[0]&&g_array[1]>g_array[2])
 {Serial.print("GREEN");
lcd.print("GREEN colour");
 } 
 else if( g_array[2]>g_array[0]&&g_array[2]>g_array[1])
 {Serial.print("BLUE");
 lcd.print("BLUE colour");
 }


 delay(4000);
}
void setup() {
  Serial.begin (9600);
  lcd.begin(16, 2);
  lcd.print("hello world");
  delay(1000); 
  


pinMode(a1,OUTPUT);
pinMode(a2,OUTPUT);
pinMode(a3,OUTPUT);
pinMode(a4,OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
TSC_Init();
 Timer3.initialize();             // defaulte is 1s
  Timer3.attachInterrupt(TSC_Callback);  
  attachInterrupt(0, TSC_Count, RISING);  

  
}

void loop()
{int dis=us();
  if(dis>0&&dis <3)

s[0]=0;
else
{s[0]=1;}
s[1]=digitalRead(ir0);
s[2]=digitalRead(ir1);
s[3]=digitalRead(ir2);
s[4]=digitalRead(ir3);
s[5]=digitalRead(ir4);
 if(((s[0])||(s[3]))&&((!(s[1]))&&(!(s[1]))&&(!(s[0]))&&(!(s[1]))))
  {fwd();
  }
  else if((!s[0])&&(!s[3]))
  {stop_();
  // delay(10);
colour_loop();
  // delay(10);
  rev();
  delay(500);
  stop_();
  delay(100);
  lt_turn();
  delay(500);
  }

  else if(((s[0])&&(s[1]))||(s[1]))
  {lt_turn();

  }

   else if(((s[1])&&(s[2]))||(s[2]))
  {lt_turn();

  }
   else if((s[0])&&(s[1])&&(s[5]))
  {rev();
 delay(500);
  rt_turn();

  }
   else if(((s[0])&&(s[5]))||(s[5]))
  {
  rt_turn();

  }
   else if(((s[5])&&(s[4]))||(s[4]))
  {
  rt_turn();
  
  }
     else if((s[3])&&(s[4]))
  {
  rt_turn();
  
  }
  else
  {fwd();}

 lcd.clear();
}

NOTE: Before compiling this code you have to  add   <TimerThree.h> header file in Arduino IDE.

Thanks :)
  




Tuesday, July 5, 2016

Exoskeleton arm controlled with Electromyography (EMG)

                                                             INTRODUCTION
Exoskeleton arm is an outer framework that can be worn on a biological arm. It is powered by actuators and can provide assistance or increase the strength of the biological arm, depending on the power of the actuator. EMG is the suitable approach for human machine interface with the help of exoskeleton.
When working with EMG we actually measure the motor unit action potential [MUAP] generated in the muscle fibers. This potential builds up in the muscles when it receives a signal from the brain to contract.

The Nerve Potential
      MOTOR UNIT ACTION POTENTIAL (MUAP) is generated on the surface of our arms whenever we contract or relax our arm.
      Amplitude is in order of 0-10 millivolts .
      The frequency in between 0-500Hz.
      This MUAP is the core of this project and the basis of EMG processing.
             


THE EXOSKELETON ARM
      It is an outer framework that can be worn on a biological arm.
      It is uses a Non-invasive method to acquire MUAP from muscles to control the framework, that can be worn on a biological arm.
       Powered by a high torque servo motor.
      Can provide assistance or increase the strength of the biological arm, depending on the torque of the servo motor.
      Electromyography (EMG) is the suitable approach for human machine interface (HMI) with the help of exoskeleton (EXO) .


Software Used:

 1).KEIL uVision for compiling the code and monitoring the signal.

 2). Multisim for circuit simulation.



Hardware Tools:

1)      Microcontroller board: EVAL-ADuCM360 PRECISION ANALOG MICROCONTROLLER (Analog Devices Inc.)This microcontroller board is used in our project as the brain to control the exoskeleton arm. This process will be used for interfacing our EMG sensors with the arm (servo motors).

2)      Instrumentation Amplifier: AD620AN (Analog Devices Inc.)This receives signal from EMG electrodes and give the differential gain as the output.

3)    OP-AMP: ADTL082/84(Analog Devices Inc.)The output from the DIFFERENTIAL AMPLIFIER is rectified and this output is fed to the LOW PASS FILTER and then to the GAIN AMPLIFIER.

4)    SERVO MOTORS: 180kg*cm torque. It is used for the movement of the arm.

5)    EMG Probes: For the acquisition of signal.

6)    Battery: Two  11.2V, 5Ah Li Po battery, it will be used to power the servo. Two 9V battery to power the EMG circuit


7)    Metal Frame
                                                      METHODOLOGY

The exoskeleton arm works in two modes .First mode is automated mode in which  EMG  signals after the signal  processing will  command the servo  and second manual mode ,a  potentiometer will command servo motor .

ADI COMPONENTS USED:
1)AD620 Low cost low power instrumentation amplifier.
2)ADTL084 Low cost JFET input operational  amplifier.
3)EVAL-ADuCM360 Precision analog microcontroller.



Various stages in EMG signal processing:
1) Signal Acquisition: The Motor Unit Action Potential (MUAP) signal is acquired from the bicep and triceps of the patient’s arm. Three EMG electrodes are used in the process. Two EMG electrodes are placed on the bicep and triceps, one on the elbow for ground reference. The acquired signal is fed into the AD620 high quality instrumentation amplifier. Which will amplify (gain=500)   the potential  difference between  the active electrodes.
Gain of instrumentation amplifier G=1+49.9KOhms/R

Fig:2V (peak to peak)MUAP signal after AD620 instrumentation op-amp. 


1    2)      Filtering and Amplification: This amplified signal is then fed to a dc coupling capacitor and a full wave rectifier which eliminates DC error offset and negative half cycles to make the signal compatible with the microcontroller. This rectified signal then goes through a low pass filter to eliminate high frequencies and make an envelope of the signal. The signal is sent into an amplifier with variable gain for further amplification. All the stages are designed using ADTL084 op-amp

Gain of op-amp Vout/Vin=-Rf/Rin


Fig: signal after full wave rectification.


Data Acquisition:
The amplified signal is fed to a microcontroller EVAL-ADuCM360 PRECISION ANALOG. The analog voltage is read by ultrahigh precision 24-bit ADC present in the microcontroller. The data is sampled at a rate of 2.450 kHz.  ADC Chopping scheme is used. This chopping scheme results in excellent dc offset and offset drift specifications and is extremely beneficial in applications where drift and noise rejection is required. The offset obtained when the muscle is relaxed is subtracted from the ADC output
Control Logic:
Since noise rejection is required in the final stage, linear mapping of the ADC output to the DAC is avoided. We have created a lookup table that writes discrete values to the DAC. Don’t care conditions are created for low voltage analog signals so that the servo is not activated unnecessarily. The threshold for maximum voltage is set manually, after testing, as it is different for every test subject.
DAC:-
The microcontroller comes with a 12-bit DAC. The DAC has two selectable ranges: 0 to 1.2 V & 0 to 1.8 V. Coincidently 1.8V input to servo motor gives the optimum turning angle for the servo motor. There this range is used as it requires no further amplification.We have used DAC Interpolation Mode .The interpolation mode uses 16-bits. 12-bits are used for the writing the data and 4 bits for interpolation.
Servo Motor:
The servo motor has a torque of 180kgcm. It runs on two modes Pulse Width Modulation and Potentiometer mode (analog signal).We have used the analog mode because it is easier to monitor and analyze as compared to PWM. When given an input of 5V the servo turns 270 degrees .It runs on 14V to 30 V. 30 V for maximum  torque .




                                                Exoskeleton Arm on a test subject
  Challenges:-
While working on EMG sensor we found that the ADTL084 op-amp are only available in SOIC and TSSOP Packaging so we came up an alternative SOIC to DIP adapter board.
High torque servo motor (380 Kg. Cm) that we had bought from China gone malfunction with no other options we replace it by new one.
We discussed about which material to choose for the frame and its design eventually we decided to go with aluminium because it is the lighter and stronger metal. A backpack is designed to hold other parts such as EMG circuit, microcontroller and batteries.
There was an offset in the final stage of the EMG circuit, it could be reduced by decreasing the gain of the final amplifier. But reducing the gain also reduce the amplitude of the signal. So extra efforts had to applied to activate the servo. But for patients undergoing rehabilitation such high efforts was not possible. Therefore we  had to increase the gain.
To handle the problem of drift, we subtracted the offset value from the input.
First linear mapping was done between ADC and DAC output. But when we increased the sensitivity of the setup for physiotherapy patients, the servo started rotating randomly due to the high sensitivity. To tackle this problem we used Boolean logic to give discrete analog values to the servo and rejected signals with low amplitude.
Future prospect:
With further research on this we can improve the design of the needs to meet the needs of the patient in rehabilitation centers . Instead of using servos, alternate methods can be used to power the arm like NANO MOTORS(Smart Memory Alloys) . When extreme power is required hydraulic systems can be used. This design provides support for the arm to lift the objects only. We have been working on acquiring signals from the triceps as well, so that objects can be pushed as well. Mechanical suits have been Sci-Fi films from a long time We think with further research we can arrive to a point where IRON MAN suit is becomes a reality.

 The team consists of three students namely Surya Pratap S Deopa ,Naval Kishore Mehta, and Abhishek Saxena .


Obstacle avoiding with color recognition robot

           Obstacle avoiding with color recognition robot  It is an intelligent robot which not only senses and overcomes obstacles ...