Robotics Assignment

download Robotics Assignment

of 15

description

Robotics

Transcript of Robotics Assignment

  • E-Puck Laboratory Report

    Paramtap Mewada, Reg. No.: 130109923

  • Contents

    1 Introduction 1

    2 Mini-Project 1 2

    3 Mini- Project 2 4

    4 Drawbacks or Incomplete of current code 5

    5 Appendix 6

    i

  • 1 Introduction

    Given the specications of the E-Puck robot with eight infrared sensor at orientation of dierent angles

    as follows:

    Sensor Orientations

    PS0 1.27

    PS1 0.77

    PS2 0.00

    PS3 5.21

    PS4 4.21

    PS5 pi

    PS6 2.37

    PS7 1.87

    Table 1: Orientations of the E-puck's Proximity Sensors

    from the calibration test the average of the maximums output of the sensor received throughUART

    1

    =(3737+3752+3757)/3=3749. Thus the output of each sensor varies between the 0 3749.

    from the given data maximum speed of each motor varies from 1000 to 1000. To track the direction of the v with speed of left and right wheel proportional to the closeness ofthe the predator or object is given by following:(

    SlSr

    )=

    (1 11 1

    )(vxvy

    )(1.1)

    This modelling works because of the fact that the force resolved into two components and concepts

    of the moment about the point(in this case center of E-Puck). As the speed of wheel will be

    set according the linear equation (0.1) as per the Varignon's Theorem the robot will experience

    moent that will orient the E-Puck in the direction of sensed predotor??.

    Should this forces be applied in the negative manner the moments will be applied in the opposite

    direction which will be demonstrated in theMini-Project 1 32them E-Puck controller instead of showing

    'following' obstacle will start running away from the predator or obstacle. Just like reversing the

    electromagnetic charge between two atoms instead of attracting, two will be repelling each other.

    According to the specication ,it is considered that output of each sensor detects the presence,

    proximity and orientation of the obstacles.

    1. Presence: It is detected by the sensor output, if PSn > 0,where n=0,...,7; then there is obstacleor predator present.

    2. Proximity: It is given by the magnitude of the PSn, where n=0,...,7. Eg: If the one reading is10, and another reading is 100, then 100 is more closer to E-Puck than at the 10.

    3. Orientation: Is given by the combination of the calibration function such that any noisy reading

    are removed by the calibration, then taking the linear combination of the sensor reading gives

    the correct orientation when divided into the vector form .(SlSr

    )=

    (1 11 1

    )(VxVy

    )e.g. PS0 detects the predator, then PS1 to PS7 reading would you be zero(ideally) or will be calibratedto zero by the calling the function e_calibrate_ir( ), then all terms from the (vx1, .., vx7) = 0 ,andvx0, vy0 6= 0.1

    Universal Asynchronous Receiver-Transmitter

    1

  • Thus calculating the vector of :

    V X0 =magnitude of proximity sensor '0'cos(0.00) ,V Y0 =magnitude of proximity sensor '0' sin(0.00).Thus speed of the Speed of left and right wheel can be given by, which is done in the following code(

    SlSr

    )=

    (1 11 1

    )(V X0V Y0

    )

    2 Mini-Project 1

    However, there is physical limitations of the motors use i.e. cannot generate innite amount of speed

    or servo step fails if given signals larger than the its specication, in this case it 1000.

    THIS IS GIVEN IN THE PROGRAM BY THE FOLLOWING:

    Listing 1: Mini Project 1

    prox0 = e_get_calibrated_prox ( 0 ) ;

    prox1 = e_get_calibrated_prox ( 1 ) ;

    prox2 = e_get_calibrated_prox ( 2 ) ;

    prox3 = e_get_calibrated_prox ( 3 ) ;

    prox4 = e_get_calibrated_prox ( 4 ) ;

    prox5 = e_get_calibrated_prox ( 5 ) ;

    prox6 = e_get_calibrated_prox ( 6 ) ;

    prox7 = e_get_calibrated_prox ( 7 ) ;

    vx0=prox0 cos ( 1 . 2 7 ) ;vx1=prox1 cos ( 0 . 7 7 ) ;vx2=prox2 cos ( 0 ) ;vx3=prox3 cos ( 5 . 2 1 ) ;vx4=prox4 cos ( 4 . 2 1 ) ;vx5=prox5 cos ( 3 . 1 4 ) ;vx6=prox6 cos ( 2 . 3 7 ) ;vx7=prox7 cos ( 1 . 8 7 ) ;// Linear Combination f o r VX

    VX=(vx0+vx1+vx2+vx3+vx4+vx5+vx6+vx7 )/max ;

    vy0=prox0 s i n ( 1 . 2 7 ) ;vy1=prox1 s i n ( 0 . 7 7 ) ;vy2=prox2 s i n ( 0 ) ;vy3=prox3 s i n ( 5 . 2 1 ) ;vy4=prox4 s i n ( 4 . 2 1 ) ;vy5=prox5 s i n ( 3 . 1 4 ) ;vy6=prox6 s i n ( 2 . 3 7 ) ;vy7=prox7 s i n ( 1 . 8 7 ) ;// Linear Combination f o r VY

    VY=(vy0+vy1+vy2+vy3+vy4+vy5+vy6+vy7 )/max ;

    //Making sure maximum magnitude never goes above 1000

    //Revers ing Charge Analogy

    S l=( i n t )(VXVY) ;i f ( Sl >1000)

    { S l =1000; }

    Sr=( i n t ) (VXVY) ;i f ( Sr >1000)

    { Sr=1000; }

    2

  • My previous methods was write the normalization algorithm and use it set the velocites of the

    wheels of motor, but as values were being set in the unrounded terms E-Puck traversed more curvy

    paths then straight lines, the code was as follows :

    Listing 2: Normalisation Algorithm

    // Algorithm to normal i s e the data s e t f o r f i nd i n g // the v e l o c i t i e s

    //Accepting the cur r ent va lue s from the senso r

    VX_temp=(vx0+vx1+vx2+vx3+vx4+vx5+vx6+vx7 ) ;

    VY_temp=(vy0+vy1+vy2+vy3+vy4+vy5+vy6+vy7 ) ;

    //Give the minimum ca l i b r a t e d value o f s enso r A=0;

    //Give the maximum ca l i b r a t e d value o f s enso r B=3749;

    //Give the minimum value o f s t epper input s i g n a l a=1000;

    //Give the maximum value o f s t e ep e r input s i g n a l b=1000

    //The normal i sed value

    VX=a+(VX_tempA) ( ba )/ (BA) ;VY=a+(VY_tempA) ( ba )/ (BA) ;

    3

  • 3 Mini- Project 2

    Task was to device the controller that makes E-Puck Robot Push an obejct. Here there is no determi-

    nation condition necessary as the objective to push the object around.

    CODE THAT DOES THIS TASK IS AS FOLLOWS:

    Listing 3: Mini Project 1

    prox0 = e_get_calibrated_prox ( 0 ) ;

    prox1 = e_get_calibrated_prox ( 1 ) ;

    prox2 = e_get_calibrated_prox ( 2 ) ;

    prox3 = e_get_calibrated_prox ( 3 ) ;

    prox4 = e_get_calibrated_prox ( 4 ) ;

    prox5 = e_get_calibrated_prox ( 5 ) ;

    prox6 = e_get_calibrated_prox ( 6 ) ;

    prox7 = e_get_calibrated_prox ( 7 ) ;

    vx0=prox0 cos ( 1 . 2 7 ) ;vx1=prox1 cos ( 0 . 7 7 ) ;vx2=prox2 cos ( 0 ) ;vx3=prox3 cos ( 5 . 2 1 ) ;vx4=prox4 cos ( 4 . 2 1 ) ;vx5=prox5 cos ( 3 . 1 4 ) ;vx6=prox6 cos ( 2 . 3 7 ) ;vx7=prox7 cos ( 1 . 8 7 ) ;// Linear Combination f o r VX

    VX=(vx0+vx1+vx2+vx3+vx4+vx5+vx6+vx7 )/max ;

    vy0=prox0 s i n ( 1 . 2 7 ) ;vy1=prox1 s i n ( 0 . 7 7 ) ;vy2=prox2 s i n ( 0 ) ;vy3=prox3 s i n ( 5 . 2 1 ) ;vy4=prox4 s i n ( 4 . 2 1 ) ;vy5=prox5 s i n ( 3 . 1 4 ) ;vy6=prox6 s i n ( 2 . 3 7 ) ;vy7=prox7 s i n ( 1 . 8 7 ) ;// Linear Combination f o r VY

    VY=(vy0+vy1+vy2+vy3+vy4+vy5+vy6+vy7 )/max ;

    //Making sure maximum magnitude never goes above 1000

    \ l a b e l { r e v e r s e p o t e n t i a l }// Revers ing Charge Analogy

    S l=( i n t )(VXVY) ;i f ( Sl >1000)

    { S l =1000; }

    Sr=( i n t ) (VXVY) ;i f ( Sr >1000)

    { Sr=1000; }

    4

  • 4 Drawbacks or Incomplete of current code

    However there are certain drawbacks of not switching over to another algorithms why the robot is in

    contact with obstacle that robot will traversed the arcs of the movement.

    So to counter this it is suggested (or extended the code ) in following manner:

    Listing 4: Mini Project 1

    prox0 = e_get_calibrated_prox ( 0 ) ;

    prox1 = e_get_calibrated_prox ( 1 ) ;

    prox2 = e_get_calibrated_prox ( 2 ) ;

    prox3 = e_get_calibrated_prox ( 3 ) ;

    prox4 = e_get_calibrated_prox ( 4 ) ;

    prox5 = e_get_calibrated_prox ( 5 ) ;

    prox6 = e_get_calibrated_prox ( 6 ) ;

    prox7 = e_get_calibrated_prox ( 7 ) ;

    vx0=prox0 cos ( 1 . 2 7 ) ;vx1=prox1 cos ( 0 . 7 7 ) ;vx2=prox2 cos ( 0 ) ;vx3=prox3 cos ( 5 . 2 1 ) ;vx4=prox4 cos ( 4 . 2 1 ) ;vx5=prox5 cos ( 3 . 1 4 ) ;vx6=prox6 cos ( 2 . 3 7 ) ;vx7=prox7 cos ( 1 . 8 7 ) ;// Linear Combination f o r VX

    VX=(vx0+vx1+vx2+vx3+vx4+vx5+vx6+vx7 )/max ;

    vy0=prox0 s i n ( 1 . 2 7 ) ;vy1=prox1 s i n ( 0 . 7 7 ) ;vy2=prox2 s i n ( 0 ) ;vy3=prox3 s i n ( 5 . 2 1 ) ;vy4=prox4 s i n ( 4 . 2 1 ) ;vy5=prox5 s i n ( 3 . 1 4 ) ;vy6=prox6 s i n ( 2 . 3 7 ) ;vy7=prox7 s i n ( 1 . 8 7 ) ;// Linear Combination f o r VY

    VY=(vy0+vy1+vy2+vy3+vy4+vy5+vy6+vy7 )/max ;

    //Making sure maximum magnitude never goes above 1000

    //Revers ing Charge Analogy

    whi l e ( prox03500 | | prox 6>3500 | | prox7 >3500)

    { S l =1000; Sr=1000}

    5

  • 5 Appendix

    Listing 5: Mini-project 1 Code

    // Cont r o l l e r that l e t s the EPuck evade the Predator

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    // g l oba l v a r i a b l e s

    v o l a t i l e i n t TimerA = 0 ;

    v o l a t i l e i n t TimerB = 0 ;

    // func t i on prototypes

    i n t g e t_se l e c t o r ( ) ;

    void dumb_wait ( unsigned i n t approximate_ms ) ;

    void process_t imers ( ) ;

    // main

    i n t main ( ){

    // // VARIABLE DECLARATIONS

    //

    // Used to s t o r e the proximity r ead ings in s t r i n g format ,

    // to be sent to the UART.

    char prox_str [ 1 0 0 ] ;

    // Used to s t o r e the l ength o f s t r .

    i n t prox_str_length ;

    // Used to s t o r e the proximity r ead ings .

    i n t prox0 , prox1 , prox2 , prox3 , prox4 , prox5 , prox6 , prox7 ;

    f l o a t vx0 , vx1 , vx2 , vx3 , vx4 , vx5 , vx6 , vx7 , vy0 , vy1 , vy2 , vy3 , vy4 , vy5 , vy6 , vy7 ;

    f l o a t VX,VY;

    i n t Sl , Sr ;

    //Here the max func t i on ensure that the speed i s normal i sed with range

    // o f 1000 to 1000f l o a t max=3749/1000;

    // // INITIALIZATION

    //

    6

  • // I n i t i a l i z i n g the motor

    e_init_motors ( ) ;

    // i n t motor_speed=500;

    // I n i t i a l i z e s the por t s .

    e_init_port ( ) ;

    // I n i t i a l i z e s the analogue to d i g i t a l c onve r t e r s .

    e_init_ad_scan (ALL_ADC) ;

    // I n i t i a l i z e s the UART.

    e_init_uart1 ( ) ;

    // Opens a new page on the UART termina l .

    e_send_uart1_char ("\ f \a " , 2 ) ;

    // This func t i on must be c a l l e d be f o r e c a l l i n g

    // e_get_calibrated_prox ( ) . I t r e co rd s constant

    // read ing e r r o r o f the sensor s , which are then

    // subtracted from the raw read ings to g ive

    // c a l i b r a t e d proximity read ings .

    // Re f l e c t ed Light = Total Light Ambient Light Constant Error .e_ca l ib ra te_i r ( ) ;

    e_activate_agenda ( process_timers , 1 0 0 ) ; / / process_timer to be

    // executed every 10 ms

    e_start_agendas_process ing ( ) ;

    // // RUNNING LOOP

    // whi le (1){

    e_set_led ( 0 , 1 ) ; / / turn LED #0 ON

    // the f o l l ow i n g s t r u c tu r e g i v e s a time de lay o f 250 ms us ing a

    // so f tware t imer

    TimerA = 25;// 25 means 250 ms

    // stuck here un t i l TimerA i s c l e a r ed by process_timer in agenda

    whi l e (TimerA>0);

    e_set_led ( 0 , 0 ) ; / / turn LED #0 OFF

    TimerA = 25 ;

    whi l e (TimerA>0);

    /When an epuck keeps sending s t r i n g s through UART bus , i t cannot be programmed us ing Tiny Boot loader . We can use the s e l e c t o r to

    c on t r o l whether the epuck i s a l lowed to send s t r i n g ./

    i f ( g e t_se l e c t o r ()==2){

    // Get the read ing o f proximity s en so r s #0.

    7

  • prox0 = e_get_calibrated_prox ( 0 ) ;

    prox1 = e_get_calibrated_prox ( 1 ) ;

    prox2 = e_get_calibrated_prox ( 2 ) ;

    prox3 = e_get_calibrated_prox ( 3 ) ;

    prox4 = e_get_calibrated_prox ( 4 ) ;

    prox5 = e_get_calibrated_prox ( 5 ) ;

    prox6 = e_get_calibrated_prox ( 6 ) ;

    prox7 = e_get_calibrated_prox ( 7 ) ;

    vx0=prox0 cos ( 1 . 2 7 ) ;vx1=prox1 cos ( 0 . 7 7 ) ;vx2=prox2 cos ( 0 ) ;vx3=prox3 cos ( 5 . 2 1 ) ;vx4=prox4 cos ( 4 . 2 1 ) ;vx5=prox5 cos ( 3 . 1 4 ) ;vx6=prox6 cos ( 2 . 3 7 ) ;vx7=prox7 cos ( 1 . 8 7 ) ;// Linear Combination f o r VX

    VX=(vx0+vx1+vx2+vx3+vx4+vx5+vx6+vx7 )/max ;

    vy0=prox0 s i n ( 1 . 2 7 ) ;vy1=prox1 s i n ( 0 . 7 7 ) ;vy2=prox2 s i n ( 0 ) ;vy3=prox3 s i n ( 5 . 2 1 ) ;vy4=prox4 s i n ( 4 . 2 1 ) ;vy5=prox5 s i n ( 3 . 1 4 ) ;vy6=prox6 s i n ( 2 . 3 7 ) ;vy7=prox7 s i n ( 1 . 8 7 ) ;// Linear Combnation f o r VY

    VY=(vy0+vy1+vy2+vy3+vy4+vy5+vy6+vy7 )/max ;

    //Making sure maximum magnitude never goes above 1000

    S l=( i n t )(VXVY) ;i f ( Sl >1000)

    {

    S l =1000;

    }

    Sr=( i n t ) (VXVY) ;

    i f ( Sr >1000)

    {

    Sr=1000;

    }

    // Put prox in to a s t r i n g to send to the UART.

    prox_str_length = s p r i n t f ( prox_str , "Prox #0: %d,%d \ r \n" , Sr , S l ) ;

    e_send_uart1_char ( prox_str , prox_str_length ) ;

    }

    // i n i t i a l motor_speed=500;

    e_set_speed_left ( S l ) ; // motor speed : from 1000 to 1000e_set_speed_right ( Sr ) ; // motor speed : from 1000 to 1000

    }

    8

  • r e turn 0 ;

    //motor speeds

    }

    /This func t i on r e tu rn s the s e l e c t o r p o s i t i o n ( ranged from 0 to 15 ) .

    The number pr in ted on epuck ' s s e l e c t o r are in hexadecimal form .So po s i t i o n 10 i s wr i t t en as A.

    /i n t g e t_se l e c t o r ( ){

    re turn SELECTOR0| (SELECTOR1

  • Listing 6: Mini-Project 2 Code

    // Cont r o l l e r that l e t s the EPuck push the ob s t a c l e

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    #inc lude

    // g l oba l v a r i a b l e s

    v o l a t i l e i n t TimerA = 0 ;

    v o l a t i l e i n t TimerB = 0 ;

    // func t i on prototypes

    i n t g e t_se l e c t o r ( ) ;

    void dumb_wait ( unsigned i n t approximate_ms ) ;

    void process_t imers ( ) ;

    // main

    i n t main ( ){

    // // VARIABLE DECLARATIONS

    //

    // Used to s t o r e the proximity r ead ings in s t r i n g format ,

    // to be sent to the UART.

    char prox_str [ 1 0 0 ] ;

    // Used to s t o r e the l ength o f s t r .

    i n t prox_str_length ;

    // Used to s t o r e the proximity r ead ings .

    i n t prox0 , prox1 , prox2 , prox3 , prox4 , prox5 , prox6 , prox7 ;

    f l o a t vx0 , vx1 , vx2 , vx3 , vx4 , vx5 , vx6 , vx7 , vy0 , vy1 , vy2 , vy3 , vy4 , vy5 , vy6 , vy7 ;

    f l o a t VX,VY;

    i n t Sl , Sr ;

    //Here the max func t i on ensure that the speed i s normal i sed with range

    // o f 1000 to 1000f l o a t max=3749/1000;

    // // INITIALIZATION

    //

    // I n i t i a l i z i n g the motor

    10

  • e_init_motors ( ) ;

    // i n t motor_speed=500;

    // I n i t i a l i z e s the por t s .

    e_init_port ( ) ;

    // I n i t i a l i z e s the analogue to d i g i t a l c onve r t e r s .

    e_init_ad_scan (ALL_ADC) ;

    // I n i t i a l i z e s the UART.

    e_init_uart1 ( ) ;

    // Opens a new page on the UART termina l .

    e_send_uart1_char ("\ f \a " , 2 ) ;

    // This func t i on must be c a l l e d be f o r e c a l l i n g

    // e_get_calibrated_prox ( ) . I t r e co rd s constant

    // read ing e r r o r o f the sensor s , which are then

    // subtracted from the raw read ings to g ive

    // c a l i b r a t e d proximity read ings .

    // Re f l e c t ed Light = Total LightAmbient Light Constant Error .e_ca l ib ra te_i r ( ) ;

    e_activate_agenda ( process_timers , 1 0 0 ) ; / / process_timer to be

    // executed every 10 ms

    e_start_agendas_process ing ( ) ;

    // // RUNNING LOOP

    // whi le (1){

    e_set_led ( 0 , 1 ) ; / / turn LED #0 ON

    // the f o l l ow i n g s t r u c tu r e g i v e s a time de lay o f 250 ms us ing a

    // so f tware t imer

    TimerA = 25;// 25 means 250 ms

    // stuck here un t i l TimerA i s c l e a r ed by process_timer in agenda

    whi l e (TimerA>0);

    e_set_led ( 0 , 0 ) ; / / turn LED #0 OFF

    TimerA = 25 ;

    whi l e (TimerA>0);

    /When an epuck keeps sending s t r i n g s through UART bus , i t cannot be programmed us ing Tiny Boot loader . We can use the s e l e c t o r to

    c on t r o l whether the epuck i s a l lowed to send s t r i n g ./

    i f ( g e t_se l e c t o r ()==2){

    // Get the read ing o f proximity s en so r s #0.

    11

  • prox0 = e_get_calibrated_prox ( 0 ) ;

    prox1 = e_get_calibrated_prox ( 1 ) ;

    prox2 = e_get_calibrated_prox ( 2 ) ;

    prox3 = e_get_calibrated_prox ( 3 ) ;

    prox4 = e_get_calibrated_prox ( 4 ) ;

    prox5 = e_get_calibrated_prox ( 5 ) ;

    prox6 = e_get_calibrated_prox ( 6 ) ;

    prox7 = e_get_calibrated_prox ( 7 ) ;

    vx0=prox0 cos ( 1 . 2 7 ) ;vx1=prox1 cos ( 0 . 7 7 ) ;vx2=prox2 cos ( 0 ) ;vx3=prox3 cos ( 5 . 2 1 ) ;vx4=prox4 cos ( 4 . 2 1 ) ;vx5=prox5 cos ( 3 . 1 4 ) ;vx6=prox6 cos ( 2 . 3 7 ) ;vx7=prox7 cos ( 1 . 8 7 ) ;// Linear Combination f o r VX

    VX=(vx0+vx1+vx2+vx3+vx4+vx5+vx6+vx7 )/max ;

    vy0=prox0 s i n ( 1 . 2 7 ) ;vy1=prox1 s i n ( 0 . 7 7 ) ;vy2=prox2 s i n ( 0 ) ;vy3=prox3 s i n ( 5 . 2 1 ) ;vy4=prox4 s i n ( 4 . 2 1 ) ;vy5=prox5 s i n ( 3 . 1 4 ) ;vy6=prox6 s i n ( 2 . 3 7 ) ;vy7=prox7 s i n ( 1 . 8 7 ) ;// Linear Combnation f o r VY

    VY=(vy0+vy1+vy2+vy3+vy4+vy5+vy6+vy7 )/max ;

    //Making sure maximum magnitude never goes above 1000

    S l=( i n t ) (VX+VY) ;

    i f ( Sl >1000)

    {

    S l =1000;

    }

    Sr=( i n t )(VX+VY) ;

    i f ( Sr >1000)

    {

    Sr=1000;

    }

    // Put prox in to a s t r i n g to send to the UART.

    prox_str_length = s p r i n t f ( prox_str , "Prox #0: %d,%d \ r \n" , Sr , S l ) ;

    e_send_uart1_char ( prox_str , prox_str_length ) ;

    }

    // i n i t i a l motor_speed=500;

    e_set_speed_left ( S l ) ; // motor speed : from 1000 to 1000e_set_speed_right ( Sr ) ; // motor speed : from 1000 to 1000

    }

    12

  • r e turn 0 ;

    //motor speeds

    }

    /This func t i on r e tu rn s the s e l e c t o r p o s i t i o n ( ranged from 0 to 15 ) .

    The number pr in ted on epuck ' s s e l e c t o r are in hexadecimal form .So po s i t i o n 10 i s wr i t t en as A.

    /i n t g e t_se l e c t o r ( ){

    re turn SELECTOR0| (SELECTOR1