Robo Tracker

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

 

Problem Description

RoboTracker program came about from discussions about the Lego MindstormsTM robotics system.  It's neat but kind of expensive in my view.  I'll bet someone that I could write a Delphi robot program to simulate Lego's RoboTracker in less than 50 lines of code.    

Background & Techniques

Version 1, TrackEater, took about 30 lines of code, not counting comment lines.  I call it TrackEater because that's what it does.  Actually it doesn't have a redraw routine to put the track back after the robot passes over it, so the track disappears. 

It is a good introduction to exit events.  The user holds down a mouse button and drags it around to form a track, then presses the Start button to have the robot follow it.   There are separate methods for OnMouseDown, OnMouseMove and OnMouseUp events.  The MouseDown procedure sets a flag to tell the MouseMove routine that we're drawing, it also does some initialization stuff like setting a nice fat  pen we'll use for drawing the track.    MouseMove  draws a line from the last point to the current point.  It also waits for 10ms so that we won't create more than about 100 points per second of drawing.   MouseUp resets the flag and moves the robot to the beginning point. 

When the Start button is pressed, (creating an OnClick event),  we just start moving the  robot point by point to retrace the steps.   The same 10ms delay is inserted between moves so it should move about as fast as the original line drawing speed.    The only tricky thing about positioning the robot is that we want to center it on the track.  All references to locations are by the top left corner though so we subtract half the width and half the height of the robot from the current point to get a location for its top left corner.

A second version is included in the source download.  It has a OnPaint routine to redraw the track after the robot moves over it and a few other enhancements that I'll leave for you to check out on your own.   

Running/Exploring the Program 

bulletBrowse source extract
bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

My next version will have a pair of eyeballs that rotate to point in the current movement direction.   It should involve a little trigonometry to figure out the direction of movement, then a line at right angles to form the center line of the eyeballs.  
Robo could be made to loop continuously by going back to point 1 and starting over.  In that case we'd need a Stop button too. 
The current implementation is not a very close approximation of the way the Lego robot operates.  It has two light sensors as I recall and when one sees light and one sees dark, it turns toward the dark one to get back on track.  The Canvas object used for all of these drawing operations has a Pixels  property that will let us test the color of every position on the canvas.  Pixels would allow us to make a closer simulation of the Lego real-life version.    
 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby    All rights reserved.