Shop OBEX P1 Docs P2 Docs Learn Events
ActivityBot Mode Select with RST Button — Parallax Forums

ActivityBot Mode Select with RST Button

edited 2013-10-01 12:03 in Learn with BlocklyProp
This program makes it easy to select between more than one different ActivityBot behavior. To advance from one mode to the next, just press and release the RST button.

Mode 0 just blinks the Activity Board's P26 and P27 lights.
Mode 1 goes forward slowly
Mode 2 goes quickly
Mode 3 does a forward, right, left, backward maneuver.

The code below is just a simple example that shows how each mode can have a different behavior. Expand these as much as you like, you can even add all the functional code from a few different ActivityBot Tutorial example programs and have a cool little configurable demo bot.

ActivityBot Tutorials
http://learn.parallax.com/activitybot

How it Works
The program starts by reading a value from the 2nd to last byte in the ActivityBoard's EEPROM memory, adds 1 to it, and writes the new value back to the same address for the next time. Then, it uses byte %= 4 to divide 4 into the byte value and get the remainder. This value can be 0, 1, 2, or 3 for a total of four modes. You can set the number of modes by changing the byte %= 4 line. For example, if you change it to byte %= 3, you will have three modes instead (0, 1, 2). Just make sure that your code decides what to do with all the modes.
#include "simpletools.h"            // Library includes         
#include "abdrive.h"

int main()                          // Main function
{
  int byte = ee_getByte(32768);     // Get a byte from EEPROM
  ee_putByte(byte + 1, 32768);      // Add 1, put back for next time
  byte %= 4;                        // Result in 0...3 range.

  set_outputs(27, 26, byte);
  set_directions(27, 26, 0b11);     // Lights indicate mode
  
  if(byte == 0)                     // Mode 0?  
  {
    while(1)                        // Lights display up-count
    {
      set_outputs(27, 26, byte++);
      pause(100);
    }
  }
  else if(byte == 1)                // Mode 1?
  {
    drive_speed(32, 32);            // Forward slowly
  }
  else if(byte == 2)                // Mode 2?
  {
    drive_speed(128, 128);          // Fast forward
  }
  else if(byte == 3)                // Mode 3?
  {
    drive_goto(128, 128);           // Forward 128
    pause(200);                     // Pause 2/10 second
    drive_goto(64, -64);            // Right 64
    pause(200);                     
    drive_goto(-64, 64);            // Left 64
    pause(200);
    drive_goto(-128, -128);         // Backward 128
    pause(200);
  }
}

Comments

  • dgatelydgately Posts: 1,630
    edited 2013-10-01 10:07
    Great idea!

    Brings up a question, though... :innocent:

    With the ActivityBot calibration data being stored in eeprom and this 1 byte data being stored, is there an address that I should use for storing my Compass calibration data? I don't want my compass data to overwrite other learn.parallax.com tutorial stored bits. I'll probably want to store a few longs worth of latitude, longitude and Magnetic declination data.


    Thanks,
    dgately
  • edited 2013-10-01 10:49
    Hi dgately,

    The ActivityBot currently uses 63418....65460 for ActivityBot calibration settings. Shrinking that is near the top of my hit list for reducing memory consumption. We haven't released it yet, but compass calibration is slated for 65478...65504.

    Our plan is to always prominently display EEPROM dependencies in library documentation. For example, check out the Macros section near the start of ...Documents/SimpleIDE/Learn/Simple Libraries/ActivityBot/Documentation abdrive Library.html.

    jazzed recommended an index, kind of like a one stop shop where library factoids like this can be found. We wholeheartedly agree. By adding EEPROM usage as #defines and documenting them in the header comments (which are auto-generated into the html docs), it'll help ensure that there is something crawlable for an indexing feature.

    Andy
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-10-01 10:54
    This is a good idea! (actually 2 good ideas!)

    Can the libraries provide a variable (user_EEPROM_Start) that marks the spot where it is safe for Users to start using it?

    Or just have a "gentleman's agreement" that's documented someplace - 0x8000-0x8100 reserved for libraries
  • edited 2013-10-01 11:06
    Oh, yeah, I almost forgot to mention:

    The plan was to use addresses closer to 65535 for library configuration data (when needed). So, it's best to build from 32768 upward for application configuration data.

    I should really change the example to 32768, or at least something that's a lower address in that upper (32768...65535) half of the EEPROM.

    ...and for those of you following along, EEPROM addresses 0...32767 is where ActivityBot example programs are stored. So, EEPROM addresses from 32768 to 65535 can be used for storing values. The great thing about EEPROM is that unlike RAM, EEPROM data is non-volatile, meaning that it remembers the data even after power has been turned off and back on.
  • edited 2013-10-01 11:13
    Too funny, your question and my afterthought go pretty well together. Yes, the "gentlemans agreement" is that libraries will start at the highest addresses (closest to 65535) and work downwards, so in most cases, application eeprom data should start at 32768 and grow upward toward higher addresses as needed.
  • dgatelydgately Posts: 1,630
    edited 2013-10-01 12:03
    ...compass calibration is slated for 65478...65504...

    Ah, that's good! Not sure what format you are going to use for compass data (I've been looking at how it's stored/communicated/coded in other examples such as from GPS devices, in databases, within code, etc.), but I'll temporarily store my placeholder data there and update when learn.parallax.com tutorials for the compass come out.

    Thanks again!

    dgately
Sign In or Register to comment.