robin icon indicating copy to clipboard operation
robin copied to clipboard

Custom messages from CodeSys structs: Error parsing Array of Strings

Open 2b-t opened this issue 3 years ago • 2 comments

Hey again, I have encountered another error when creating custom messages from CodeSys structs similar to the previously reported issue #10. When using the data type ARRAY[1..n] OF STRING as a message type in a custom struct such as

TYPE TestStruct :
STRUCT
	var_string: ARRAY[1..32] OF STRING;
END_STRUCT
END_TYPE

with a program in structured text

PROGRAM ROS_PRG
VAR_INPUT
	struct_to_codesys: TestStruct;
END_VAR
VAR
	robin: Robin;
END_VAR

that contains a subscriber (the corresponding publisher seems to work)

robin();
robin.read('struct_to_codesys', struct_to_codesys);

this results in the error message

* * * * * * * * * * * * *
* * * Robin Updater * * *
* * * * * * * * * * * * *

Creating SSH key ...

Adding SSH key to agent ...
Identity added: C:\Users\lab\.ssh\robin_key (C:\Users\lab\.ssh\robin_key)

Adding SSH key to target ... Password will be required
[email protected]'s password:
[sudo] password for user: Accessing target through ssh... Ensure ssh service is ON. 
Connecting... 
sa-sha2-512)
warning: agent returned different signature type ssh-rsa (expected rsa-sha2-512)

Generating source code...

Generating new ros package robin_bridge_generated...

Recompiling...
NOTICE: Could not determine the width of the terminal. A default width of 80 will be used. This warning will only be printed once.
_______________________________________________________________________________
Errors << robin_bridge_generated:make /home/user/catkin_ws/logs/robin_bridge_generated/build.make.118.log
/home/user/catkin_ws/src/robin_bridge_generated/src/robin_bridge_generated/robin_inst.cpp: In member function ?void RobinSubscriber<T1, T2>::write(const T2*) [with T1 = TestStruct; T2 = robin_bridge_generated::TestStruct_<std::allocator<void> >]?:
/home/user/catkin_ws/src/robin_bridge_generated/src/robin_bridge_generated/robin_inst.cpp:14:43: error: invalid conversion from ?char? to ?char*? [-fpermissive]
     std::snprintf((*shm_ptr_).var_string[i_0], sizeof((*shm_ptr_).var_string[i_0]), "%s", (*msg_ptr).var_string[i_0].c_str());
                   ~~~~~~~~~~~~~~~~~~~~~~~~^
In file included from /usr/include/features.h:424:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:533,
                 from /usr/include/c++/7/cstdio:41,
                 from /home/user/catkin_ws/src/robin_bridge_generated/src/robin_bridge_generated/robin_inst.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:61:1: note:   initializing argument 1 of ?int snprintf(char*, size_t, const char*, ...)?
 __NTH (snprintf (char *__restrict __s, size_t __n,
 ^
make[2]: *** [CMakeFiles/robin_inst_generated.dir/src/robin_bridge_generated/robin_inst.cpp.o] Error 1
make[1]: *** [CMakeFiles/robin_inst_generated.dir/all] Error 2
make: *** [all] Error 2
cd /home/user/catkin_ws/build/robin_bridge_generated; catkin build --get-env robin_bridge_generated | catkin env -si  /usr/bin/make --jobserver-fds=6,7 -j; cd -
WARNING: Could not encode unicode characters. Please set the PYTHONIOENCODING environment variable to see complete output. (i.e. PYTHONIOENCODING=UTF-8)
...............................................................................
Failed << robin_bridge_generated:make            [ Exited with code 2 ]
Traceback (most recent call last):
  File "./updater.py", line 401, in <module>
    Updater().update(catkin_ws=catkin_ws)
  File "./updater.py", line 79, in update
    self._recompile_robin(catkin_ws)
  File "./updater.py", line 296, in _recompile_robin
    raise RuntimeError('Failed to recompile robin_bridge_generated package.')
RuntimeError: Failed to recompile robin_bridge_generated package.

when executing the start_update.py script.


The reason for this seems to be that the script generates a message of the form

struct TestStruct
{
  char var_string[32];
};

in robin_generated/include/robin_bridge_generated/structs.h instead of

struct TestStruct
{
  char var_string[32][81];
};

I still have to look into more detail into the source code of updater.py and srcgen.py to propose a potential fix on a code level for it.

2b-t avatar Mar 18 '21 14:03 2b-t