eProsima / Micro-XRCE-DDS-Apps

Looking for commercial support? Contact info@eprosima.com
10 stars 5 forks source link

Integrating to the external transport template #9

Closed vibnwis closed 3 years ago

vibnwis commented 3 years ago

Hi Pablo and team. I have completed integrating the link layer of CAN-bus in the project, namely "sample_project". I have got the send_CAN_frame_xxx(), and recv_CAN_frame_xxx(), as well as the corresponding initialisation function. With my limited knowledge, the implementation is in Micro-XRCE-DDS-Client. Where and How do I integrate the (or my) "sample_project" with Micro-XRCE-DDS-Client?

Appreciate any comments or suggestions.

vibnwis commented 3 years ago

Again, very embarrassing, I found the needed code the main_template.c. I am working on integrating the code. However, I thing, I will need some assistance later. Many thanks for keeping this channel opened.

vibnwis commented 3 years ago
  1. When merging the main-template.c with mine which requires the app.c. However, compilation failed on app.c where

    include <uxr/client/client.h>

    include <ucdr/microcdr.h>

    are not found. I searched, and found that they are in the folder micro-xrce-dds-client/Micro-XRCE-DDS-Client-master/include/uxr/client/client.h, but the sample_project has not micro-xrce-dds-client. As such, I copied the entire micro-xrce-dds-client into the Micro-XRCE-DDS-Apps-features-refactor-nuttx. It is now at the same level of FreeRTOS. This resolves the missing (the two) header files. However, it encountered another error message:

In file included from ../Core/Src/app.c:5:0: /home/wiki-ros/microROS/Micro-XRCE-DDS-Apps-feature-refactor_nuttx/Micro-XRCE-DDS-Client/include/uxr/client/client.h:18:10: fatal error: uxr/client/config.h: No such file or directory

include <uxr/client/config.h>

However, it is available as /home/wiki-ros/micro-xrce-dds-client/Micro-XRCE-DDS-Client-master/include/uxr/client/config.h.in

Admittedly, I am using STM32CubeIDE to compile which is definitely wrong approach. I am trying my best to resolve as many compilation errors as possible while waiting for resolution. Can you please provide steps how to compile the sample_project, please?

pablogs9 commented 3 years ago

Usually when using CMake for configuring and building Micro XRCE-DDS Client the config.h.in file is used to generate a config.h based on the current configuration. You can read more about CMake configure file here.

In fact here you can see how the XRCE library is being build using CMake.

Of course, you can manually generate a config.h based on your desired configuration. Feel free to ask if you want to know more about certain config flags.

vibnwis commented 3 years ago

Many thanks. Following the steps in README.md. However, at the step "In FreeRTOS/Inc/FreeRTOSConfig.h add these two lines in the USER CODE section (line 45):", the result of git clone -b feature/refactor_nuttx https://github.com/eProsima/Micro-XRCE-DDS-Apps, has no Inc folder. As I found the similar filename in the other folder created when executing microros-setup, I compared with "meld", they are slightly different. Can you use it? any comment, please?

pablogs9 commented 3 years ago

FreeRTOS/Inc/FreeRTOSConfig.h is generated is step:

Inside STM32CubeMX load FreeRTOS/sample_project.ioc and generate code.

vibnwis commented 3 years ago

Those code I work on were generated by STM32CubeMX which I added to the CAN-bus interface using the sample_project.ioc as a reference. See the picture attached. In other words, the STM32CubeMX does not generate the file. Also the file structure is compatible with the file structure described in the FreeRTOS/Makefile and README.md.

Okie, I was asked to migrate or continue when loading the IOC file. I was wondering if that caused the new file structure? IMG_1105.JPG https://drive.google.com/file/d/1iVnZ7G9xmFjxgz1xM7jaZZT6-zeMsnml/view?usp=drive_web

On Mon, 26 Oct 2020 at 22:42, Pablo Garrido notifications@github.com wrote:

FreeRTOS/Inc/FreeRTOSConfig.h is generated is step:

Inside STM32CubeMX load FreeRTOS/sample_project.ioc and generate code.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eProsima/Micro-XRCE-DDS-Apps/issues/9#issuecomment-716432202, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCYQVSIJUF6OLOAPFPMCY3SMVAADANCNFSM4S5R4W6Q .

pablogs9 commented 3 years ago

Please share a fork of this repo with your changes, I would like to replicate your procedure.

vibnwis commented 3 years ago

I found the issue. After using STM32CubeMX using the "continue" option (not "migrate") it generated the file structure and the files in the right folders. Yes, you are right about the I regenerated the files and others as well.

My knowledge of using git is very limited, also I have not spent time reading how to do the "fork" thingy yet. Anyway, I should to the reading now, and get that submitted.

On Mon, 26 Oct 2020 at 23:31, Pablo Garrido notifications@github.com wrote:

Please share a fork of this repo with your changes, I would like to replicate your procedure.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eProsima/Micro-XRCE-DDS-Apps/issues/9#issuecomment-716457889, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCYQVQMEY2AZCRV4MNTZNLSMVFX7ANCNFSM4S5R4W6Q .

vibnwis commented 3 years ago

I presume it is okie to create the folder sys for the time.h as suggested in README.md.

On Mon, 26 Oct 2020 at 23:40, vibnwis vibnwis@gmail.com wrote:

I found the issue. After using STM32CubeMX using the "continue" option (not "migrate") it generated the file structure and the files in the right folders. Yes, you are right about the I regenerated the files and others as well.

My knowledge of using git is very limited, also I have not spent time reading how to do the "fork" thingy yet. Anyway, I should to the reading now, and get that submitted.

On Mon, 26 Oct 2020 at 23:31, Pablo Garrido notifications@github.com wrote:

Please share a fork of this repo with your changes, I would like to replicate your procedure.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eProsima/Micro-XRCE-DDS-Apps/issues/9#issuecomment-716457889, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCYQVQMEY2AZCRV4MNTZNLSMVFX7ANCNFSM4S5R4W6Q .

vibnwis commented 3 years ago

Further, "make" stopped at the following error, make: *** No rule to make target '/home/wiki-ros/microROS/Micro-XRCE-DDS-Apps/FreeRTOS/build/FreeRTOS_POSIX_utils.o', needed by '/home/wiki-ros/microROS/Micro-XRCE-DDS-Apps/FreeRTOS/build/sample_project.elf'. Stop.

Any idea what that is? Appreciate your help.

Cheers!

On Tue, 27 Oct 2020 at 00:38, vibnwis vibnwis@gmail.com wrote:

I presume it is okie to create the folder sys for the time.h as suggested in README.md.

On Mon, 26 Oct 2020 at 23:40, vibnwis vibnwis@gmail.com wrote:

I found the issue. After using STM32CubeMX using the "continue" option (not "migrate") it generated the file structure and the files in the right folders. Yes, you are right about the I regenerated the files and others as well.

My knowledge of using git is very limited, also I have not spent time reading how to do the "fork" thingy yet. Anyway, I should to the reading now, and get that submitted.

On Mon, 26 Oct 2020 at 23:31, Pablo Garrido notifications@github.com wrote:

Please share a fork of this repo with your changes, I would like to replicate your procedure.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eProsima/Micro-XRCE-DDS-Apps/issues/9#issuecomment-716457889, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCYQVQMEY2AZCRV4MNTZNLSMVFX7ANCNFSM4S5R4W6Q .

pablogs9 commented 3 years ago

Are you initing and building this submodule: https://github.com/eProsima/Micro-XRCE-DDS-Apps/tree/feature/refactor_nuttx/FreeRTOS/Middlewares/Third_Party ?

vibnwis commented 3 years ago

No, but building under FrerRTOS folder. I edited the Makefile to include the new files , make it.

On Tue, 27 Oct 2020 at 2:20 AM, Pablo Garrido notifications@github.com wrote:

Are you initing and building this submodule: https://github.com/eProsima/Micro-XRCE-DDS-Apps/tree/feature/refactor_nuttx/FreeRTOS/Middlewares/Third_Party ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eProsima/Micro-XRCE-DDS-Apps/issues/9#issuecomment-716540895, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCYQVTS24FOSBN4WUONOTLSMVZRTANCNFSM4S5R4W6Q .

vibnwis commented 3 years ago

I revisited the steps. Yes, I did init the submodule and update the submodule. I re-do it again, by renaming the existing ones. However, yes, I did notice that since the very first time, I had the similar previously too as what I am experiencing now. See the errors below. Very appreciate your comments, please.

iki-ros@wikiros-NUC8i5BEH:~/microROS/Micro-XRCE-DDS-Apps$ git submodule init
wiki-ros@wikiros-NUC8i5BEH:~/microROS/Micro-XRCE-DDS-Apps$ git submodule update
Cloning into '/home/wiki-ros/microROS/Micro-XRCE-DDS-Apps/FreeRTOS/Middlewares/Third_Party/FreeRTOS_POSIX'...
Cloning into '/home/wiki-ros/microROS/Micro-XRCE-DDS-Apps/Nuttx/apps'...
remote: Repository nuttx/apps not found
fatal: repository 'https://bitbucket.org/nuttx/apps.git/' not found
fatal: clone of 'https://bitbucket.org/nuttx/apps.git' into submodule path '/home/wiki-ros/microROS/Micro-XRCE-DDS-Apps/Nuttx/apps' failed
Failed to clone 'Nuttx/apps'. Retry scheduled
Cloning into '/home/wiki-ros/microROS/Micro-XRCE-DDS-Apps/Nuttx/nuttx'...
remote: Repository nuttx/nuttx not found
fatal: repository 'https://bitbucket.org/nuttx/nuttx.git/' not found
fatal: clone of 'https://bitbucket.org/nuttx/nuttx.git' into submodule path '/home/wiki-ros/microROS/Micro-XRCE-DDS-Apps/Nuttx/nuttx' failed
Failed to clone 'Nuttx/nuttx'. Retry scheduled
Cloning into '/home/wiki-ros/microROS/Micro-XRCE-DDS-Apps/Nuttx/apps'...
remote: Repository nuttx/apps not found
vibnwis commented 3 years ago

Also, I notice that ' https://github.com/eProsima/Micro-XRCE-DDS-Apps/tree/feature/refactor_nuttx/FreeRTOS/Middlewares/Third_Party " Has the ../tree/... which does not appear in my local repository folder. Should I add the above module into my local repo? If so, will the file structure remain the same? Kindly advise, please?

On Tue, 27 Oct 2020 at 02:20, Pablo Garrido notifications@github.com wrote:

Are you initing and building this submodule: https://github.com/eProsima/Micro-XRCE-DDS-Apps/tree/feature/refactor_nuttx/FreeRTOS/Middlewares/Third_Party ?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eProsima/Micro-XRCE-DDS-Apps/issues/9#issuecomment-716540895, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCYQVTS24FOSBN4WUONOTLSMVZRTANCNFSM4S5R4W6Q .

vibnwis commented 3 years ago

Pardon my ignorance. IDespite using the Makefile , modified to local system, under the FreeRTOS, I tried to use the cmake, probably not necessary, to create the Makefile. What i did were, under the FreeRTOS, $ mkdir build; cd build $ cmake ..

Unfortunately, I got this error, CMake Error: The source directory "/home/wiki-ros/microROS/Micro-XRCE-DDS-Apps/FreeRTOS" does not appear to contain CMakeLists.txt. Apparently in FreeRTOS, it does not have CMakeLists.txt. Here is my question, where or which CMakeLists.txt should it be? as when I searched, tons of them came up.

On Mon, 26 Oct 2020 at 19:27, Pablo Garrido notifications@github.com wrote:

Usually when using CMake for configuring and building Micro XRCE-DDS Client the config.h.in file is used to generate a config.h based on the current configuration https://github.com/eProsima/Micro-XRCE-DDS-Client/blob/66df0a6df20063d246dd638ac3d33eb2e652fab2/CMakeLists.txt#L349. You can read more about CMake configure file here https://cmake.org/cmake/help/latest/command/configure_file.html.

In fact here https://github.com/eProsima/Micro-XRCE-DDS-Apps/blob/263e0c07d7f67503651423d77094df03872937e8/FreeRTOS/Makefile#L308 you can see how the XRCE library is being build using CMake.

Of course, you can manually generate a config.h based on your desired configuration. Feel free to ask if you want to know more about certain config flags.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eProsima/Micro-XRCE-DDS-Apps/issues/9#issuecomment-716334135, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCYQVQ3BOQN33OVO67DVC3SMUJF7ANCNFSM4S5R4W6Q .

vibnwis commented 3 years ago

libmicroxrcedds: arm_toolchain cd $(PROJECTFOLDER)/../Micro-XRCE-DDS-Client; rm -rf build; mkdir build; cd build; \ cmake .. -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DUCLIENT_PIC=OFF -DUCLIENT_BIG_ENDIANNESS=OFF -DUCLIENT_ISOLATED_INSTALL=OFF -DCMAKE_INSTALL_PREFIX=$(PROJECTFOLDER)/micro_xrce_dds_install -DCMAKE_TOOLCHAIN_FILE=$(PROJECTFOLDER)/arm_toolchain.cmake && make && make install;

From the Makefile lines above, I can see that the execution begins in Micro-XRCE-DDS-Client by removing and recreating build folder, and then run cmake .. (CMakeLists.txt the parent folder). However, the local repo, Micro-XRCE-DDS-Apps's Micro-XRCE-DDS-Client folder is empty.

Appreciate your advice. Thanks

pablogs9 commented 3 years ago

Sorry, @vibnwis I have completely lost the line of your procedure for building this. I only can provide support if a complete and reproducible list of commands/instructions is provided. Also is required if possible a repo containing the code you are using.

I need to reproduce the errors in order to provide solutions.

vibnwis commented 3 years ago

Hi Pablo, Ever since you suggested to reproduce the errors, I have been working on "Fork" and trying to push to my remote repo, somehow, I encountered errors and errors. I know very strange. It is due to my limited knowledge of git. I will continue to tomorrow again. Meanwhile, can you work on those zip files. Basically, I have added three files FreeRTOS/Src/CAN_utils.c FreeRTOS/Src/circularByteBuffer.c FreeRTOS/Src/SWV_redirect.c, their headers files, CAN_utils.h, circularByteBuffer.h and common.h. The main.c and other files which instructed by README.md. Would you able to compile at your end with those? I have not worked on the udp_transport.c as I see, I need to able to get working (error free development environment) before proceeding further. My local fork repo, have all the files and have the folders, but the remote repo has only newly added files, no modified files, such as main.c. I will try again tomorrow.

Meanwhile, you can get the my local repo, zipped entire local repo folder, in the following link,

[https://files.mycloud.com/home.php?brand=webfiles&seuuid=6695df5c79e21f6d49954cdd9d6a18f5&name=my-Micro-XRCE-DDS-Apps]

vibnwis commented 3 years ago

Hi Pablo, I think, I have got the fork repo update to the level I could despite only the submodule Third_Party/FreeRTOS_Posix and the rest are not able to update to fork. I guess, all the files needed for it should be sufficient for you to try out. I run out of idea for now. Your assistance is very much appreciated.

pablogs9 commented 3 years ago

Usual build:

My steps are:

sudo apt update
sudo apt install build-essential cmake git openocd gcc-arm-none-eabi usbutils
git clone https://github.com/eProsima/Micro-XRCE-DDS-Apps

cd Micro-XRCE-DDS-Apps
git submodule init
git submodule update

# Open FreeRTOS/sample_project.ioc with STMCubeMX and click on generate project

cd FreeRTOS
touch Middlewares/Third_Party/FreeRTOS_POSIX/include/FreeRTOS_POSIX/sys/time.h
touch Middlewares/Third_Party/FreeRTOS_POSIX/include/FreeRTOS_POSIX/sys/timeval.h 
echo '''
#ifndef _FREERTOS_POSIX_SYSTIME_H_
#define _FREERTOS_POSIX_SYSTIME_H_

struct timeval {
  long    tv_sec;         /* seconds */
  long    tv_usec;        /* and microseconds */
};

#endif /* ifndef _FREERTOS_POSIX_SYSTIME_H_ */
''' > Middlewares/Third_Party/FreeRTOS_POSIX/include/FreeRTOS_POSIX/sys/time.h

# Now add these lines to FreeRTOS/Inc/FreeRTOSConfig.h line 45:
##define configUSE_POSIX_ERRNO 1
##define INCLUDE_xTaskGetHandle 1

cp -rf main_template.c Src/main.c

make libmicroxrcedds
make UXRCEDDS_AGENT_IP=192.168.1.100 UXRCEDDS_AGENT_PORT=8888

This may give you an error when building libmicroxrcedds. Go to /Micro-XRCE-DDS-Client/src/c/profile/transport/ip/udp/udp_transport_posix_nopoll.c and add this include:

#include <sys/time.h>

This should be fixed by https://github.com/eProsima/Micro-XRCE-DDS-Client/pull/172

Adding CAN support build:

Once we have all the previous steps done, is possible to open again FreeRTOS/sample_project.ioc with STMCubeMX, enable CAN1 and CAN2 and click on generate code.

In order to add a new custom transport based on UPD-like transport:

cd Micro-XRCE-DDS-Apps/Micro-XRCE-DDS-Client/src/c/profile/transport/ip/udp
cp udp_transport_external.c.template udp_transport_external.c

cd Micro-XRCE-DDS-Apps/Micro-XRCE-DDS-Client/include/uxr/client/profile/transport/ip/udp
cp udp_transport_external.h.template udp_transport_external.h

# Now you have two files where you have to implement you CAN transports

Ok, let's tell the library build that it should use this external transport. In FreeRTOS/Makefile line 311 we are using CMake to build the library. Check the line:

cmake .. -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DUCLIENT_PIC=OFF -DUCLIENT_BIG_ENDIANNESS=OFF -DUCLIENT_ISOLATED_INSTALL=OFF -DCMAKE_INSTALL_PREFIX=$(PROJECTFOLDER)/micro_xrce_dds_install -DCMAKE_TOOLCHAIN_FILE=$(PROJECTFOLDER)/arm_toolchain.cmake && make && make install;

We can tell the library to use the external transport by adding this:

-DUCLIENT_EXTERNAL_UDP=ON

This flag will tell the library to use udp_transport_external.c and udp_transport_external.h

So let's rebuild the library:

rm -rf Micro-XRCE-DDS-Client/build

cd FreeRTOS
make libmicroxrcedds
make
vibnwis commented 3 years ago

Very grateful for those steps. The new steps you sent are really helpful.

Also, may I ask through JTag, what and how do you upload binaries to the target board, please?

pablogs9 commented 3 years ago

You have the JTAG we are using in the Required hardware section

Reguarding the how, you have the openocd command in the Build section

vibnwis commented 3 years ago

Sweet! Will do.

vibnwis commented 3 years ago

I have added all needed CAN-bus files, and succeeded compiling without error. Many thanks.

As a reference for others who may use the steps, I would like to add a step i.e., to add your source (.c) files under the C_SOURCES = \

vibnwis commented 3 years ago

Would you mind share the config.cfg and script.ocd for the Olimex Jtag please?

pablogs9 commented 3 years ago

I guess that OpenOCD comes with the Olimex ARM-USB-TINY-H and the Olimex STM32-E407 support integrated. Check this flashing script, I not aware of installing these files, so I guess that they came preinstalled.

vibnwis commented 3 years ago

Those work with changes to local binaries. You are right, they come preinstalled.

On Thu, 29 Oct 2020 at 19:19, Pablo Garrido notifications@github.com wrote:

I guess that OpenOCD comes with the Olimex ARM-USB-TINY-H and the Olimex STM32-E407 support integrated. Check this flashing script https://github.com/micro-ROS/micro_ros_setup/blob/foxy/config/freertos/olimex-stm32-e407/flash.sh, I not aware of installing these files, so I guess that they came preinstalled.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eProsima/Micro-XRCE-DDS-Apps/issues/9#issuecomment-718386872, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCYQVRWB7V7QQCY34F7ZOTSNECPZANCNFSM4S5R4W6Q .

vibnwis commented 3 years ago

Hi Pablo, Something share. I managed to use Eclipse to compile the project, and also run cross gdb in Eclipse which allows single stepping. That is very so useful for someone new of the Micro-XRCE-DDS-Apps like me.

vibnwis commented 3 years ago

I see that in udp_transport.c the function uxr_init_udp_transport(..) has the "transport" argument, but not in udp_transport_external.c. Without the transport field, the functions send_can_msg, recv_can_msg, can not be established and later get called. Also the uxr_init_udp_platform() is being called in it own, the transport variable are being declared any where, nor being extern in udp_transport_external.c. I am going to change the functions to uxr_init_can_transport(), uxr_close_can_transport() following the udp_transport.c structure. It makes more sense. Anyway, I do value your input. Hence, feel free to comment.

uxr_init_udp_transport( uxrUDPTransport* transport, struct uxrUDPPlatform* platform, uxrIpProtocol ip_protocol, const char* ip, const char* port) ool uxr_init_udp_platform( uxrUDPPlatform* platform, uxrIpProtocol ip_protocol, const char* ip, const char* port)
vibnwis commented 3 years ago

Hi Pablo,

I have resolved the UART printf() thingy. Thank you for your patience. BTW, I have also succeeded in integrating (ie compiling) the CAN-bus into the external transport. Now I am moving to Raspberry Pi 4. I was wondering if you are aware that the previous resolution still generating errors. Anyway, very grateful for your assistance.

pablogs9 commented 3 years ago

I'm not sure that I have understood all the problem in your previous comment, but if you are wondering how to maintain a structure that is passed to all you callback functions please check the here. This struct can be modified with all your platform required data, it can be init in the init function and the library will pass it to all you calls to write/read/end.

You can see an example of how to use it here.

vibnwis commented 3 years ago

Thank you for the answers. That truly helps to reinforce my understanding. All good,

vibnwis commented 3 years ago

Very appreciate the assistance provided. I would not have gone so far without the thorough explanation. Apologies for being impatience.