Skip to content

Commit

Permalink
Add wchar support (#349)
Browse files Browse the repository at this point in the history
* Add wchar support and .idl example

* Undo automatic IDE formatting noise

* Added back unused imports to see if this fixes the build

* More attempts to fix the weird build failure

* Removed the linter tests for auto-generated message source files in `rclrs_example_msgs`. Re-applied some changes removed when root causing.

---------

Co-authored-by: Sam Privett <[email protected]>
  • Loading branch information
maspe36 and maspe36 authored Jan 9, 2024
1 parent 812b91a commit 3fb5e5f
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 7 deletions.
9 changes: 9 additions & 0 deletions examples/message_demo/src/message_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ fn check_default_values() {
);
}

fn check_default_idl_values() {
let idiomatic_msg = rclrs_example_msgs::msg::MyMessage::default();
let rmw_msg = rclrs_example_msgs::msg::rmw::MyMessage::default();

assert_eq!(idiomatic_msg.wchar_value, 0u16);
assert_eq!(rmw_msg.wchar_value, 0u16);
}

fn demonstrate_printing() {
let default_msg = rclrs_example_msgs::msg::VariousTypes::default();
println!("================== Compact debug representation ==================");
Expand Down Expand Up @@ -170,6 +178,7 @@ fn demonstrate_pubsub() -> Result<(), Error> {

fn main() -> Result<(), Error> {
check_default_values();
check_default_idl_values();
demonstrate_printing();
demonstrate_serde()?;
demonstrate_sequences();
Expand Down
3 changes: 2 additions & 1 deletion rclrs_example_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ find_package(rosidl_default_generators REQUIRED)
set(msg_files
"msg/NestedType.msg"
"msg/VariousTypes.msg"
"msg/MyMessage.idl"
)

rosidl_generate_interfaces(${PROJECT_NAME}
${msg_files}
ADD_LINTER_TESTS
)

ament_export_dependencies(rosidl_default_runtime)
Expand Down
86 changes: 86 additions & 0 deletions rclrs_example_msgs/msg/MyMessage.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Taken and slightly adapted from
// https://github.com/ros2/rosidl/blob/iron/rosidl_parser/test/msg/MyMessage.idl

module rclrs_example_msgs {
module msg {
module MyMessage_Constants {
const short SHORT_CONSTANT = -23;
const unsigned long UNSIGNED_LONG_CONSTANT = 42;
const float FLOAT_CONSTANT = 1.25;
const boolean BOOLEAN_CONSTANT = TRUE;
const string STRING_CONSTANT = "string_value";
const wstring WSTRING_CONSTANT = "wstring_value_\u2122";
const string EMPTY_STRING_CONSTANT = "";
};

@verbatim ( language="comment", text="Documentation of MyMessage." "Adjacent string literal." )
@transfer_mode(SHMEM_REF)
struct MyMessage {
short short_value, short_value2;
@default ( value=123 )
unsigned short unsigned_short_value;
@key
@range ( min=-10, max=10 )
long long_value;
@verbatim (language="comment", text="")
unsigned long unsigned_long_value;
long long long_long_value;
unsigned long long unsigned_long_long_value;
float float_value;
double double_value;
// long double long_double_value;
char char_value;
wchar wchar_value;
boolean boolean_value;
octet octet_value;
int8 int8_value;
uint8 uint8_value;
int16 int16_value;
uint16 uint16_value;
int32 int32_value;
uint32 uint32_value;
int64 int64_value;
uint64 uint64_value;
string string_value;
string<5> bounded_string_value;
wstring wstring_value;
wstring<23> bounded_wstring_value;
// wstring<UNSIGNED_LONG_CONSTANT> constant_bounded_wstring_value;
sequence<short> unbounded_short_values;
sequence<short, 5> bounded_short_values;
sequence<string<3>> unbounded_values_of_bounded_strings;
sequence<string<3>, 4> bounded_values_of_bounded_strings;
short array_short_values[23];

// Tests of the floating point parser (7.2.6.4)
@default ( value=1.9e10 )
float int_and_frac_with_positive_scientific;
@default ( value=1.9e+10 )
float int_and_frac_with_explicit_positive_scientific;
@default ( value=1.1e-10)
float int_and_frac_with_negative_scientific;
@default ( value=0.00009 )
float int_and_frac;
@default ( value = 1. )
float int_with_empty_frac;
@default ( value = .1 )
float frac_only;
@default ( value=9e05 )
float int_with_positive_scientific;
@default ( value=9e+05 )
float int_with_explicit_positive_scientific;
@default ( value=9e-05 )
float int_with_negative_scientific;

// Tests of the fixed point parser (7.2.6.5)
@default ( value=8.7d )
float fixed_int_and_frac;
@default ( value=4.d )
float fixed_int_with_dot_only;
@default ( value=.3d )
float fixed_frac_only;
@default ( value=7d )
float fixed_int_only;
};
};
};
9 changes: 3 additions & 6 deletions rosidl_generator_rs/rosidl_generator_rs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import os
import pathlib
import subprocess

from pathlib import Path

Expand All @@ -24,12 +23,7 @@
import rosidl_pycommon

from rosidl_parser.definition import AbstractGenericString
from rosidl_parser.definition import AbstractNestedType
from rosidl_parser.definition import AbstractSequence
from rosidl_parser.definition import AbstractString
from rosidl_parser.definition import AbstractWString
from rosidl_parser.definition import Array
from rosidl_parser.definition import BASIC_TYPES
from rosidl_parser.definition import BasicType
from rosidl_parser.definition import BoundedSequence
from rosidl_parser.definition import BoundedString
Expand Down Expand Up @@ -219,6 +213,7 @@ def primitive_value_to_rs(type_, value):
if type_.type in [
'byte',
'char',
'wchar',
'int8',
'uint8',
'int16',
Expand Down Expand Up @@ -311,6 +306,8 @@ def get_rmw_rs_type(type_):
return 'u8'
elif type_.typename == 'char':
return 'u8'
elif type_.typename == 'wchar':
return 'u16'
elif type_.typename == 'float':
return 'f32'
elif type_.typename == 'double':
Expand Down

0 comments on commit 3fb5e5f

Please sign in to comment.