Legacy Forum: Preserving Nearly 20 Years of Community History - A Time Capsule of Discussions, Memories, and Shared Experiences.

libavr/libbioloid C library for CM5 released!

Bioloid robot kit from Korean company Robotis; CM5 controller block, AX12 servos..
289 postsPage 4 of 201, 2, 3, 4, 5, 6, 7 ... 20
289 postsPage 4 of 201, 2, 3, 4, 5, 6, 7 ... 20

Post by RandomMatt » Fri Jan 09, 2009 6:28 pm

Post by RandomMatt
Fri Jan 09, 2009 6:28 pm

BillB wrote:I am sending 2 bytes to the CM5 and I assume they are both being stored in the Uart buffer.


Not true... the uart buffers are for transmit only. I do intend to add a buffer for serial (pc-link/zigbee) reads, but there isn't one yet.

BillB wrote:My problem is that I do not seem to be able to use lastchar() and getchar() to step through the contents of the buffer.


I think you want to only use lastchar(). Then your code becomes:

Code: Select all
for(;;) {
  char c;
  c = lastchar();
  if (c != '\0') {
       // Process the data here
  }

  // do other stuff here
}


--

It might become clearer if I quote the implementation of getchar (taken from sio_input.c):

Code: Select all
char getchar(void) {
    char c = sio_ungot;
    if (c != '\0') {
        sio_ungot = '\0';
        return c;
    }
    while ('\0' == (c = lastchar()))
        /* nothing */;
    return c;
}


As you can see, there is some stuff at the top to deal with an ungot char, and then the rest is based on lastchar().

--

A thought occurs to me: I probably want to make lastchar() return an int and use -1 as its no-char-yet value, at the moment you cannot read 0x00s from the uart!
BillB wrote:I am sending 2 bytes to the CM5 and I assume they are both being stored in the Uart buffer.


Not true... the uart buffers are for transmit only. I do intend to add a buffer for serial (pc-link/zigbee) reads, but there isn't one yet.

BillB wrote:My problem is that I do not seem to be able to use lastchar() and getchar() to step through the contents of the buffer.


I think you want to only use lastchar(). Then your code becomes:

Code: Select all
for(;;) {
  char c;
  c = lastchar();
  if (c != '\0') {
       // Process the data here
  }

  // do other stuff here
}


--

It might become clearer if I quote the implementation of getchar (taken from sio_input.c):

Code: Select all
char getchar(void) {
    char c = sio_ungot;
    if (c != '\0') {
        sio_ungot = '\0';
        return c;
    }
    while ('\0' == (c = lastchar()))
        /* nothing */;
    return c;
}


As you can see, there is some stuff at the top to deal with an ungot char, and then the rest is based on lastchar().

--

A thought occurs to me: I probably want to make lastchar() return an int and use -1 as its no-char-yet value, at the moment you cannot read 0x00s from the uart!
RandomMatt
Savvy Roboteer
Savvy Roboteer
Posts: 117
Joined: Sat Dec 20, 2008 11:16 pm

Post by RandomMatt » Sat Jan 10, 2009 12:10 am

Post by RandomMatt
Sat Jan 10, 2009 12:10 am

RandomMatt wrote:A thought occurs to me: I probably want to make lastchar() return an int and use -1 as its no-char-yet value, at the moment you cannot read 0x00s from the uart!


It is done.

r972 (and above) will use -1 to signal no-char-yet from lastchar(). So in the code snipit above you'll need to change the '\0' to -1
RandomMatt wrote:A thought occurs to me: I probably want to make lastchar() return an int and use -1 as its no-char-yet value, at the moment you cannot read 0x00s from the uart!


It is done.

r972 (and above) will use -1 to signal no-char-yet from lastchar(). So in the code snipit above you'll need to change the '\0' to -1
RandomMatt
Savvy Roboteer
Savvy Roboteer
Posts: 117
Joined: Sat Dec 20, 2008 11:16 pm

Post by BillB » Sat Jan 10, 2009 11:12 pm

Post by BillB
Sat Jan 10, 2009 11:12 pm

Many thanks Matt
Many thanks Matt
BillB
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 232
Joined: Sun Aug 06, 2006 1:00 am
Location: Hampshire, UK

Post by BillB » Mon Jan 12, 2009 11:38 pm

Post by BillB
Mon Jan 12, 2009 11:38 pm

Matt,

I am trying to understand how to store some of my lookup tables in Flash memory (I keep running out of memory).

I would like to start by understanding your trig tables. I have added the following line to the beginning of my code:

#include <bioloid/trig_tables.c>

Unfortunately the file cannot then be compiled with errors like: "multiple definition of `trig_atan'". I have looked at the trig_tables.c file and these trig lookup are only are only defined once, so the error appears very odd.

I have also tried this with the example.c file, but same effect.

Any suggestions?
Matt,

I am trying to understand how to store some of my lookup tables in Flash memory (I keep running out of memory).

I would like to start by understanding your trig tables. I have added the following line to the beginning of my code:

#include <bioloid/trig_tables.c>

Unfortunately the file cannot then be compiled with errors like: "multiple definition of `trig_atan'". I have looked at the trig_tables.c file and these trig lookup are only are only defined once, so the error appears very odd.

I have also tried this with the example.c file, but same effect.

Any suggestions?
BillB
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 232
Joined: Sun Aug 06, 2006 1:00 am
Location: Hampshire, UK

Post by RandomMatt » Tue Jan 13, 2009 9:02 am

Post by RandomMatt
Tue Jan 13, 2009 9:02 am

you want to try try something like:

Code: Select all
#include <stdint>
#include <libavr>

flash_int16_t table[8] = {0, -1, 2, -3, 4, -5, 6, -7}

...

i = 5;
value = (int16_t)flash_read16(&table[i]);


two things that'll make it clearer:
flash_int16_t is defined to be "const FLASH int16_t", and
flash_read16() returns a uint16_t

(You could also have a look at the definition and use of "devicemodels" to see how stuart put a structure in flash)
you want to try try something like:

Code: Select all
#include <stdint>
#include <libavr>

flash_int16_t table[8] = {0, -1, 2, -3, 4, -5, 6, -7}

...

i = 5;
value = (int16_t)flash_read16(&table[i]);


two things that'll make it clearer:
flash_int16_t is defined to be "const FLASH int16_t", and
flash_read16() returns a uint16_t

(You could also have a look at the definition and use of "devicemodels" to see how stuart put a structure in flash)
RandomMatt
Savvy Roboteer
Savvy Roboteer
Posts: 117
Joined: Sat Dec 20, 2008 11:16 pm

Post by RandomMatt » Tue Jan 13, 2009 9:06 am

Post by RandomMatt
Tue Jan 13, 2009 9:06 am

it should be:
Code: Select all
#include libavr/flash.h
(but in angle backets)
it should be:
Code: Select all
#include libavr/flash.h
(but in angle backets)
RandomMatt
Savvy Roboteer
Savvy Roboteer
Posts: 117
Joined: Sat Dec 20, 2008 11:16 pm

Post by BillB » Tue Jan 13, 2009 12:42 pm

Post by BillB
Tue Jan 13, 2009 12:42 pm

Thank you Matt. That example was a great illustration.
I was using the line:

Code: Select all
value = table[i];

where I should have used :
Code: Select all
value = (int16_t)flash_read16(&table[i]);



Out of interest is there any performance impact of storing data in Flash that I should be aware of?
Thank you Matt. That example was a great illustration.
I was using the line:

Code: Select all
value = table[i];

where I should have used :
Code: Select all
value = (int16_t)flash_read16(&table[i]);



Out of interest is there any performance impact of storing data in Flash that I should be aware of?
BillB
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 232
Joined: Sun Aug 06, 2006 1:00 am
Location: Hampshire, UK

Post by RandomMatt » Tue Jan 13, 2009 6:55 pm

Post by RandomMatt
Tue Jan 13, 2009 6:55 pm

BillB wrote:Out of interest is there any performance impact of storing data in Flash that I should be aware of?


Not really... flash_read/flash_read16/flash_read32 functions are all inlined - the performance loss of reading from flash is much lower than, say, a function call (it is of the order of a single cycle per byte).

The eeprom_read* and eeprom_write* (defined in libavr/eeprom.h) functions are, however, very slow.

Edit: eeprom_read*() is fast enough - 10 cycles or so, eeprom_write*() takes >3ms per byte
BillB wrote:Out of interest is there any performance impact of storing data in Flash that I should be aware of?


Not really... flash_read/flash_read16/flash_read32 functions are all inlined - the performance loss of reading from flash is much lower than, say, a function call (it is of the order of a single cycle per byte).

The eeprom_read* and eeprom_write* (defined in libavr/eeprom.h) functions are, however, very slow.

Edit: eeprom_read*() is fast enough - 10 cycles or so, eeprom_write*() takes >3ms per byte
RandomMatt
Savvy Roboteer
Savvy Roboteer
Posts: 117
Joined: Sat Dec 20, 2008 11:16 pm

Post by anjocama » Tue Jan 20, 2009 1:48 am

Post by anjocama
Tue Jan 20, 2009 1:48 am

Hello, i have installed WinAVR and i tried to complile examle.c but output this error:

> "make.exe" all
gcc -Wall -g -std=gnu99 -Os -I../libbioloid -lm -o ../libbioloid/bioloid/trig_tables._ ../libbioloid/bioloid/make_trig_tables.c
process_begin: CreateProcess(NULL, gcc -Wall -g -std=gnu99 -Os -I../libbioloid -lm -o ../libbioloid/bioloid/trig_tables._ ../libbioloid/bioloid/make_trig_tables.c, ...) failed.
make (e=2): El sistema no puede hallar el archivo especificado.

make.exe: *** [../libbioloid/bioloid/trig_tables.c] Error 2

> Process Exit Code: 2
> Time Taken: 00:00

I am probed the option at comand line for make_trig_tables.c but obtain other error:

avr-gcc -o make_trig_tables make_trig_tables.c
c:/winavr-20081205/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/crts8515.o:(.ini
t9+0x0): undefined reference to `main'

¿How can i compile example.c?
¿can you upload the then final archive trig_tables.c?

Thanks!! :D
Hello, i have installed WinAVR and i tried to complile examle.c but output this error:

> "make.exe" all
gcc -Wall -g -std=gnu99 -Os -I../libbioloid -lm -o ../libbioloid/bioloid/trig_tables._ ../libbioloid/bioloid/make_trig_tables.c
process_begin: CreateProcess(NULL, gcc -Wall -g -std=gnu99 -Os -I../libbioloid -lm -o ../libbioloid/bioloid/trig_tables._ ../libbioloid/bioloid/make_trig_tables.c, ...) failed.
make (e=2): El sistema no puede hallar el archivo especificado.

make.exe: *** [../libbioloid/bioloid/trig_tables.c] Error 2

> Process Exit Code: 2
> Time Taken: 00:00

I am probed the option at comand line for make_trig_tables.c but obtain other error:

avr-gcc -o make_trig_tables make_trig_tables.c
c:/winavr-20081205/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/crts8515.o:(.ini
t9+0x0): undefined reference to `main'

¿How can i compile example.c?
¿can you upload the then final archive trig_tables.c?

Thanks!! :D
anjocama
Savvy Roboteer
Savvy Roboteer
Posts: 36
Joined: Wed Jan 14, 2009 10:53 am

Post by RandomMatt » Tue Jan 20, 2009 9:30 am

Post by RandomMatt
Tue Jan 20, 2009 9:30 am

chances are... you don't have gcc installed.

Try running "gcc -v", if that doesn't work then you need to install MinGW (as well as WinAVR).

If that does work, then it looks like make cannot run gcc for some reason. I've only experienced this once, when using a cygwin make.exe from cmd.exe (the problem when away when I ran it from sh.exe)
chances are... you don't have gcc installed.

Try running "gcc -v", if that doesn't work then you need to install MinGW (as well as WinAVR).

If that does work, then it looks like make cannot run gcc for some reason. I've only experienced this once, when using a cygwin make.exe from cmd.exe (the problem when away when I ran it from sh.exe)
RandomMatt
Savvy Roboteer
Savvy Roboteer
Posts: 117
Joined: Sat Dec 20, 2008 11:16 pm

Post by anjocama » Tue Jan 20, 2009 10:39 am

Post by anjocama
Tue Jan 20, 2009 10:39 am

Very thanks RandomMatt,
I installed the MinGW and compile the make_trig_tables.exe and generate trig_tables.c and then i can gerate the .hex file. Good, good job your libraries.
Very thanks RandomMatt,
I installed the MinGW and compile the make_trig_tables.exe and generate trig_tables.c and then i can gerate the .hex file. Good, good job your libraries.
anjocama
Savvy Roboteer
Savvy Roboteer
Posts: 36
Joined: Wed Jan 14, 2009 10:53 am

Post by BillB » Tue Jan 20, 2009 10:52 am

Post by BillB
Tue Jan 20, 2009 10:52 am

For some reason the WinAVR pack does not seem to be able to generate the trig_tables.c file. I got around the problem by compiling on a Mac and then copying the trig_tables.c file over to the PC (into libbioloid/bioloid directory). Since then WinAVR has worked wonderfully well.
For some reason the WinAVR pack does not seem to be able to generate the trig_tables.c file. I got around the problem by compiling on a Mac and then copying the trig_tables.c file over to the PC (into libbioloid/bioloid directory). Since then WinAVR has worked wonderfully well.
BillB
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 232
Joined: Sun Aug 06, 2006 1:00 am
Location: Hampshire, UK

Post by anjocama » Tue Jan 20, 2009 11:17 am

Post by anjocama
Tue Jan 20, 2009 11:17 am

Other question:

At the example.c comment this:

// Note: Default battery setting is to shut down robot at 10vdc. This is ideal
// for a 3 cell lithium polymer. Change libbioloid/bioloid/battery.h if you're
// using a different battery pack.
// Suggestions:
// - 6.4vdc for 8s NiMH
// - 10vdc for 3s LiPo

I have a 8s NiMH battery, how i configure this in the baterry.h:

#ifndef __LIBBIOLOID_BATTERY__
#define __LIBBIOLOID_BATTERY__

#include <stdint>

#define MV_FLASH 10500
#define MV_CHARGE 10000
#define MV_STOP 10000

// Battery voltage in mV
extern int battery_mv, battery_positive, battery_negative;
extern uint8_t battery_charging;
#define PSU (battery_negative > 0)

void battery_init(void);
void battery_printinfo(void);

#endif
Other question:

At the example.c comment this:

// Note: Default battery setting is to shut down robot at 10vdc. This is ideal
// for a 3 cell lithium polymer. Change libbioloid/bioloid/battery.h if you're
// using a different battery pack.
// Suggestions:
// - 6.4vdc for 8s NiMH
// - 10vdc for 3s LiPo

I have a 8s NiMH battery, how i configure this in the baterry.h:

#ifndef __LIBBIOLOID_BATTERY__
#define __LIBBIOLOID_BATTERY__

#include <stdint>

#define MV_FLASH 10500
#define MV_CHARGE 10000
#define MV_STOP 10000

// Battery voltage in mV
extern int battery_mv, battery_positive, battery_negative;
extern uint8_t battery_charging;
#define PSU (battery_negative > 0)

void battery_init(void);
void battery_printinfo(void);

#endif
anjocama
Savvy Roboteer
Savvy Roboteer
Posts: 36
Joined: Wed Jan 14, 2009 10:53 am

Post by BillB » Tue Jan 20, 2009 11:42 am

Post by BillB
Tue Jan 20, 2009 11:42 am

anjocama wrote:
I have a 8s NiMH battery, how i configure this in the battery.h:


Sounds like you are still using the battery pack that came with the Bioloid Kit. Matts Library is by default geared towards, the much better, LiPo packs (a highly recommended upgrade for all Bioloids). The only trouble with LiPo batteries is that you must be very careful that they are not discharged too much. The parameters in battery.h specify when to cut power to the Servos to prevent further discharge.

Overdischarge is not so much a problem with the battery packs which came with the Bioloid so you could probably afford to change the parameters to something like:

Code: Select all
#define MV_FLASH 8500
#define MV_CHARGE 8000
#define MV_STOP 8000


So long as you use NIMH batteries there is probably not much harm if you wanted to change the parameters even lower.
anjocama wrote:
I have a 8s NiMH battery, how i configure this in the battery.h:


Sounds like you are still using the battery pack that came with the Bioloid Kit. Matts Library is by default geared towards, the much better, LiPo packs (a highly recommended upgrade for all Bioloids). The only trouble with LiPo batteries is that you must be very careful that they are not discharged too much. The parameters in battery.h specify when to cut power to the Servos to prevent further discharge.

Overdischarge is not so much a problem with the battery packs which came with the Bioloid so you could probably afford to change the parameters to something like:

Code: Select all
#define MV_FLASH 8500
#define MV_CHARGE 8000
#define MV_STOP 8000


So long as you use NIMH batteries there is probably not much harm if you wanted to change the parameters even lower.
BillB
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 232
Joined: Sun Aug 06, 2006 1:00 am
Location: Hampshire, UK

Post by anjocama » Tue Jan 20, 2009 12:13 pm

Post by anjocama
Tue Jan 20, 2009 12:13 pm

Yes, i have the default pack battery. I bought my bioloid 3 weeks ago. I buy in sparkfun the Bluetooth BlueSMiRF for integrated whit the CM-5 but i think this will arrive me in 5 or 6 days.

Other two question (i am heavy :D )...
1) The libbioloid, have any function to the AX-S1?
2) I have a HaVimo camera for bioloid. You have any idea about integrated this whit this libraries?
Yes, i have the default pack battery. I bought my bioloid 3 weeks ago. I buy in sparkfun the Bluetooth BlueSMiRF for integrated whit the CM-5 but i think this will arrive me in 5 or 6 days.

Other two question (i am heavy :D )...
1) The libbioloid, have any function to the AX-S1?
2) I have a HaVimo camera for bioloid. You have any idea about integrated this whit this libraries?
anjocama
Savvy Roboteer
Savvy Roboteer
Posts: 36
Joined: Wed Jan 14, 2009 10:53 am

PreviousNext
289 postsPage 4 of 201, 2, 3, 4, 5, 6, 7 ... 20
289 postsPage 4 of 201, 2, 3, 4, 5, 6, 7 ... 20