Philip English

Robotics Enthusiast, Director, Investor, Trainer, Author and Vlogger

NAO Tactile Head Python Tutorial

NAO Tactile Head Python Tutorial

Hi Everyone and welcome, today we are going back to the NAO Tactile Head behavour and looking in to how to program some colour states. So if you want your robot to flash his eyes like a disco, then please stay tuned.

Hi guys I’m Philip English from now on this video were looking to teach you how to toggle between 8 different color states using the NAO tactile head.

We will do this by implementing some python code which will cut down as having lots of choregraphe boxes.

Alright hi guys! And let’s have a look at this tutorial a python tutorial for the tactile heads and the colors the eyes color for the NAOs.

So and what we are going to do is a ignore this box here this is one of mine earlier so we can speed things up so lets create a brand new python box so right click and then create new and python ok so were gonna name this box Eye Light Blend and then what we need to do is we need to create a three new inputs for this box and they will have to be on bangs type so we click the come down here inputs and hit the plus sign and the first one we are going to have red all lower case make sure the type in bang ok then all box in click again we need a green one and make sure its bang again ok and hit plus sign and we need a blue one and make sure there’s the bangs on that then we hit ok and we have our python box all setup and ready to go on the inputs so the red, green and blue now we are using a tactile head so were just gonna bring this down here and the tactile head button were looking for is in sensing and there is tactile head drag it out there?

Now, we wanna connect up like so so we wanna put one here and left needle here and then we’ll see from the needles from the top of tactile head so we see this is the top a the front tactile head and this is the middle one and this is the back one so we see each one is connected we choose different color for it.

Now what I’m gonna do is I’m actually just gonna delete this and I’m actually gonna put the one I’ve made earlier so we can copy the code so this tut Isn’t hours and hours long just me writing out code for you so lets put that in there so again the top, the middle and the bottom button or should I say the front, the back ah the front the middle and the back button which should as go in the red the green and the blue input we just made on the python box.

So if we click into the box the script editor phase and what I want you to do is I want you to pause the video and input all of the text so we can get our python code and then I’ll quickly run through what it means so I’ll pause it now guys and type that all in.

So guys I’m guessing that you’ve had time and you have put in the code and written into your python history box.

So to put you guys through it the script contains the state consisting of three Boolean variables so this is the red, the green and the blue that we’ve input into it.

Boolean variables can either be true or false. So when you hit their buttons on the top of the NAO so the tactile head buttons ah we can toggle the corresponding variable using the not operator which performs negation so not true is false and not false is true.

So what we do is a we use the state variables to set the LED colors in the on input on the start method which continually loops and sets the eye colors. The colors are set by the normal 24 bit RGB value colors in the binary code this is done by the last 8 bits of the blue component. The proceeding 8 bits of the green component and the 8 bits before that’s on the red component. So if you have any paint programs guys you can quickly go in there and type in these variables into the color and color field and you will see the actual color appears so there in the hexadecimal it says 0XFF and four zeros is red 0x two zeros two F two 0 is green and 0x four 0 and two F is blue. You also notice there is a bitwiser or operator so this is the vertical bar here so this takes the two binary numbers for each bit if the bit is set in either number it is set in the output.  

So to give you example if you have 100110 and then you have the vertical bar which is the bitwiser followed by 010100 this corresponds to equals 110 10 so the sequence os the iff statement sets the corresponding color component if the red, green and blue variables have been set to true.

Right as brilliant guys so just to give you a quick overview of how I made it again and my tutorials are trying to keep from its basic as possible not to get too detailed with python. So what were gonna do now is were gonna close the box and we are gonna hit play on the system file oh gonna save it first lets save the files there we go saving hit play its all working smoothly this if the code is wrong youll get a red box appear and you don’t want this so you can go check the codes then hit play its running smoothly now. So lets go over the robot and lets see what we get.

Right hi guys! So here we have the NAO so lets give him a go so if I touch the front panel Ive done it in the dark so we can see this a little bit easier front those the front panel there we have is red eyes and were turning off and if we hit the middle panel we have the green eyes and were turning off and then the back of tactile head and it was blue eyes turning off so ofcourse we can combine these combinations so if we hit red and green we have a yellow color and if we take the green off and we have a blue we have a purple color so you can see how we have a mixture of different colors but yes you can see its working very very nicely.

Well done guys, you can now manipulate your robots eyes to any colour you desire! And you have also learnt some more python skills

Now have a play with this behaviour and experiment with the all eight different colour combinations.

Have a play guys and use your imagination.

Now if you liked this tutorial and want to see the next one in the collection, then please hit the Subscribe button and keep update with the latest videos that come out.

Please have a look below, where I have put links relating to this videos , as well as other information about the NAO Robot.

If you have any questions or want to see any other related tutorials, then please write me a message in the comments section, and I will see what I can do.

Thanks Guys! And I will see you next time.

Philip English:

Sponsor: Robot Center:

You might be interested in …

Leave a Reply

Your email address will not be published. Required fields are marked *