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

C++ for bioloid

Bioloid robot kit from Korean company Robotis; CM5 controller block, AX12 servos..
19 postsPage 1 of 21, 2
19 postsPage 1 of 21, 2

C++ for bioloid

Post by ryann2k1 » Tue Jun 26, 2007 6:59 am

Post by ryann2k1
Tue Jun 26, 2007 6:59 am

Does anyone develop programming language for the bioloid with c++?hopefully you can help me since the robot only comes with c programming.
Thank you.

cheers

ryann2k1
Does anyone develop programming language for the bioloid with c++?hopefully you can help me since the robot only comes with c programming.
Thank you.

cheers

ryann2k1
ryann2k1
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 154
Joined: Thu Nov 16, 2006 1:00 am

Post by roycepipkins » Tue Jun 26, 2007 7:57 am

Post by roycepipkins
Tue Jun 26, 2007 7:57 am

I once back-ported the WinARM make file to WinAVR. At the time WinAVR didn't do auto-dependences either, but the WinARM make file did C, C++ and auto-dependences all together.

You might want to take a peek at WinARM to see how they do it. When I get back I try to round up what I have or just redo it.
I once back-ported the WinARM make file to WinAVR. At the time WinAVR didn't do auto-dependences either, but the WinARM make file did C, C++ and auto-dependences all together.

You might want to take a peek at WinARM to see how they do it. When I get back I try to round up what I have or just redo it.
roycepipkins
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 25
Joined: Tue Jun 20, 2006 1:00 am

Post by limor » Tue Jun 26, 2007 9:15 am

Post by limor
Tue Jun 26, 2007 9:15 am

the ATmega provides small amount of memory and in order to implement fancy C++ classes, inheritance, polymorphisms etc. the compiler usually needs lots of memory to do stuff behind the scenes.

So don't expect your ATMega embedded code to look pretty. advanced programmers (coders) always look at the output assembly code in order to do manual optimizations. The high level language provides a good startup point.

There are C++'ish compilers for Atmel.
Check out http://www.avrfreaks.net/index.php?modu ... =viewTools
the ATmega provides small amount of memory and in order to implement fancy C++ classes, inheritance, polymorphisms etc. the compiler usually needs lots of memory to do stuff behind the scenes.

So don't expect your ATMega embedded code to look pretty. advanced programmers (coders) always look at the output assembly code in order to do manual optimizations. The high level language provides a good startup point.

There are C++'ish compilers for Atmel.
Check out http://www.avrfreaks.net/index.php?modu ... =viewTools
limor
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 1845
Joined: Mon Oct 11, 2004 1:00 am
Location: London, UK

Post by savuporo » Tue Jun 26, 2007 10:00 am

Post by savuporo
Tue Jun 26, 2007 10:00 am

limor wrote:the ATmega provides small amount of memory and in order to implement fancy C++ classes, inheritance, polymorphisms etc. the compiler usually needs lots of memory to do stuff behind the scenes.

C++ is used in lots of embedded projects with plenty of success, but you have to be careful of the pitfalls.
Im a embedded developer myself, although i mainly work in 32-bit ARM space, and we mostly use C++ with occassional assembly. We usually have more wiggle room than Atmega.

To avoid bloat, avoid certain language features like RTTI, use templates only very carefully ( good guide is to typedef all the template instances and use only the typedefed types ) and thoroughly think through whether you want exceptions or not. Exceptions add roughly 20% code space and thus increase runtime memory footprint, if you can live without them, great. But this makes error checking everywhere more of a pain, and you cant use certain useful libraries.
Use heap sparingly if at all, and if you do, write or use nondefault allocators tuned for small systems ( dlmalloc is a good implementation, very customizeable )


Look at Stroustrup page here, search for "embedded". especially interesting reading material is the Joint Strike Fighter coding standards document. It contains lots of good guidelines, with reasoning behind the choices. The analysis is there, you can pick your own conclusions.

In short, C++ is suitable for embedded, and depending on skills of programmer, can actually beat C implementations in size requirements, but definitely it can beat them in readability and maintainability.
limor wrote:the ATmega provides small amount of memory and in order to implement fancy C++ classes, inheritance, polymorphisms etc. the compiler usually needs lots of memory to do stuff behind the scenes.

C++ is used in lots of embedded projects with plenty of success, but you have to be careful of the pitfalls.
Im a embedded developer myself, although i mainly work in 32-bit ARM space, and we mostly use C++ with occassional assembly. We usually have more wiggle room than Atmega.

To avoid bloat, avoid certain language features like RTTI, use templates only very carefully ( good guide is to typedef all the template instances and use only the typedefed types ) and thoroughly think through whether you want exceptions or not. Exceptions add roughly 20% code space and thus increase runtime memory footprint, if you can live without them, great. But this makes error checking everywhere more of a pain, and you cant use certain useful libraries.
Use heap sparingly if at all, and if you do, write or use nondefault allocators tuned for small systems ( dlmalloc is a good implementation, very customizeable )


Look at Stroustrup page here, search for "embedded". especially interesting reading material is the Joint Strike Fighter coding standards document. It contains lots of good guidelines, with reasoning behind the choices. The analysis is there, you can pick your own conclusions.

In short, C++ is suitable for embedded, and depending on skills of programmer, can actually beat C implementations in size requirements, but definitely it can beat them in readability and maintainability.
savuporo
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 26
Joined: Sun Dec 17, 2006 1:00 am

Re: C++ for bioloid

Post by acy.stapp » Sat Aug 25, 2007 10:08 pm

Post by acy.stapp
Sat Aug 25, 2007 10:08 pm

ryann2k1 wrote:Does anyone develop programming language for the bioloid with c++?hopefully you can help me since the robot only comes with c programming.
Thank you.

cheers

ryann2k1


I'm using C++ with WinAVR. I had to modify the default makefile but everything works fine. Here are the lines you need to change in your makefile. You'll need to find the correct lines and patch them manually:

Code: Select all
# List C source files here. (C dependencies are automatically generated.)
SRC = Example.cpp Servo.cpp
...
# Define all object files.
OBJ = $(addsuffix .o,$(basename $(SRC))) $(ASRC:.S=.o)

# Define all listing files.
LST = $(ASRC:.S=.lst) $(addsuffix .lst,$(basename $(SRC)))
...
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(addsuffix .lst,$(basename $(<)))
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
...
# Compile: create object files from CPP source files.
%.o : %.cpp
   @echo
   @echo $(MSG_COMPILING) $<
   $(CC) -c $(ALL_CFLAGS) $< -o $@

# Compile: create object files from CPP source files.
%.o : %.c
   @echo
   @echo $(MSG_COMPILING) $<
   $(CC) -c $(ALL_CFLAGS) $< -o $@

# Compile: create assembler files from CPP source files.
%.s : %.cpp
   $(CC) -S $(ALL_CFLAGS) $< -o $@

# Compile: create assembler files from CPP source files.
%.s : %.c
   $(CC) -S $(ALL_CFLAGS) $< -o $@
...
clean_list :
   ...
   $(REMOVE) $(OBJ)
   $(REMOVE) $(LST)
   $(REMOVE) $(addsuffix .s,$(basename $(SRC)))
   $(REMOVE) $(addsuffix .d,$(basename $(SRC)))
   $(REMOVE) .dep/*


ryann2k1 wrote:Does anyone develop programming language for the bioloid with c++?hopefully you can help me since the robot only comes with c programming.
Thank you.

cheers

ryann2k1


I'm using C++ with WinAVR. I had to modify the default makefile but everything works fine. Here are the lines you need to change in your makefile. You'll need to find the correct lines and patch them manually:

Code: Select all
# List C source files here. (C dependencies are automatically generated.)
SRC = Example.cpp Servo.cpp
...
# Define all object files.
OBJ = $(addsuffix .o,$(basename $(SRC))) $(ASRC:.S=.o)

# Define all listing files.
LST = $(ASRC:.S=.lst) $(addsuffix .lst,$(basename $(SRC)))
...
CFLAGS += -Wall -Wstrict-prototypes
CFLAGS += -Wa,-adhlns=$(addsuffix .lst,$(basename $(<)))
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
...
# Compile: create object files from CPP source files.
%.o : %.cpp
   @echo
   @echo $(MSG_COMPILING) $<
   $(CC) -c $(ALL_CFLAGS) $< -o $@

# Compile: create object files from CPP source files.
%.o : %.c
   @echo
   @echo $(MSG_COMPILING) $<
   $(CC) -c $(ALL_CFLAGS) $< -o $@

# Compile: create assembler files from CPP source files.
%.s : %.cpp
   $(CC) -S $(ALL_CFLAGS) $< -o $@

# Compile: create assembler files from CPP source files.
%.s : %.c
   $(CC) -S $(ALL_CFLAGS) $< -o $@
...
clean_list :
   ...
   $(REMOVE) $(OBJ)
   $(REMOVE) $(LST)
   $(REMOVE) $(addsuffix .s,$(basename $(SRC)))
   $(REMOVE) $(addsuffix .d,$(basename $(SRC)))
   $(REMOVE) .dep/*


acy.stapp
Robot Builder
Robot Builder
Posts: 14
Joined: Sat Aug 25, 2007 5:25 pm

Post by ryann2k1 » Sun Aug 26, 2007 3:08 am

Post by ryann2k1
Sun Aug 26, 2007 3:08 am

Thx acy.stapp it's really helpful.

Cheers,

ryann2k1
Thx acy.stapp it's really helpful.

Cheers,

ryann2k1
ryann2k1
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 154
Joined: Thu Nov 16, 2006 1:00 am

Post by limor » Wed Aug 29, 2007 2:32 pm

Post by limor
Wed Aug 29, 2007 2:32 pm

acy.stapp , if you have some neat c++ classes you wish to share related to the bioloid and cm5, will be of much appreciated.
:lol:
acy.stapp , if you have some neat c++ classes you wish to share related to the bioloid and cm5, will be of much appreciated.
:lol:
limor
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 1845
Joined: Mon Oct 11, 2004 1:00 am
Location: London, UK

C++ Classes

Post by acy.stapp » Fri Aug 31, 2007 5:09 pm

Post by acy.stapp
Fri Aug 31, 2007 5:09 pm

Later tonight I'll set up a sourceforge project for my stuff. Right now I've just got two classes built: Servo and Fixed.

class Fixed is a simple templatized math class that allows you to use fixed point numbers with standard math notation. This is much faster than floating point and has the same precision throughout its range which makes certain numerical solutions more stable. You can choose the number of fraction bits, the base storage type, and the storage type for intermediates. A Fixed<3> is a signed, two's complement fixed point number with 1 sign bit, 12 integral bits, and 3 bits of fraction. This lets us store and calculate with a servo position or velocity with 2 bits on top and 3 bits below.

Servo is an interface class to the AX-12+ and the sensor module. It handles reading and writing registers, pinging the servos, caching the device status, and has some nifty features like only writing changed values to the servo eeprom (since there is a write limit for those registers) and waiting the 5ms after writing an eeprom register. Functions are present to let you read fixed point speed, load, and position values, converting reads from the sign-bit representation of the AX-12 to a faster-calculating fixed-point representation. Fixed point values can also be written back to the AX-12+. Packets are constructed directly into the usart FIFO for efficiency. The generated code is very good.

The code is still in a hobbyist state while I write it. The communications stuff will be factored out next, it's still using the example communications setup.
Later tonight I'll set up a sourceforge project for my stuff. Right now I've just got two classes built: Servo and Fixed.

class Fixed is a simple templatized math class that allows you to use fixed point numbers with standard math notation. This is much faster than floating point and has the same precision throughout its range which makes certain numerical solutions more stable. You can choose the number of fraction bits, the base storage type, and the storage type for intermediates. A Fixed<3> is a signed, two's complement fixed point number with 1 sign bit, 12 integral bits, and 3 bits of fraction. This lets us store and calculate with a servo position or velocity with 2 bits on top and 3 bits below.

Servo is an interface class to the AX-12+ and the sensor module. It handles reading and writing registers, pinging the servos, caching the device status, and has some nifty features like only writing changed values to the servo eeprom (since there is a write limit for those registers) and waiting the 5ms after writing an eeprom register. Functions are present to let you read fixed point speed, load, and position values, converting reads from the sign-bit representation of the AX-12 to a faster-calculating fixed-point representation. Fixed point values can also be written back to the AX-12+. Packets are constructed directly into the usart FIFO for efficiency. The generated code is very good.

The code is still in a hobbyist state while I write it. The communications stuff will be factored out next, it's still using the example communications setup.
acy.stapp
Robot Builder
Robot Builder
Posts: 14
Joined: Sat Aug 25, 2007 5:25 pm

Makefile

Post by ryann2k1 » Sat Sep 01, 2007 3:51 am

Post by ryann2k1
Sat Sep 01, 2007 3:51 am

Hi acy.stapp,

I have tried to use your makefile source code but there is an error warning.

# Compile: create object files from CPP source files.
%.o : %.cpp
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@

The warning comes from @echo line.
How did you overcome this?
Thank you.

Cheers

ryann2k1
Hi acy.stapp,

I have tried to use your makefile source code but there is an error warning.

# Compile: create object files from CPP source files.
%.o : %.cpp
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@

The warning comes from @echo line.
How did you overcome this?
Thank you.

Cheers

ryann2k1
ryann2k1
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 154
Joined: Thu Nov 16, 2006 1:00 am

Re: C++ Classes

Post by limor » Sun Sep 02, 2007 1:53 am

Post by limor
Sun Sep 02, 2007 1:53 am

acy.stapp wrote:Later tonight I'll set up a sourceforge project for my stuff. Right now I've just got two classes built: Servo and Fixed.

There's a project called "robosavvy" on sourceforge which will consolidate lots of the source code and 3D graphic files that show up here on the forum.

http://robosavvy.svn.sourceforge.net/vi ... vvy/trunk/

if you would like to use this project to upload your code, please let me know your sourceforge user name and i'll add you to the project.

:lol:
acy.stapp wrote:Later tonight I'll set up a sourceforge project for my stuff. Right now I've just got two classes built: Servo and Fixed.

There's a project called "robosavvy" on sourceforge which will consolidate lots of the source code and 3D graphic files that show up here on the forum.

http://robosavvy.svn.sourceforge.net/vi ... vvy/trunk/

if you would like to use this project to upload your code, please let me know your sourceforge user name and i'll add you to the project.

:lol:
limor
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 1845
Joined: Mon Oct 11, 2004 1:00 am
Location: London, UK

Re: Makefile

Post by acy.stapp » Mon Sep 03, 2007 4:43 am

Post by acy.stapp
Mon Sep 03, 2007 4:43 am

ryann2k1 wrote:Hi acy.stapp,

I have tried to use your makefile source code but there is an error warning.

# Compile: create object files from CPP source files.
%.o : %.cpp
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@

The warning comes from @echo line.
How did you overcome this?
Thank you.

Cheers

ryann2k1


Try out my makefile from
http://robosavvy.com/Builders/acy.stapp/
ryann2k1 wrote:Hi acy.stapp,

I have tried to use your makefile source code but there is an error warning.

# Compile: create object files from CPP source files.
%.o : %.cpp
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@

The warning comes from @echo line.
How did you overcome this?
Thank you.

Cheers

ryann2k1


Try out my makefile from
http://robosavvy.com/Builders/acy.stapp/
acy.stapp
Robot Builder
Robot Builder
Posts: 14
Joined: Sat Aug 25, 2007 5:25 pm

Makefile

Post by ryann2k1 » Mon Sep 03, 2007 9:46 am

Post by ryann2k1
Mon Sep 03, 2007 9:46 am

Hi,acy.stapp
After I compiled, the warning pops out about this line below
:(
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++

and how do you implement timer128.c?

make.exe: *** No rule to make target `../../AVRLib/timer128.o', needed by `AngieGynoid.elf'. Stop.

Another error also :(

Gynoid.cpp: In function `int main()':
Gynoid.cpp:749: error: invalid conversion from `const char*' to `byte*'
Gynoid.cpp:749: error: initializing argument 1 of `void TxDString(byte*)'

looking forward to your respond.
Thank you.

cheers,

ryann2k1
Hi,acy.stapp
After I compiled, the warning pops out about this line below
:(
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++

and how do you implement timer128.c?

make.exe: *** No rule to make target `../../AVRLib/timer128.o', needed by `AngieGynoid.elf'. Stop.

Another error also :(

Gynoid.cpp: In function `int main()':
Gynoid.cpp:749: error: invalid conversion from `const char*' to `byte*'
Gynoid.cpp:749: error: initializing argument 1 of `void TxDString(byte*)'

looking forward to your respond.
Thank you.

cheers,

ryann2k1
ryann2k1
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 154
Joined: Thu Nov 16, 2006 1:00 am

Re: Makefile

Post by acy.stapp » Mon Sep 03, 2007 2:35 pm

Post by acy.stapp
Mon Sep 03, 2007 2:35 pm

ryann2k1 wrote:Hi,acy.stapp
After I compiled, the warning pops out about this line below
:(
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++

and how do you implement timer128.c?

make.exe: *** No rule to make target `../../AVRLib/timer128.o', needed by `AngieGynoid.elf'. Stop.

Another error also :(

Gynoid.cpp: In function `int main()':
Gynoid.cpp:749: error: invalid conversion from `const char*' to `byte*'
Gynoid.cpp:749: error: initializing argument 1 of `void TxDString(byte*)'

looking forward to your respond.
Thank you.

cheers,

ryann2k1

The '-Wstrict-prototypes' error can be ignored or you can just find that line are remove it from the makefile. It is a C-only option but I haven't modfied the makefile yet to have different C and C++ options.

timer128.c is from the Procyon AVRLib (google it). I'll be migrating a lot of my stuff over to this later. Remove the file from your SRC= line.

TxDString needs to be changed to void TxDString(char const *) or TxDString(char const *) (same thing). You'll have to add some casts to bytes inside TxDString or rework the lower-level functions to take const parameters.
ryann2k1 wrote:Hi,acy.stapp
After I compiled, the warning pops out about this line below
:(
cc1plus.exe: warning: command line option "-Wstrict-prototypes" is valid for C/ObjC but not for C++

and how do you implement timer128.c?

make.exe: *** No rule to make target `../../AVRLib/timer128.o', needed by `AngieGynoid.elf'. Stop.

Another error also :(

Gynoid.cpp: In function `int main()':
Gynoid.cpp:749: error: invalid conversion from `const char*' to `byte*'
Gynoid.cpp:749: error: initializing argument 1 of `void TxDString(byte*)'

looking forward to your respond.
Thank you.

cheers,

ryann2k1

The '-Wstrict-prototypes' error can be ignored or you can just find that line are remove it from the makefile. It is a C-only option but I haven't modfied the makefile yet to have different C and C++ options.

timer128.c is from the Procyon AVRLib (google it). I'll be migrating a lot of my stuff over to this later. Remove the file from your SRC= line.

TxDString needs to be changed to void TxDString(char const *) or TxDString(char const *) (same thing). You'll have to add some casts to bytes inside TxDString or rework the lower-level functions to take const parameters.
acy.stapp
Robot Builder
Robot Builder
Posts: 14
Joined: Sat Aug 25, 2007 5:25 pm

Make file

Post by ryann2k1 » Tue Sep 04, 2007 1:16 pm

Post by ryann2k1
Tue Sep 04, 2007 1:16 pm

Hi acy.stapp,
It seems all the library from the company (dynamixel.h) need to be reworked.
Once I try to fix TxDstring, than all errors pop up... writebyte, writeword, all functions need to be fixed.
Which dynamixel library do you use?
I thought it was easy , just add several lines in the makefile... :(
any idea?
Thank you...

cheers,

ryann2k1
Hi acy.stapp,
It seems all the library from the company (dynamixel.h) need to be reworked.
Once I try to fix TxDstring, than all errors pop up... writebyte, writeword, all functions need to be fixed.
Which dynamixel library do you use?
I thought it was easy , just add several lines in the makefile... :(
any idea?
Thank you...

cheers,

ryann2k1
ryann2k1
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 154
Joined: Thu Nov 16, 2006 1:00 am

Simple and dirty C++ example

Post by siempre.aprendiendo » Tue Sep 04, 2007 8:57 pm

Post by siempre.aprendiendo
Tue Sep 04, 2007 8:57 pm

This simple and dirty c++ example works for me with the WinAVR

http://robosavvy.com/Builders/siempre.a ... o/cpp0.zip
This simple and dirty c++ example works for me with the WinAVR

http://robosavvy.com/Builders/siempre.a ... o/cpp0.zip
siempre.aprendiendo
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 559
Joined: Wed Aug 08, 2007 9:13 pm
Location: Barcelona

Next
19 postsPage 1 of 21, 2
19 postsPage 1 of 21, 2