@@ -37,6 +37,7 @@ extern EyeManager eye;
3737
3838ros::Subscriber<geometry_msgs::Point> sub_point (" ~look_at" , &callback_look_at);
3939ros::Subscriber<std_msgs::String> sub_eye_status (" ~eye_status" , &callback_emotion);
40+
4041void callback_look_at (const geometry_msgs::Point &msg)
4142{
4243 eye.set_gaze_direction ((float )msg.x , (float )msg.y );
@@ -49,13 +50,6 @@ void callback_emotion(const std_msgs::String &msg)
4950std::string ros_read_asset ()
5051{
5152 std::map<std::string, EyeAsset>& eye_asset_map = eye.eye_asset_map ;
52- while (not nh.connected ())
53- {
54- nh.spinOnce ();
55- delay (1000 );
56- }
57- delay (500 ); // wait 0.5 sec before reading asset
58-
5953 std::ostringstream oss;
6054
6155 bool mode_right;
@@ -77,94 +71,102 @@ std::string ros_read_asset()
7771 oss << " eye_asset_names: " ;
7872 for (auto it = eye_asset_names.begin (); it != eye_asset_names.end (); ++it) {
7973 std::string name = *it;
80- std::string suffix = " _extra" ;
81- if (name.size () >= suffix.size () &&
82- name.rfind (suffix) == name.size () - suffix.size ()) {
83- name = name.substr (0 , name.size () - suffix.size ());
84- }
8574 oss << name;
8675 if (std::next (it) != eye_asset_names.end ()) oss << " , " ;
8776 }
8877 oss << " \n " ;
8978 //
9079 for (auto name: eye_asset_names) {
9180 char eye_asset_map_key[256 ];
92- bool have_extra = false ;
93- std::string suffix = " _extra" ;
94- if (name.size () >= suffix.size () &&
95- name.rfind (suffix) == name.size () - suffix.size ()) {
96- name = name.substr (0 , name.size () - suffix.size ());
97- have_extra = true ;
98- }
99- // path_upperlid
100- for (const std::string& type: {" upperlid" , " outline" , " iris" , " pupil" , " reflex" }) {
81+
82+ // path
83+ std::vector<std::string> eye_types;
84+ snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset_%s_eye_types" , name.c_str ());
85+ nh.getParam (eye_asset_map_key, eye_types);
86+ for (const std::string& type: eye_types) {
10187 std::string path;
10288 snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/path_%s" , name.c_str (), type.c_str ());
10389 if (nh.getParam (eye_asset_map_key, path)) {
10490 oss << " eye_asset_image_path: " << name << " : " << type << " : " << path << " \n " ;
10591 }
10692 }
107- // upperlid_position, upperlid_default_pos_x, upperlid_default_pos_y, upperlid_default_theta
108- std::vector<int > position;
109- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/upperlid_position" , name.c_str ());
110- if (nh.getParam (eye_asset_map_key, position, 300 )) { // timeout == 300
111- oss << " eye_asset_position: " << name << " : upperlid: " << joinVector (position) << " \n " ;
112- } else { // v2 API, upperlid_position_x, upperlid_position_y, upperlid_rotate_theta instead of upperlid_position
113- nh.logwarn (" Using v2 API (position_x, position_y, rotation_theta). Please ignore the above 'Parameter %sn does not exist' message" , eye_asset_map_key);
114- std::vector<int > position_x, position_y, rotation_theta;
115- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/upperlid_position_x" , name.c_str ());
116- if (nh.getParam (eye_asset_map_key, position_x)) {
117- oss << " eye_asset_position_x: " << name << " : upperlid: " << joinVector (position_x) << " \n " ;
118- }
119- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/upperlid_position_y" , name.c_str ());
120- if (nh.getParam (eye_asset_map_key, position_y)) {
121- oss << " eye_asset_position_y: " << name << " : upperlid: " << joinVector (position_y) << " \n " ;
122- }
123- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/upperlid_rotation_theta" , name.c_str ());
124- if (nh.getParam (eye_asset_map_key, rotation_theta)) {
125- oss << " eye_asset_rotation_theta: " << name << " : upperlid: " << joinVector (rotation_theta) << " \n " ;
126- }
127- } // v2 API
128- for (const std::string& pos: {" default_pos_x" , " default_pos_y" , " default_theta" }) {
129- int data;
130- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/upperlid_%s" , name.c_str (), pos.c_str ());
131- if (nh.getParam (eye_asset_map_key, &data)) {
132- oss << " eye_asset_" << pos << " : " << name << " : upperlid: " << data << " \n " ;
93+
94+ // position
95+ std::vector<std::string> eye_positions;
96+ snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset_%s_positions" , name.c_str ());
97+ nh.getParam (eye_asset_map_key, eye_positions);
98+ for (const std::string& eye_position: eye_positions) {
99+ if (eye_position == " NONE" ) continue ;
100+ std::vector<int > position;
101+ snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/%s" , name.c_str (), eye_position.c_str ());
102+ if (nh.getParam (eye_asset_map_key, position)) {
103+ size_t pos = eye_position.find (' _' );
104+ if ( pos != std::string::npos ) {
105+ std::string eye_type = eye_position.substr (0 , pos);
106+ std::string position_type = eye_position.substr (pos+1 );
107+ oss << " eye_asset_" << position_type << " : " << name << " : " << eye_type << " : " << joinVector (position) << " \n " ;
108+ } else {
109+ logerror (" Invalid param name : %s" , eye_position);
110+ }
133111 }
134112 }
135- // v3 API (extra images)
136- if (have_extra) {
137- for (const std::string& type: {" extra1" , " extra2" }) {
138- std::string path;
139- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/path_%s" , name.c_str (), type.c_str ());
140- if (nh.getParam (eye_asset_map_key, path, 300 )) { // timeout == 300
141- oss << " eye_asset_image_path: " << name << " : " << type << " : " << path << " \n " ;
142- }
143- std::vector<int > position_x, position_y, rotation_theta;
144- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/%s_position_x" , name.c_str (), type.c_str ());
145- if (nh.getParam (eye_asset_map_key, position_x)) {
146- oss << " eye_asset_position_x: " << name << " : " << type << " : " << joinVector (position_x) << " \n " ;
147- }
148- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/%s_position_y" , name.c_str (), type.c_str ());
149- if (nh.getParam (eye_asset_map_key, position_y)) {
150- oss << " eye_asset_position_y: " << name << " : " << type << " : " << joinVector (position_y) << " \n " ;
151- }
152- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/%s_rotation_theta" , name.c_str (), type.c_str ());
153- if (nh.getParam (eye_asset_map_key, rotation_theta)) {
154- oss << " eye_asset_rotation_theta: " << name << " : " << type << " : " << joinVector (rotation_theta) << " \n " ;
155- }
156- int data;
157- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/%s_default_pos_x" , name.c_str (), type.c_str ());
158- if (nh.getParam (eye_asset_map_key, &data)) {
159- oss << " eye_asset_default_pos_x: " << name << " : " << type << " : " << data << " \n " ;
113+
114+ // rotation
115+ std::vector<std::string> eye_rotations;
116+ snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset_%s_rotations" , name.c_str ());
117+ nh.getParam (eye_asset_map_key, eye_rotations);
118+ for (const std::string& eye_rotation: eye_rotations) {
119+ if (eye_rotation == " NONE" ) continue ;
120+ std::vector<int > rotation;
121+ snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/%s" , name.c_str (), eye_rotation.c_str ());
122+ if (nh.getParam (eye_asset_map_key, rotation)) {
123+ size_t pos = eye_rotation.find (' _' );
124+ if ( pos != std::string::npos ) {
125+ std::string eye_type = eye_rotation.substr (0 , pos);
126+ std::string rotation_type = eye_rotation.substr (pos+1 );
127+ oss << " eye_asset_" << rotation_type << " : " << name << " : " << eye_type << " : " << joinVector (rotation) << " \n " ;
128+ } else {
129+ logerror (" Invalid param name : %s" , eye_rotation);
160130 }
161- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/%s_default_pos_y" , name.c_str (), type.c_str ());
162- if (nh.getParam (eye_asset_map_key, &data)) {
163- oss << " eye_asset_default_pos_y: " << name << " : " << type << " : " << data << " \n " ;
131+ }
132+ }
133+
134+ // default
135+ std::vector<std::string> eye_defaults;
136+ snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset_%s_defaults" , name.c_str ());
137+ nh.getParam (eye_asset_map_key, eye_defaults);
138+ for (const std::string& eye_default: eye_defaults) {
139+ if (eye_default == " NONE" ) continue ;
140+ std::vector<int > defaults;
141+ snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/%s" , name.c_str (), eye_default.c_str ());
142+ if (nh.getParam (eye_asset_map_key, defaults)) {
143+ size_t pos = eye_default.find (' _' );
144+ if ( pos != std::string::npos ) {
145+ std::string eye_type = eye_default.substr (0 , pos);
146+ std::string default_type = eye_default.substr (pos+1 );
147+ oss << " eye_asset_" << default_type << " : " << name << " : " << eye_type << " : " << joinVector (defaults) << " \n " ;
148+ } else {
149+ logerror (" Invalid param name : %s" , eye_default);
164150 }
165- snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/%s_default_theta" , name.c_str (), type.c_str ());
166- if (nh.getParam (eye_asset_map_key, &data)) {
167- oss << " eye_asset_default_theta: " << name << " : " << type << " : " << data << " \n " ;
151+ }
152+ }
153+
154+ // zoom
155+ std::vector<std::string> eye_zooms;
156+ snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset_%s_zooms" , name.c_str ());
157+ nh.getParam (eye_asset_map_key, eye_zooms);
158+ for (const std::string& eye_zoom: eye_zooms) {
159+ if (eye_zoom == " NONE" ) continue ;
160+ std::vector<float > zooms;
161+ snprintf (eye_asset_map_key, sizeof (eye_asset_map_key), " ~eye_asset/%s/%s" , name.c_str (), eye_zoom.c_str ());
162+ if (nh.getParam (eye_asset_map_key, zooms)) {
163+ size_t pos = eye_zoom.find (' _' );
164+ if ( pos != std::string::npos ) {
165+ std::string eye_type = eye_zoom.substr (0 , pos);
166+ std::string zoom_type = eye_zoom.substr (pos+1 );
167+ oss << " eye_asset_" << zoom_type << " : " << name << " : " << eye_type << " : " << joinVector (zooms) << " \n " ;
168+ } else {
169+ logerror (" Invalid param name : %s" , eye_zoom);
168170 }
169171 }
170172 }
0 commit comments