Hi fellow Bittle and Nybble owners !
In this new post I will continue to analyse the code of opencat and today I want to explain the IR remote part of the code.
As a reminder, you can add motions and postures to your robot by writing the data in the instinct header file into the WriteInstict folder, once again this part is well documented in the manual at : https://bittle.petoi.com/8-teach-bittle-new-skills. As said in the manual, you can modify an already existant motion like the "zero" motion, it's an easy way to add a skill to your robot as you will just have to push the button assigned to the "zero" skill (the 9 button by default) to make it run by your robot. But you will surely want to teach more than one skill to your robot so I will show you how to change the IR remote buttons assignment. Everything happens in the opencat.h file, here you can find the "macros" that defines the assignment. Macros are text substitution that happen at the code compilation time (it happen when you upload the code into your robot), all you have to know here is that they are defined by the well named '#define' keyword at the line 142:
//abbreviation //gait/posture/function names
#define K00 "d" //rest and shutdown all servos
#define K01 "F" //forward
#define K02 "g" //turn off gyro feedback to boost speed
#define K10 "L" //left
#define K11 "balance" //neutral stand up posture
#define K12 "R" //right
#define K20 "p" //pause motion and shut off all servos
#define K21 "B" //backward
#define K22 "c" //calibration mode with IMU turned off
#define K30 "vt" //stepping
#define K31 "cr" //crawl
#define K32 "wk" //walk
#define K40 "tr" //trot
#ifdef NYBBLE
#define K41 "lu" //look up
#define K42 "buttUp" //butt up
#else //BITTLE
#define K41 "rn" //run
#define K42 "ck" //check around
#endif
#define K50 "hi" //greeting
#define K51 "pu" //push up
#define K52 "pee" //standng with three legs
#define K60 "str" //stretch
#define K61 "sit" //sit
#define K62 "zero" //zero position
Here you can see the name of the skill called by each key, these are the names set in the instinct header like explained in the documentation.
If you want to knows which key corresponds to which symbol on the remote you can look at the OpenCat.ino file at line 82:
switch (results.value) {
//IR signal key on IR remote //key mapping
case 0xFFA25D: /*PTLF(" CH-"); */ return (F(K00));
case 0xFF629D: /*PTLF(" CH"); */ return (F(K01));
case 0xFFE21D: /*PTLF(" CH+"); */ return (F(K02));
case 0xFF22DD: /*PTLF(" |<<"); */ return (F(K10));
case 0xFF02FD: /*PTLF(" >>|"); */ return (F(K11));
case 0xFFC23D: /*PTLF(" >||"); */ return (F(K12));
case 0xFFE01F: /*PTLF(" -"); */ return (F(K20));
case 0xFFA857: /*PTLF(" +"); */ return (F(K21));
case 0xFF906F: /*PTLF(" EQ"); */ return (F(K22));
case 0xFF6897: /*PTLF(" 0"); */ return (F(K30));
case 0xFF9867: /*PTLF(" 100+"); */ return (F(K31));
case 0xFFB04F: /*PTLF(" 200+"); */ return (F(K32));
case 0xFF30CF: /*PTLF(" 1"); */ return (F(K40));
case 0xFF18E7: /*PTLF(" 2"); */ return (F(K41));
case 0xFF7A85: /*PTLF(" 3"); */ return (F(K42));
case 0xFF10EF: /*PTLF(" 4"); */ return (F(K50));
case 0xFF38C7: /*PTLF(" 5"); */ return (F(K51));
case 0xFF5AA5: /*PTLF(" 6"); */ return (F(K52));
case 0xFF42BD: /*PTLF(" 7"); */ return (F(K60));
case 0xFF4AB5: /*PTLF(" 8"); */ return (F(K61));
case 0xFF52AD: /*PTLF(" 9"); */ return (F(K62));
case 0xFFFFFFFF: return (""); //Serial.println(" REPEAT");
default: {
//Serial.println(results.value, HEX);
}
return (""); //Serial.println("null");
}// End Case
To add a new skill assignment you can simply comment (it do not take memory) the old assignment and replace it by yours like that:
//old assignment is commented out and so not interpreted by the compiler
//#define K61 "sit" //sit
#define K61 "mySkill" //my awesome new skill
And that's all ! if you have defined correctly the new skill with that name on the "teach a new skill" part of the documentation, you will just have to push the right button (here the 8 button) to make your robot run your new skill. I hope having explained well but don't hesitate to ask me questions if something is not clear for you. Have fun with your robot ! 😄 PS: there is a special case for 2 and 3 keys but I'm sure you would have understood, the definitions after '#ifdef NYBBLE' are for Nybble and the definitions after '#else //BITTLE' are for Bittle. Pretty easy. 😉
Very nice! You can make a main post with links to all your future posts, and I'll pin your main post to the top of this category so that it's better organized for new members.