Hide and Seek Robot...
 
Notifications
Clear all

Hide and Seek Robots - Request for Comments

Page 5 / 5

THRandell
(@thrandell)
Trusted Member
Joined: 1 year ago
Posts: 90
Topic starter  

@frogandtoad

I think that I owe you an explanation of my melodious robots.

So, I’m a big fan of Pololu Electronics.  I’ve learned a lot about programming the ATmega32U4 and ATmega328P from reading their libraries.  So this solution is specific to those chips and the Arduino IDE.  If you’re still interested you can find their stuff on Github.  I’m using an  ATmega32U4 based board so the library uses Timer 4 and pin 6 to control the output.  Which in my case is a piezo buzzer.  In my experiments I found that the range of tones and volume is greater when compared to the Arduino solution.  The tone sequences are represented by musical notation with syntax that is similar to the Gw-Basic play command.  One nice thing about their implementation is that the sequences can be stored in program memory to save RAM.

Anyway, I wrote a Cruise behavior for one of my robots and I thought that it would be fun to play some Cruise music from the film ‘American Graffiti’ while that behavior had control.  I searched for sheet music on the web for a few tunes, eg Johnny B. Goode, and transcribed the songs into the Pololu notation.  Here’s what I came up with:

 

// Daisybel
const char daisybel[] PROGMEM = 
         "! L4 T200 O4 V10 >d2.b2.g2.d2.  ef#g  e2g  d2.d2r  a2.>d2.b2.g2.  ef#g  a2b a2.arb "
         ">cba >d2b ag2g2a b2g e2g ed2.rd g2b a2r g2b ab>c >dbg a2d g2.";
// Ya Ya
const char yaya[] PROGMEM = 
         "! L4 T120 O4 V10 rcdf16d16c8 d8f8ffd8c8 d8f8f8d8fd8c8 frrr8d8 frrr8>e8 >d8>d8>caf8f8 g8f8f8d8fg8d8 "
         "frrr8d8 frrr8d8 ega8g8g8c8 d8f8f8d8g8f8f8d8 frrr8d8 frrr";
// Surf City         
const char surfcity[] PROGMEM = 
        "! L4 T120 O5 V10 e-.e-.e- c2d2 <b1 <brr8g8g8g8 a8a8ge8d8c8<a8 <a8c8c8dc. ree8e. e8ee8r8 "
        "g8g8g8 ag8g8e8d8c8<a8 <a8c8c8c8d8c. ree8e. e8ee8re8e8 ff8f8g8f8f8f8 e8dd8d2 f8f8ff8f8f8f8 a8gg2."; 
// Johnny B. Goode
const char johnnybgoode[] PROGMEM = 
        "! L4 T140 O5 V10 rrr8<a8c8d8 f8f8f8f8f8e-8d8c8 <g#8<a8<f8<d8<f8<d8<f8<g8 <a-8<a-8<g8<f8<a-8<a-8<g8<f8 "
        "r2rr8c c8c8c8c8c8<a8<b-8<a8 <b-8<ac.r8c8 c8c8c8c8c8<a8<b-8<a8 <b-8<a<f.r8c8 "
        "c8<a-8<b-<b-8<a-8<b-8<a-8 <b-8<a-c.r8c8 c8c8c8<a8c<b-8<a8 <b-8<a8<f8<f.r8c8 c8<a8<b-8<a8<b-8<a8<b-8<a8 "
        "<b-<a8c<f8<a8<b-8  c8c8c8c<a8<b-8<a8 <b-8<a8<g8<f."; 
// Do You Want to Dance
const char doyouwanttodance[] PROGMEM = "! L4 T120 O4 V10 r>c2>c8>c8 "
        ">ca8a.a gg8a.r a.aaa8 gg8ag8a a.f8f2 rf8a8g.f8 f1 r>c2>c8>c8  "
        ">ca8a.a gg8a.r a.aaa8 gg8ag8a a.f8f2 rf8a8g.f8 f1 r>cb-2 "
        ">ca8aa8a g8ag8ag raa2 g8ag8ag a2f2  f8a8gf8f."; 
// Love Potion Number 9
const char lovepotionnumber9[] PROGMEM = 
        "! L4 T100 O4 V10 r8b8b8b8b8b8b8b8 ae8g.r r8b8b8b8b8b8b8b8 ae8g.r de8d8ga8g8 b8a8g8d8er e8e8g8e8g8g8a rba8g8e8d8 e1 r1 "
        "r8b8b8b8b8b8b8b8 ae8g.r r8b8b8b8b8b8b8b8 ae8g.r de8d8ga8g8 b8a8g8d8er e8e8g8e8g8g8a rba8g8e8d8 e1 r2rr8g8 "
        "aa8g8a8g8a8g8 a8g8e8a.r8e8 f#8e8f#8e8f#8e8f#8e8 f#8e8c#8f#.r8g#8 a8g8a8g8a8g8a8g8 a8g8e8a.r8b8 b8b8b8b8b8b8b8r8 ";

 

 In this robot’s program I treated the motors and the buzzer both as actuators.  So when a behavior wants its motor commands to be executed it asks for CONTROL else it will PUNT.  When a behavior wants to run its tune it asks to PLAY else it will PASS.  Clear as mud?

 

 

void cruise() {

  behavior(CRUISE_ID);
  static unsigned long cruise_time = 0;
  static unsigned char state = 0;
  static signed int cruise_angle = 0;
  static signed int cruise_speed = 0;                         

  
  if (latest_winner != CRUISE_ID) {  
    state = 0;
    cruise_speed = 0;
  }
  
  switch(state)
   {
     case 0:  
       cruise_speed += pc_incr;              
       drive_angle(0, cruise_speed);    
       if (cruise_speed >= pg_speed)
         state++;
       CONTROL;                               
       break;
     case 1:
       cruise_time = millis() + pc_dur;         
       cruise_angle = ((rand() % 3) - 1);        
       drive_angle(cruise_angle, pg_speed);
       state++;
       CONTROL;
       if (buzzer.isPlaying()) {
         PASS;
       }
       else {
         tune_number(rand()%256);  
         PLAY;
       }
       break;
     default:              
       if (millis() >= cruise_time) 
         state = 1;  
       CONTROL;
       PASS;    
       break;
   }

}

 

 

Tom


Ron liked
ReplyQuote
Ron
 Ron
(@zander)
Noble Member
Joined: 2 years ago
Posts: 2262
 

@thrandell Very cool, and dam you, now I have another thing to check out!!!!

It is considered poor judgement to traverse a chasm in 2 leaps.


Inst-Tech liked
ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 3 years ago
Posts: 1213
 

@thrandell

Posted by: @thrandell

@frogandtoad

I think that I owe you an explanation of my melodious robots.

No problem Tom, and thanks for the information.

I find this stuff very fascinating reading and thus learning.

Cheers


ReplyQuote
THRandell
(@thrandell)
Trusted Member
Joined: 1 year ago
Posts: 90
Topic starter  
Posted by: @zander

Very cool, and dam you, now I have another thing to check out!!!!

Your comment got me thinking about the Raspberry Pi Pico and that maybe I need to join the world of low voltage MCUs.  All of the sensors and motor controllers that I use in my robots accept 3.3V, so why not?  I could start by porting my existing toolkit of C sketches.  It's food for thought anyway.

 

Tom


ReplyQuote
Ron
 Ron
(@zander)
Noble Member
Joined: 2 years ago
Posts: 2262
 

@thrandell However if you need WiFi you will need to mount the pico in a holder and add an ESP01.

Here is a picture of one that Bill recently used or similar with the ES01 attached (pencil points at it. The problem is of cource this is a much bigger board, 3.5" x 2.5" (with WiFi board over 10cm by 70)

I suspect there are other choices in the ESP family with WiFi, low power and possibly 5V -> 3.3V LDO built in.

Personally I would check the esp3 family first, it's the latest from espressif.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
THRandell
(@thrandell)
Trusted Member
Joined: 1 year ago
Posts: 90
Topic starter  
Posted by: @zander

However if you need WiF

Nope.


Ron liked
ReplyQuote
Ron
 Ron
(@zander)
Noble Member
Joined: 2 years ago
Posts: 2262
 

@thrandell Then the PICO will be great, keep us informed of progress.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
Page 5 / 5