ライントレース

ライントレース

彼は、目標を自分で探して進みます。
  
彼は、物を見る目が一つしかないので右と左の区別ができません。

下しか見ないので、 周りの状況も見えません。

床が滑るので、パソコンの中のキャラクターの様に
正確な位置や角度を知ることもできません。
 

しかし

プログラミングで 目標を探す方法を教えて上げると・・・・・

彼は、目標を自分で探して進みます。

ソースコード

generated by mBlock5 for codey & rocky
 codes make you happy
 import codey, event, rocky, time
 initialize variables
 R_count = 0
 F_speed = 0
 F_time = 0
 R_Angle = 0
 R_error = 0
 R_increase = 0
 @event.start
 def on_start():
     global R_count, F_speed, F_time, R_Angle, R_error, R_increase
     codey.display.show_image("00003c7e7e3c000000003c7e7e3c0000")
     codey.speaker.play_melody('hi.wav')
 @event.received('Lost')
 def on_received():
     global R_count, F_speed, F_time, R_Angle, R_error, R_increase
     R_count = 10
     while True:
         for count in range(int(R_count)):
             rocky.turn_right_by_degree(R_Angle)
             if rocky.color_ir_sensor.is_color('red'):
                 rocky.turn_right_by_degree(R_Angle)
                 codey.broadcast('find')
                 rocky.stop()
                 codey.stop_this_script()
     rocky.forward(1, 0.2, straight = True)     R_count = (R_count + R_increase)     R_count = (R_count + 5)     for count2 in range(int(R_count)):         rocky.turn_left_by_degree(R_Angle)         if rocky.color_ir_sensor.is_color('red'):             rocky.turn_left_by_degree(R_Angle)             codey.broadcast('find')             rocky.stop()             codey.stop_this_script()     R_count = (R_count + R_increase)
 @event.received('Stop')
 def on_received1():
     global R_count, F_speed, F_time, R_Angle, R_error, R_increase
     rocky.stop()
     codey.stop_all_scripts()
 @event.button_a_pressed
 def on_button_a_pressed():
     global R_count, F_speed, F_time, R_Angle, R_error, R_increase
     F_speed = 3
     F_time = 0.2
     R_Angle = 2
     R_increase = 10
     R_error = 5
     rocky.forward(F_speed, F_time, straight = True)
     if rocky.color_ir_sensor.is_color('red'):
         codey.broadcast('find')
         codey.stop_this_script()
 else:     rocky.forward(F_speed, F_time, straight = True)     rocky.forward(F_speed, F_time, straight = True)     codey.broadcast('Lost')     codey.stop_this_script()
 @event.button_c_pressed
 def on_button_c_pressed1():
     global R_count, F_speed, F_time, R_Angle, R_error, R_increase
     codey.broadcast('Stop')
 @event.received('find')
 def on_received2():
     global R_count, F_speed, F_time, R_Angle, R_error, R_increase
     while True:
         rocky.forward(F_speed, F_time, straight = True)
         if rocky.color_ir_sensor.is_color('red'):
             rocky.forward(F_speed, F_time, straight = True)
     else:         rocky.stop()         codey.broadcast('Lost')         codey.stop_this_script()
よかったらシェアしてね!

コメント

コメントする

目次