Pages: [1] 2   Go Down
Author Topic: BBC Turtle Clone?  (Read 2586 times)
0 Members and 1 Guest are viewing this topic.
Kent, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Guys

Many years ago when I was at school, we were taught to use a robot that used a pen to draw geometric shapes on paper.  It was programmed using a BBC Micro computer and the robot was called Turtle (as that's what it resembled).

I would like to create a similar robot for my daughter that has the same or similar programming language.  It was almost like BASIC where simple scripts could be written and sent to the robot.  Such as

Code:
PD
FD 120
LT 90
FD 120
PD
FD 120
LT 90
FD 120
PU
HOME

Would draw a square.

I have tried googling around but am finding surprisingly little on it.  It seems like the sort of thing that someone would have made with the arduino.  However, I see no obvious example.  There are a lot of drawing robots that seem to be more about artistic drawing, rather than designed to teach very basic 'programming' commands.

So has anyone come across a project like this?  The robot is simple enough to build.  But I would rather not spend time developing the scripting side of things if someone has already done it. 

Would appreciate your views.
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 48
Posts: 3402
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The language used is Logo - not a good choice in hindsight - googling arduino & logo brings back a bunch of useless hits.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You would just send it those kinds of commands from the serial monitor, and have the robot receive and save them, then run them when it got a "go" command?
Looks like you have
Pen Down
Pen Up
Left Turn degrees
Right Turn degrees
Forward distance
would there be Reverse distance?
Home - not sure what that does.

That would be straightforward to implement in Arduino code, maybe something like this, flesh out the motor command parts
Code:
if (Serial.available()>1){ // start of message?
iC[0] = Serial.read(); // iC[] = incoming Command array
iC[1] = Serial.read();

// pen up or down
   if (iC[0] == 'P'){
       if (iC[1] == 'D'){
       valid = 1; // good command received
       // command motor/servo/stepper whatever to put pen down
       }
      if (iC[1] == 'U'){
       valid = 1; // good command received
      // command motor/servo/stepper whatever to pick pen up
       }
   }
// left turn
  if (iC[0] =='L' and iC[1] == 'T'){
  // wait for degrees to come in, must be 3 digits
   while (Serial.available()<3){
   ic[2] = Serial.read() - 0x48; // read ASCII and convert to a number
   ic[3] = Serial.read() - 0x48; // read ASCII and convert to a number
   ic[4] = Serial.read() - 0x48; // read ASCII and convert to a number
   degrees = ic[2]*100 + ic[3]*10 + ic[4]; // convert to 0 to a number
    valid = 1; // good command received
   // send motor command to turn/spin left the number of degrees commanded
   }
// right turn
  if (iC[0] =='R' and iC[1] == 'T'){
  // wait for degrees to come in, must be 3 digits
   while (Serial.available()<3){
   ic[2] = Serial.read() - 0x48; // read ASCII and convert to a number
   ic[3] = Serial.read() - 0x48; // read ASCII and convert to a number
   ic[4] = Serial.read() - 0x48; // read ASCII and convert to a number
   degrees = ic[2]*100 + ic[3]*10 + ic[4]; // convert to 0 to a number
    valid = 1; // good command received
   // send motor command to turn/spin right the number of degrees commanded
   }
// forward
  if (iC[0] =='F' and iC[1] == 'D'){
  // wait for distance to come in, must be 3 digits
   while (Serial.available()<3){
   ic[2] = Serial.read() - 0x48; // read ASCII and convert to a number
   ic[3] = Serial.read() - 0x48; // read ASCII and convert to a number
   ic[4] = Serial.read() - 0x48; // read ASCII and convert to a number
   distance = ic[2]*100 + ic[3]*10 + ic[4]; // convert to a distance
   valid = 1; // good command received
   // send motor command to go forward some distance
   }
// backward
  if (iC[0] =='B' and iC[1] == 'K'){
  // wait for distance to come in, must be 3 digits
   while (Serial.available()<3){
   ic[2] = Serial.read() - 0x48; // read ASCII and convert to a number
   ic[3] = Serial.read() - 0x48; // read ASCII and convert to a number
   ic[4] = Serial.read() - 0x48; // read ASCII and convert to a number
   distance = ic[2]*100 + ic[3]*10 + ic[4]; // convert to a distance
    valid = 1; // good command received
   // send motor command to go backward some distance
   }
// Home
  if (iC[0] =='H' and iC[1] == 'M'){
   valid = 1; // good command received
   // send motor command to go do whatever "home" means
   }
if (valid == 0){
Serial.print("invalid command received ");
Serial.print(ic[0]);
Serial.println(ic[1]);
}
valid = 0; // clear flag for next pass
} // end Serial.available check


Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Belgium
Offline Offline
Edison Member
*
Karma: 58
Posts: 1729
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@CrossRoads
For someone who claims not to be good at programming that is a really nice piece of code.
Best regards
Jantje
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Jantje.  smiley
I don't find simple manipulation of minimal serial data to be difficult. 5 bytes, not many options, not much there.
Now, if the degrees or distance was allowed to be 1,2, or 3 digits, that would certainly complicate things smiley-cool

I do find following other people's uncommented cryptic C/C++ code to be difficult to follow. I just glaze over looking at it sometimes.


Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I was thinking using switch:case would run faster, without have 5 or 6 sets of if:then statements to go thru.
I don't know how to define cases based on two array elements tho.
Somehow make a variable
command = iC[0] + ic[1];
then use that for the cases.
Probably simple, I've just never done that:
Code:
switch(command){
case 'PD':
//
break;
case 'PU':
//
break;
//etc.
}
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Belgium
Offline Offline
Edison Member
*
Karma: 58
Posts: 1729
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

rofl
many programmers don't make a distinction between char ' and char array " when defining constants. When you do I see that as an indication of quality. Moreover  the code is readable and well documented. It shows knowledge of arrays and string to value conversion.

Switch Case does not support string comparison. If you want to do something with 2 chars you would have to do something like 'a'*FF+'b'.
Not a pretty sight. So if then else is the best option I know.

Quote
Now, if the degrees or distance was allowed to be 1,2, or 3 digits,
not really just change
Code:
degrees = ic[2]*100 + ic[3]*10 + ic[4]; // convert to 0 to a number
to something like:
Code:
degrees=0;
for(int curChar=2;curChar<numsChar;curChar++) degrees=degrees*10+ic[curChar];

Best regards
Jantje

Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

for(int curChar=2;curChar<numsChar;curChar++) degrees=degrees*10+ic[curChar];

See, now it gets messy. Have to figure out to stop waiting for more digits to come in;
numsChar = sizeof[ic] or whatever that syntax is;
looks like something else is needed to catch the 100's place.
That kind of variability is  hard to write for.
Writing for fixed constraints is much easier.

Quote
Switch Case does not support string comparison
See, that would have been handy to have!
Now, one would have to convert each command: PU, PD, RT, LT, FD, BK, HM into a number and then do switch:case on the number.
Or: change the command to make each one start with a unique letter and do switch:case on a single letter.
'U' P up pen
'D' P down pen
'R' T right turn
'L' T left turn
'F' D forward
'B' K backward
'H' M home
in which case, just single letter commands could be used, making things simpler still.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Kent, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey

Thanks guys.  This is the germ of an idea in my mind, but I very much appreciate the code examples.  I'm very new to coding myself and agree about uncommented sketches.  It took me days working about a very simple shift register example that was included with the library!

Still, I'll spend some time planning out the hardware.
Logged

Chicago
Offline Offline
Sr. Member
****
Karma: 5
Posts: 456
With every answer comes more questions.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's awesome. I remember using LOGO back in grade school!

Hey, if it helps, or if anyone wants to play with it...I just found this -
http://www.transum.org/software/logo/
- an online LOGO emulator.

I just wasted about 30 mins playing around on it! smiley-lol
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you need a motor driver, you could check out these boards
http://www.dipmicro.com/store/L298N-MOD
http://www.ruggedcircuits.com/html/basic_motor_driver.html
http://www.ruggedcircuits.com/html/rugged_motor_driver.html
and the choices & chassis here
http://www.pololu.com/
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Kent, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I have been browsing around and researching my options.  I think CrossRoads was correct about using the Pololu 3pi style robot for this project.  For it to work just like the original Turtle, the pen will have to be dead centre and the robot will have to rotate exactly around that point.  Ultimately I think I would enjoy designing the robot's chasis and specs.  So I'm thinking about getting a kit robot to test ideas and learn what I need in the final design.

What do you guys think about these ultra-cheap kits from China:

http://www.ebay.co.uk/itm/171056734576 ?

I'm thinking for testing it will work out fine.  Or should I double my money and go for something like this:

http://www.ebay.co.uk/itm/130936585418

Views welcome
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Your call.
How expandable are they if you decide to make something more out of it?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How will you mount the pen dead center and have room to move it up & down if the control  boards are there?
Maybe mount the control boards vertically instead of laying flat on the chassis?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Kent, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The pen setup would have to be the first thing installed.  Everything else would be built around it.
Logged

Pages: [1] 2   Go Up
Jump to: