LEGO MINDSTORMS - The Unofficial Guide to Robots - Jonathan B. Knudsen Part 12

Tham khảo tài liệu 'lego mindstorms - the unofficial guide to robots - jonathan b. knudsen part 12', kỹ thuật - công nghệ, cơ khí - chế tạo máy phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 210 When arbitrate has determined the motor command it uses motor_control to interpret the command and to actually set the direction and speed of the outputs. This design is very similar to the design of the NQC RoboTag program from Chapter 9. The cruise behavior is simple it just sets its command variable to COMMAND_FORWARD ad infinitum. The next behavior seek_enlightenment is not so simple. The basic idea however goes like this if I m seeing darker stuff than I ve just been seeing look to either side for something brighter seek_enlightenment implements this with the idea of a baseline. The initial baseline is taken straight from the light sensor reading baseline process light SENSOR 2 The behavior then enters an endless loop examining the value of the light sensor. If it falls too far below the baseline seek_enlightenment asserts control and searches for brighter light current process light SENSOR 2 if current baseline - FUDGE To search for brighter light seek_enlightenment first sets a new baseline from the current light value baseline current Then the robot turns left or right more or less randomly using the system clock if sys time 2 0 seek command COMMAND LEFT else seek_command COMMAND_RIGHT A helper function wait_for_better is used to wait for a brighter light than the new baseline result wait for better baseline 1000 It s entirely possible that the robot will not find any brighter light. In this case it times out after 1000 milliseconds and returns -1. In this case the robot will turn back in the opposite direction and search for brighter light if result -1 if seek_command COMMAND_LEFT seek_command COMMAND_RIGHT else if seek_command COMMAND_RIGHT seek_command COMMAND_LEFT The wait_for_better helper function is again used with a longer timeout result wait for better baseline 2000 211 In either search if a better value is found it is used as the new baseline if result -1 baseline result else baseline result That s the basic algorithm. There is one extra .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.