C:\> Rostislav Persion's Projects

.:: Motion Sensing Robot ::.
Robot that detects motion and runs away






This project is a robot that runs away from people while playing music. As of now I did not yet make the robot run away. For now it runs a demo program to demonstrate mobility. I am currently in the process of 3D printing blinders for the motion sensors. I am also waiting for the sound boards to arrive.



DOWNLOAD VIDEO






  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
  #include <servo-01.h>
   
  // SENSORS
  int front_sensor()
  {
     int ret = 0;
     if(input(pin_A0) == 1) {ret = 1;}
     else {ret = 0;}
     return ret;
  }
   
  int right_sensor()
  {
     int ret = 0;
     if(input(pin_A1) == 1) {ret = 1;}
     else {ret = 0;}
     return ret;
  }
   
  int rear_sensor()
  {
     int ret = 0;
     if(input(pin_A2) == 1) {ret = 1;}
     else {ret = 0;}
     return ret;
  }
   
  int left_sensor()
  {
     int ret = 0;
     if(input(pin_A3) == 1) {ret = 1;}
     else {ret = 0;}
     return ret;
  }
   
  // MOTOR CONTROL
  void left_servo_backward()
  {
        for (int i=0;i<3;i++)
        {
           output_high(PIN_B7);
           delay_us(500);
           output_low(PIN_B7);
           delay_us(19500);
        }
  }
   
  void left_servo_forward()
  {
        for (int j=0;j<3;j++)
        {
           output_high(PIN_B7);
           delay_us(2500);
           output_low(PIN_B7);
           delay_us(17500);
        }
  }
   
  void right_servo_backward()
  {
        for (int j=0;j<3;j++)
        {
           output_high(PIN_B6);
           delay_us(2500);
           output_low(PIN_B6);
           delay_us(17500);
        }
  }
   
  void right_servo_forward()
  {
        for (int i=0;i<3;i++)
        {
           output_high(PIN_B6);
           delay_us(500);
           output_low(PIN_B6);
           delay_us(19500);
        }
  }
   
  // MOTION CONTROL
  void go_forward(int amount)
  {
     for(int i=0;i<amount;i++)
     {
        left_servo_forward();
        right_servo_forward();
     }
  }
   
  void go_backward(int amount)
  {
     for(int i=0;i<amount;i++)
     {
        left_servo_backward();
        right_servo_backward();
     }
  }
   
  void turn_left(int amount)
  {
     for(int i=0;i<amount;i++)
     {
        left_servo_backward();
        right_servo_forward();
     }
  }
   
  void turn_right(int amount)
  {
     for(int i=0;i<amount;i++)
     {
        left_servo_forward();
        right_servo_backward();
     }
  }
   
  // AUDIO
  void play_music()
  {
     output_high(PIN_B0);
     delay_ms(100);
     output_low(PIN_B0);
  }
   
  // MAIN LOOP
  void main()
  {
     setup_lcd(LCD_DISABLED);
     
     
     set_tris_a(0b11111111); // PORTA input
     set_tris_b(0b00000000); // PORTB output
   
     delay_ms(5000); // WAIT FOR SENSORS TO CLEAR
   
     while(TRUE)
     {
     
        /*
        if(front_sensor() == 1)
        {
           play_music();
           go_backward(50);
           delay_ms(5000);
        }
        if(rear_sensor() == 1)
        {
           play_music();
           go_forward(50);
           delay_ms(5000);
        }
        if(left_sensor() == 1)
        {
           play_music();
           turn_right(8);
           go_forward(50);
           delay_ms(5000);
        }
        if(right_sensor() == 1)
        {
           play_music();      
           turn_left(8);
           go_forward(50);
           delay_ms(5000);
        }
        */
        
        // DEMO 01
        turn_left(32);
        turn_right(32);
        delay_ms(1000);
        
        // DEMO 02
        go_forward(20);
        go_backward(20);
        turn_right(8);
        turn_left(8);
        turn_left(8);      
        turn_right(8);
        delay_ms(1000);
        
        // DEMO 03
        go_forward(20);
        turn_left(8);
        go_forward(20);
        turn_left(8);
        go_forward(20);
        turn_left(8);
        go_forward(20);
        turn_left(8);
        delay_ms(1000);
     
   
     }
   
  }