My ActivityBot Phase II
Rsadeika
Posts: 3,837
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
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
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
Ray