PDA

View Full Version : [Question(s)] On Bioloid: How to input a word via the computer screen?



cybernetics
06-30-2011, 07:29 PM
Hi, thanks for reading my post.

BACKGROUND: I'm working with Bioloid and I'm using embedded C that I download to my robot via the RoboPlus Terminal. I've made a robot with 3 DOF; it's an arm that can wright. Two of the servo-motor can move in the XY-plane and the other servo-motor's purpose is to decide whether the pencil is touching the sheet or not (ie. it rotates about the XY-plane). I've almost done everything I wanted to do: when I write a word in the program and then compile it and download it in my robot, it can right the word. However, I would like to write the word directly on the interface procured by the RoboPlus Terminal instead of always recompiling the program.

QUESTION: How can I input a word on my Bioloid robot via my computer screen? (using the RoboPlus Terminal or something else that does not implied recompiling the program each time I change the word)

Here is what I've tried:

[...]
else if(~PIND & BTN_START)
{
char word[10];
printf("Entrer un mot: ");
gets(word);
//strcpy(word,"JE SUIS UN ROBOT");
for(i=0;i<(sizeof word);i++)
{
switch(word[i])
{
case 'A': A(); continue;
case 'B': B(); continue;
case 'C': C(); continue;
case 'D': D(); continue;
case 'E': E(); continue;
[...]

However, I'm not able to write anything when comes the time.

Any ideas if it is possible, and if so, how to do it?

Thanks!

tician
07-01-2011, 09:57 AM
Interesting sounding project. Which controller are you using? The CM-5 has its own precompiled library for all of the serial, zigbee, battery charging, and button sensing functions (I have a copy, but have not used it) and the CM-510/700 use a newer Embedded C library with available source code (unsure what license as none listed). Unfortunately, I am not finding a gets() function in either of them. The new CM-510/700 Serial library has a function called serial_read() which can read any number of characters from the serial port (but does not return until at least that many characters are available to be read), and it also has std_getchar() and std_puchar() which override/enable some <stdio.h> functions (getchar(), putchar(), printf()).

I'm a bit sleep deprived and have not tested this, so a bit wary of my code.



#include <avr/io.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include "serial.h" // from the CM-510/700 Embedded C files from Robotis

int main(void)
{
serial_initialize(57600);
sei();

/*
The first chunk of your code
*/
else if(~PIND & BTN_START)
{
char word[10];
printf("Entrer un mot: ");

// OPTION #1
// This line would not return until 10 characters are entered on the command line
serial_read(word, 10);

// OPTION #2 (recommended)
// This loop would not be dependent on input length
// (or you could modify the serial_read() function to exit if it reads a newline)
int numletters=0;
while (numletters<10)
{
char rcv = getchar();

if (rcv == '\n')
break;
else
word[numletters++] = rcv;
}

for(i=0;i<(numletters);i++)
{
switch(word[i])
{
/*
'break' means the switch will stop trying to compare the letter which has already
been found and move on to the next iteration of the loop (the next letter).
If you can only print in uppercase letters, you may want to add a to_upper() function
to ensure every letter in word[] is in uppercase.
*/
case 'A': A(); break;
case 'B': B(); break;
case 'C': C(); break;
case 'D': D(); break;
case 'E': E(); break;
// etc., etc.
}
}
}
/*
The rest of your code
*/

return 0;
}

cybernetics
07-04-2011, 10:30 AM
Hi tician,

Thanks for your answer.

I have a CM-510 (I forgot to mention it :S).

Firstly, I've tried your Option 2, and it cannot compile because I get these errors:
U:\MinGW\include/stdio.h:338 undefined reference to '_imp__iob'
U:\MinGW\include/stdio.h:338 undefined reference to '_filbuf'
I've look on other forums, but I don't get it. I think I need the libc.lib library (?), but I can't find it.

Secondly, I've tried your Option 1. I've compiled it and run it. It seems to work except I can't type anything: nothing appears on the screen and the robot keeps waiting for a string that doesn't arrive. Maybe the problem isn't my program, but rather the RoboPlus Terminal (v.103) software.

What do you think?

Thank you!

P.S.: How do you post your code in that form on the forum?

tician
07-04-2011, 07:01 PM
The "#" (pound, hash, number symbol, etc. I've heard it called many things) button on the post/reply to a thread screen adds the required tags around text blocks.

Whatever makefile you are using is attempting to use MinGW as a compiler. Since you are obviously using Windows, you will have to install either WinAVR or Atmel's AVRStudio to get the avr-gcc compiler. If you use WinAVR, you will need a makefile that adds in the Robotis libraries and the correct path to the files. If you have either WinAVR or AVRStudio already installed, which version and how complete is your makefile (if any)?

I have attached the very basic source I gave earlier and a makefile that has worked quite well for some time using avr-gcc 4.3.0. It compiles fine on my system and should work on yours, but I do not have a CM-510 with me to test nor have I checked the makefile recently on a Windows system (the shell command defines at the very end may need modification). I cannot remember where I first acquired it, but it is a pretty nice makefile and almost any changes you could need to make are at the very top with obvious names/comments.

The makefile assumes the folder tree is set up as follows:
Robotis precompiled libraries in /projectname/lib
Robotis header files in /projectname/include
Project source and makefile in /projectname/app

Also, the
#define BTN_START 1<<3 is almost certainly wrong, so change it to what you know works.

cybernetics
07-05-2011, 10:22 AM
I had already installed both WinAVR and AVRStudio (4.18) as suggested in Bioloid's E-manual: http://support.robotis.com/en/

I've just look on the Internet to see what was a makefile because I didn't know what it was before you mention this word. So I guess I do not have a makefile (or I have the default one?).

The errors I've got are a result of putting the function "getchar()"; without it, all my code works fine. And if I use another function, such as "std_getchar(word,10)", then I can compile my program without getting errors, but I'm not able to input a word when comes the time.

It isn't working when I'm using this:

#define BTN_START 1<<3

instead I'm using this and it works fine for me:

#define BTN_START 0x01

tician
07-05-2011, 12:10 PM
You only need the makefile if you use WinAVR. AVRStudio has all of the makefile configurations made through the GUI. I made a small mistake in the makefile (defined the wrong chip), and a few more improvements to the code.

I have tested compilation of this new code on a WinXP box running WinAVR-20100110 (no MinGW, but I do have another system with it, so I may test that one later), and I have finally tested the program itself on a CM-510. On my system, the use of getchar() is easily overriden by the std_getchar() function in the Robotis library. Thinking about it, I am almost certain that when you use '#include <stdio.h>', it is finding the MinGW version first instead of the avr-gcc version. Instead of '<stdio.h>', try using the absolute path like '#include "c:/WinAVR-20100110/avr/include/stdio.h"'

About the "#define BTN_START", I had a note at the bottom of my previous post that it would almost certainly be wrong. It is wrong not just in the number of times to left shift, but also the format as "PIND & 1<<3" would behave very differently from "PIND & (1<<3)". The first version logical ANDs PIND with '1' and then left shifts it three times (multiplies by 8). The second version left shifts '1' three times and then logical ANDs PIND with the result.

A note about Robotis terminal, it does not print out the character you type, so I added a small change to the input reading loop to echo whatever you type and also handle backspaces, so what you have typed on the screen is what the CM-510 has stored in 'word[]'.

cybernetics
07-05-2011, 02:49 PM
#include "c:/WinAVR-20100110/avr/include/stdio.h"'Oh that's good to know!


About the "#define BTN_START", I had a note at the bottom of my previous postOups sorry.


Your program worked fine, but it didn't work when I implemented your code in mine; so I've gradually change your code for mine until it didn't work, in order to see what was the problem.

The line that inhibit the input is this one: PORTD = 0x11;

When this line is in my program, my program stops at the "getchar()" function because I cannot input any character.

Do you have any idea why?

Anyway, I removed that line (ie. and I don't remember why putting it in the first place) and now it works fine. :happy: I thought it would never going to. ^^

Thanks a lot!!! It's really appreciated.

cybernetics
07-06-2011, 10:19 AM
Hi,

I've got one more little question regarding this part of the code:



//begining of the code
int numletters=0;
while (numletters<50)
{
char rcv = getchar();

if (rcv == '\n')
break;
if (rcv == '\b')
{
printf("\b");
if (numletters>0)
numletters--;
}
else
{
word[numletters++] = rcv;
printf("%c", rcv);
}
}

int first = 1;
if(!strcmp(word,"square") || !strcmp(word,"Square"))
{
Square(); //*checkpoint*
continue;
}
else if(!strcmp(word,"star") || !strcmp(word,"Star"))
{
Star();
continue;
}
//end of the code

Do you know why when I type "square" it doesn't do the Square() function (see *checkpoint*), and the same thing for other words such as "star"? However, when I enter the word directly into the program like this:

strcpy(word,"square");
it works.

Thanks

tician
07-06-2011, 12:00 PM
The receive word loop as written does not necessarily produce a c-string (especially if you took advantage of the backspace functionality as it does not overwrite the backspaced letter). Adding a '\0' to word[numletters_final+1] would ensure it is a c-string, but may not fix the problem and could possibly exceed the allocated size of word[] if you are not careful.

The easiest way to debug is to add a 'printf("\nWord: \"%s\"\n", word);' after the receive loop to ensure what you think is being stored in word[] actually is what is stored in word[].

cybernetics
07-06-2011, 02:06 PM
Nice it works! Thanks again!

cybernetics
07-07-2011, 08:55 PM
I've got another question...

Now I'm trying to control my Bioloid via the computer keyboard, by doing something like that


//beginning of the code
scanf("%c",&input);
if((~PINE & BTN_UP)||(input=='w'))
{
//code
}
else if((~PINE & BTN_DOWN)||(input=='s'))
{
//code
}
//end of the code

However, I want to be able to still control it with the button on my CM-510. However, doing it this way, the program wait for an input absolutely (on the line: scanf("%c",&input);) before continuing. I've seen maybe 6 or 7 good ways to do it, but in each of them there is a need for a library I can't seem to get with this compiler. Here is the list:


#include <conio.h>
#include <slang.h>
#include <termios.h>
#include <unistd.h>
#include <tigcclib.h>
#include <sys/filio.h>

So is there another way to do it without these libraries or is there a way to install one of these library?

Thanks!

P.S.: I've look to around 50 web sites and didn't find anything. There is more than one hundred thousand hits on Google when I'm looking for that, so maybe I've missed something.

tician
07-07-2011, 10:16 PM
Using only the Robotis serial library.



// beginning of the code
// get number of characters in receive buffer
if (serial_get_qstate()>0)
input=getchar(); // get first available character, if any

if((~PINE & BTN_UP)||(input=='w'))
{
//code
}
else if((~PINE & BTN_DOWN)||(input=='s'))
{
//code
}
//end of the code

cybernetics
07-08-2011, 08:28 AM
Thanks! I was wondering where you had learned this? Is there somewhere I can find all the functions present in the Robotis serial library?

I'll try to post a little video showing a small part of what my robot can do (so you can see what you've help me to build :wink:).

tician
07-08-2011, 10:41 PM
It seems you've not too much experience with C/C++. Classes, namespaces, global/class variables, and function prototypes, etc. are declared in the header files ("serial.h", "zigbee.h", "dynamixel.h", etc.).

The CM-510 embedded C libraries from the Robotis support site also include the source code, so a quick read through the comments helps understand what the functions actually do and what any variables represent.

On a side note, most of the libraries you listed in your earlier post (especially termios.h) are for use with full operating systems. The ATmega2561 onboard the CM-510/700 requires lower level configuration and control (using individual registers), whereas termios is a high level library requiring lower level systems/drivers to create sockets that it can use.


VEERING WAY OFF TOPIC...
I have learned to poorly program from many different sources. First was the obligatory graphing calculator with BASIC. Then I was part of the last 'intro programming for engineers' class where J (http://ruinsmiley.tripod.com/Themesmileys_files/pukeface.gif)a (http://images.zaazu.com/img/vomit-boy02-vomit-puke-sick-smiley-emoticon-000653-large.gif)v (http://i299.photobucket.com/albums/mm306/ShennaB13/clown_meat.jpg)a (http://www.hospitalrecords.com/uploadimages/tonyfinger484.jpg) was taught (it changed to Alice + MATLAB the following year, and now they are teaching LabVIEW and MATLAB). Fiddled briefly with C/C++ for a 'Statics' project. I had to learn MATLAB out of necessity for 'Mechanisms and Machine Kinematics', 'Linear Systems', and 'Mechanical Systems/Machine Design'. I became adept at 68HC11 assembly code from two semesters of microcontrollers courses. I have learned the bulk of my C/C++ from working with the CM-510/700 for Instructional Robotics example projects, various data collection/formatting projects to meet the input requirements of analysis programs, and now with the DARwIn-OP we recently got in the lab (currently having some problems with the FT232RL on its very much beta release CM-730 not enumerating). I also familiarized myself with LabVIEW for the PC side of the CM-510/700 example projects because it did not occur to me that the Dynamixel and Zigbee SDK's from Robotis would include the actual vi's (so I built roughly equivalent versions from just the images on the support site).

cybernetics
07-11-2011, 09:26 AM
Indeed I haven't a lot of experience in C/C++.

Thanks for the tip.

For my part, I've learned Matlab (for numeric purpose) and Maple (for symbolic purpose) in an 'intro to programming for engineers' class. Now I'm learning C/C++ by myself. And in a later course I'm going to learn LabView.

cybernetics
09-11-2011, 03:02 PM
Here is the video I said I would post.


http://www.youtube.com/watch?v=Qu_CNmo6Tx8