Thanks so much for this short program! My question is, what is the logic behind defining kp as 20? and how does it work. Any explanation would be helpful. Also, is it possible for the robot to know how far it is from the ir beacon solely from signal strength? Thanks.

Wed Feb 04, 2015 1:57 am

MHTS

Guru

Joined: Sun Nov 15, 2009 5:46 amPosts: 1523

Re: IR code for tetrix

rkage wrote:

Thanks so much for this short program! My question is, what is the logic behind defining kp as 20? and how does it work. Any explanation would be helpful. Also, is it possible for the robot to know how far it is from the ir beacon solely from signal strength? Thanks.

The code is a classic Proportional-only control (part of PID control). You can google PID control to learn more about it. But essentially, it is a close-loop control system where it says the power to the motor should be proportional to how far you are from target. If you are far away from your target, you run the motor full speed. If you become closer and close, the "error" is smaller and smaller and the motor power becomes smaller as well (i.e. you go slower when you are about to reach target). So in this case, the target is the direction of the IR beacon (being zone 5). If the robot is way off target (e.g. zone 9), the error is then 9 - 5 = 4. So if you use this error value to determine the difference in power between the left and right wheel, you can make the robot turn to minimize error. But power difference of 4 is not enough to turn the robot, therefore, we need a scale factor and hence Kp. If Kp is 20, then the power difference would be 80. That will be more than enough to turn the robot towards the IR beacon. As the robot turns (i.e. the reading becomes, 8, then 7, then 6, for example), the error now becomes 6 - 5 = 1 and multiplied by Kp (20) that gives you a power difference between the wheels down to 20. As you can see the turning slowed down. When you final get a reading 5, the error becomes zero, the power difference between left and right wheel is now zero. So the robot is in theory aligned with the IR beacon.Reading the IR strength will give you an indication whether you are getting closer to the IR beacon but it is difficult to translate that information to absolute distance to the beacon because the signal strength is affected by the battery level of the beacon as well as the sensitivity of your IR seeker.

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum