Shop OBEX P1 Docs P2 Docs Learn Events
My ActivityBot Phase II — Parallax Forums

My ActivityBot Phase II

RsadeikaRsadeika Posts: 3,837
edited 2013-09-29 08:44 in Learn with BlocklyProp
This is the start of the Phase II prototype program, which will be more IR_remote centric. The program below works as expected, except for the AB_volts, I have not driven my bot to the <=6.0Volts level, so I am not sure if the LED will turn on. I am hoping that the Learn Team will finish defining the rest of the keys for the remote controller, then I will probably use key ONE and ZERO for the start/stop of AB_roam.

Now open for discussion.

Code Size 13,596 bytes (17,424 total)

Ray
/*
*  abpl1.c
*
*  September 25, 2013
*
*  ActivityBot Program - Phase II
*
*/
#include "simpletools.h"
#include "abdrive.h"
#include "sonyremote.h"
#include "adcDCpropab.h"

#define IRpin 9

int main()
{
  // Add startup code here.
  // AB_nav
  int speedLeft, speedRight;
  int speedLeftOld  =  speedLeft;
  int speedRightOld =  speedRight;
  // AB_ir_remote
  int key;
  ir_tLimit(50);
  // AB_volts
  adc_init(21,20,19,18);
  float v3;
 
  while(1)
  {
    // Add main loop code here.
    // AB_volts
    v3 = adc_volts(3);
    v3 = v3*2;
    if(v3 <= 6.0) high(26);
    // IR_remote code - 
    key = ir_key(IRpin);
    if(key == PWR)   // PWR -> Stop Bot
    {      
      speedLeft = 0;
      speedRight = 0;
    }
    if(key == CH_UP)  // CH_UP -> Forward
    {
      speedLeft = 32;
      speedRight = 32;
    }
    if(key == CH_DN)  // CH_DN -> Backward
    {
      speedLeft = -32;
      speedRight = -32;
    }
    if(key == VOL_UP)  // VOL_UP -> Right
    {
      speedLeft = 16;
      speedRight = 0;
    }
    if(key == VOL_DN)  // VOL_DN -> Left
    {
      speedLeft = 0;
      speedRight = 16;
    }

    
    // AB_nav code, control of servo drives
    if(speedLeftOld != speedLeft || speedRightOld != speedRight)
    {
      drive_speed(speedLeft, speedRight);
      speedLeftOld = speedLeft;
      speedRightOld = speedRight;
    } 
    pause(20);
    
  }  
}

Comments

  • edited 2013-09-25 11:26
    Hi Ray,

    If you press 1, the ir_key function should return 1, and if you press 0, the ir_key function should return 0. Likewise for all digits on the keypad.

    The ir_key function corrects for the fact that the IR code is off by 1 from the actual button number for 1 through 9 (codes are 0 through 8, and then 0 is 9). But, ir_key returns adjusted codes of 0...9 for buttons 0...9.

    Additional button codes from http://www.sbprojects.com/knowledge/ir/sirc.php:

    16 Channel +
    17 Channel -
    18 Volume +
    19 Volume -
    20 Mute
    21 Power
    22 Reset
    23 Audio Mode
    24 Contrast +
    25 Contrast -
    26 Colour +
    27 Colour -
    30 Brightness +
    31 Brightness -
    38 Balance Left
    39 Balance Right
    47 Standby

    Also, from testing:

    11 Enter
    59 Prev channel

    I'm going to fix a bug that does not affect any of this, but could affect others (the ir_key function fetches 6 instead of 7 bits), and will also add a device function for finding out what device the IR remote is set to talk to.

    So, I'm thinking of changing library name to sirc (SONY Infrared Remote Control), and the API to:

    void sirc_setTimeout(int ms)
    int sirc_button(int ioPin)
    int sirc_device(int IoPin)
    int sirc_code(int ioPin, int bits)

    Andy
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-09-29 08:44
    Below, the program structure got reworked a little, but functionality is still the same. I started to do some experiments with manual drive programming, so if you press the "1" key, it will run a drive program. This is leading up to getting access to a program/file(a manual program) that would be located on the uSD card, and run by an assigned IR_remote control key. Now the hard part, getting access to uSD card, and running the program.

    Ray
    /*
    *  abpl1.c
    *
    *  September 25, 2013
    *
    *  ActivityBot Program - Phase II
    *  Strictly IR remote controlled.
    *
    */
    #include "simpletools.h"
    #include "abdrive.h"
    #include "sonyremote.h"
    #include "adcDCpropab.h"
    #include "ping.h"
    
    #define IRpin 9
    #define Pingpin 8
    
    static volatile int speedLeft = 0;
    static volatile int speedRight = 0;
    static volatile int speedLeftOld = 0;
    static volatile int speedRightOld = 0;
    
    
    
    // Function prototype
    int IR_remote(int irPin);
    void ab_nav(void);
    
    void key1_drive(void);
    
    
    
    int main()
    {
      // Add startup code here.
      // SD related
      int DO = 22, CLK = 23, DI = 24, CS = 25;        // SD I/O pins
      sd_mount(DO, CLK, DI, CS);
      // AB_nav
      int speedLeft, speedRight;
      int speedLold2  =  speedLeft;
      int speedRold2 =  speedRight;
      // AB_ir_remote
      ir_tLimit(50);
      int key = -1;
      // AB_volts
      adc_init(21,20,19,18);
      float v3;
    
     
      while(1)
      {
        // Add main loop code here.
        // AB_volts
        v3 = adc_volts(3);
        v3 = v3*2;   
        if(v3 <= 6.0) high(27);
        // IR_remote code 
        key = IR_remote(IRpin);  
        // AB_nav code, control of servo drives
        ab_nav();
      }  
    }
    
    /* IR remote control */
    /* Added the number keys for use. */
    int IR_remote(int irPin)
    {
      int key, ircmd;
      ir_tLimit(50);
    
      key = ir_key(IRpin);
        if(key == PWR)   // PWR -> Stop Bot
        {      
          speedLeft = 0;
          speedRight = 0;
        }
        if(key == CH_UP)  // CH_UP -> Forward
        {
          speedLeft = 32;
          speedRight = 32;
        }
        if(key == CH_DN)  // CH_DN -> Backward
        {
          speedLeft = -32;
          speedRight = -32;
        }
        if(key == VOL_UP)  // VOL_UP -> Right
        {
          speedLeft = 16;
          speedRight = 0;
        }
        if(key == VOL_DN)  // VOL_DN -> Left
        {
          speedLeft = 0;
          speedRight = 16;
        }
        if(key == 1)  // 
        {
          high(26);
          key1_drive();
        }
        if(key == 2)
        {
          high(26);
        }
        if(key == 3)
        {
          high(26);
        }
        if(key == 4)
        {
          high(26);
        }
        if(key == 5)
        {
          high(26);
        }
        if(key == 6)
        {
          high(26);
        }
        if(key == 7)
        {
          high(26);
        }
        if(key == 8)
        {
          high(26);
        }
        if(key == 9) 
        {
          high(26);      
        } 
        if(key == 0) // Stop numbered functions.
        {
          low(26);
        }
    
    }
    /* The servo drive control function. */
    void ab_nav(void)
    {
      if(speedLeftOld != speedLeft || speedRightOld != speedRight)
      {
        drive_speed(speedLeft, speedRight);
        speedLeftOld = speedLeft;
        speedRightOld = speedRight;
      } 
      pause(20);
    }
    
    void key1_drive(void)
    {
      drive_goto(128,128);
      pause(50);
      drive_goto(-12,13);
      pause(50);
      drive_goto(128,128);
      pause(50);
      drive_goto(-25,26);
      pause(50);
      drive_goto(96,96);
      low(26);
    }
    
    
Sign In or Register to comment.