Fawkes API  Fawkes Development Version
naogui.h
00001 
00002 /***************************************************************************
00003  *  naogui.h - Nao GUI
00004  *
00005  *  Created: Mon Oct 27 17:10:58 2008
00006  *  Copyright  2008-2011  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #ifndef __PLUGINS_NAO_TOOLS_NAOGUI_NAOGUI_H_
00024 #define __PLUGINS_NAO_TOOLS_NAOGUI_NAOGUI_H_
00025 
00026 #include <gui_utils/connection_dispatcher.h>
00027 
00028 #include <gtkmm.h>
00029 
00030 namespace fawkes {
00031   class BlackBoard;
00032   class Interface;
00033   class NaoJointPositionInterface;
00034   class NaoJointStiffnessInterface;
00035   class NaoSensorInterface;
00036   class NavigatorInterface;
00037   class HumanoidMotionInterface;
00038   class SpeechSynthInterface;
00039   class InterfaceDispatcher;
00040   class LedInterface;
00041   class SwitchInterface;
00042 }
00043 
00044 class NaoGuiGtkWindow : public Gtk::Window
00045 {
00046  public:
00047   NaoGuiGtkWindow(BaseObjectType* cobject,
00048                   const Glib::RefPtr<Gtk::Builder> &builder);
00049   ~NaoGuiGtkWindow();
00050 
00051  private:
00052   void update_servo_value(Gtk::HScale *hsc, Gtk::Label *label, float value);
00053   void update_sensor_value(Gtk::Label *label, float value, bool show_decimal=true);
00054   void update_entry_value(Gtk::Entry *ent, float value, unsigned int width = 2);
00055   void update_ultrasonic_direction();
00056   void send_servo_msg(Gtk::HScale *hsc, unsigned int servo);
00057   void update_values(bool force = false);
00058   void update_jointpos_values(bool force = false);
00059   void update_sensor_values(bool force = false);
00060   bool servos_enabled() const;
00061   void update_tts();
00062 
00063   void on_led_data_changed(fawkes::Interface *iface);
00064   void on_button_data_changed(fawkes::Interface *iface);
00065 
00066   void on_stiffness_clicked();
00067   void on_control_toggled();
00068   void on_sv_copy_clicked();
00069   void on_us_emit_clicked();
00070   void on_us_auto_toggled();
00071   void on_goto_parkpos_clicked();
00072   void on_goto_zero_all_clicked();
00073   void on_get_up_clicked();
00074   void on_walkvel_exec_clicked();
00075   void on_ws_exec_clicked();
00076   void on_wsw_exec_clicked();
00077   void on_kick_exec_clicked();
00078   void on_standup_exec_clicked();
00079   void on_nav_exec_clicked();
00080   void on_wa_exec_clicked();
00081   void on_turn_exec_clicked();
00082   void on_motion_stop_clicked();
00083   void on_cf_read_clicked();
00084   void on_cf_write_clicked();
00085   void on_stiffness_write_clicked();
00086   void on_stiffness_read_clicked();
00087   void on_stiffness_global_toggled();
00088   void on_tts_exec_clicked();
00089   void on_slider_changed(Gtk::HScale *hsc, Gtk::Label *lab, unsigned int servo);
00090   void on_changed_speed();
00091   void on_connection_clicked();
00092   void on_connect();
00093   void on_disconnect();
00094   void on_exit_clicked();
00095 
00096   void on_control_leds_toggled();
00097   void on_led_tb_toggled(std::string iface_id, Gtk::ToggleButton *tb);
00098   void on_led_slider_changed(std::string iface_id, Gtk::Scale *scl);
00099   bool on_led_slider_button_release(GdkEventButton *event,
00100                                     std::string iface_id, Gtk::Scale *scl);
00101 
00102   void on_button_click_pressed(std::string iface_id);
00103   void on_button_click_released(std::string iface_id);
00104 
00105   bool convert_str2float(Glib::ustring sn, float *f);
00106   Glib::ustring convert_float2str(float f, unsigned int width = 2);
00107 
00108   void init();
00109 
00110 
00111  private:
00112   fawkes::BlackBoard *bb;
00113   fawkes::InterfaceDispatcher *ifd_jointpos;
00114   fawkes::InterfaceDispatcher *ifd_sensor;
00115   fawkes::InterfaceDispatcher *ifd_tts;
00116   fawkes::InterfaceDispatcher *ifd_leds;
00117   fawkes::InterfaceDispatcher *ifd_buttons;
00118   fawkes::NaoJointPositionInterface *jointpos_if;
00119   fawkes::NaoJointStiffnessInterface *jointstiff_if;
00120   fawkes::NaoSensorInterface *sensor_if;
00121   fawkes::NavigatorInterface *nao_navi_if;
00122   fawkes::SpeechSynthInterface *speechsynth_if;
00123   fawkes::HumanoidMotionInterface *hummot_fawkes_if;
00124   fawkes::HumanoidMotionInterface *hummot_naoqi_if;
00125   fawkes::ConnectionDispatcher connection_dispatcher;
00126 
00127   std::map<std::string, fawkes::LedInterface *> led_ifs;
00128   std::map<std::string, Gtk::Scale *> led_scales;
00129   std::map<std::string, Gtk::ToggleButton *> led_buttons;
00130 
00131   bool servo_enabled;
00132   bool global_stiffness_enabled;
00133 
00134   Gtk::Frame  *frm_servos;
00135   Gtk::Frame  *frm_sensors;
00136   Gtk::Frame  *frm_ultrasonic;
00137 
00138   Gtk::HScale *hsc_HeadYaw;
00139   Gtk::Label  *lab_HeadYaw;
00140   Gtk::HScale *hsc_HeadPitch;
00141   Gtk::Label  *lab_HeadPitch;
00142   Gtk::HScale *hsc_RShoulderPitch;
00143   Gtk::Label  *lab_RShoulderPitch;
00144   Gtk::HScale *hsc_RShoulderRoll;
00145   Gtk::Label  *lab_RShoulderRoll;
00146   Gtk::HScale *hsc_RElbowYaw;
00147   Gtk::Label  *lab_RElbowYaw;
00148   Gtk::HScale *hsc_RElbowRoll;
00149   Gtk::Label  *lab_RElbowRoll;
00150   Gtk::HScale *hsc_RWristYaw;
00151   Gtk::Label  *lab_RWristYaw;
00152   Gtk::HScale *hsc_RHand;
00153   Gtk::Label  *lab_RHand;
00154   Gtk::HScale *hsc_LShoulderPitch;
00155   Gtk::Label  *lab_LShoulderPitch;
00156   Gtk::HScale *hsc_LShoulderRoll;
00157   Gtk::Label  *lab_LShoulderRoll;
00158   Gtk::HScale *hsc_LElbowYaw;
00159   Gtk::Label  *lab_LElbowYaw;
00160   Gtk::HScale *hsc_LElbowRoll;
00161   Gtk::Label  *lab_LElbowRoll;
00162   Gtk::HScale *hsc_LWristYaw;
00163   Gtk::Label  *lab_LWristYaw;
00164   Gtk::HScale *hsc_LHand;
00165   Gtk::Label  *lab_LHand;
00166   Gtk::HScale *hsc_RHipYawPitch;
00167   Gtk::Label  *lab_RHipYawPitch;
00168   Gtk::HScale *hsc_RHipPitch;
00169   Gtk::Label  *lab_RHipPitch;
00170   Gtk::HScale *hsc_RHipRoll;
00171   Gtk::Label  *lab_RHipRoll;
00172   Gtk::HScale *hsc_RKneePitch;
00173   Gtk::Label  *lab_RKneePitch;
00174   Gtk::HScale *hsc_RAnklePitch;
00175   Gtk::Label  *lab_RAnklePitch;
00176   Gtk::HScale *hsc_RAnkleRoll;
00177   Gtk::Label  *lab_RAnkleRoll;
00178   Gtk::HScale *hsc_LHipYawPitch;
00179   Gtk::Label  *lab_LHipYawPitch;
00180   Gtk::HScale *hsc_LHipPitch;
00181   Gtk::Label  *lab_LHipPitch;
00182   Gtk::HScale *hsc_LHipRoll;
00183   Gtk::Label  *lab_LHipRoll;
00184   Gtk::HScale *hsc_LKneePitch;
00185   Gtk::Label  *lab_LKneePitch;
00186   Gtk::HScale *hsc_LAnklePitch;
00187   Gtk::Label  *lab_LAnklePitch;
00188   Gtk::HScale *hsc_LAnkleRoll;
00189   Gtk::Label  *lab_LAnkleRoll;
00190   Gtk::HScale *hsc_speed;
00191   Gtk::Label  *lab_speed;
00192   Gtk::ToolButton *tb_connection;
00193   Gtk::ToolButton *tb_stiffness;
00194   Gtk::ToggleToolButton *tb_control;
00195   Gtk::ToolButton *tb_getup;
00196   Gtk::ToolButton *tb_parkpos;
00197   Gtk::ToolButton *tb_zeroall;
00198   Gtk::ToolButton *tb_exit;
00199   Gtk::Label  *lab_l_fsr_fl;
00200   Gtk::Label  *lab_l_fsr_fr;
00201   Gtk::Label  *lab_l_fsr_rl;
00202   Gtk::Label  *lab_l_fsr_rr;
00203   Gtk::Label  *lab_r_fsr_fl;
00204   Gtk::Label  *lab_r_fsr_fr;
00205   Gtk::Label  *lab_r_fsr_rl;
00206   Gtk::Label  *lab_r_fsr_rr;
00207   Gtk::Label  *lab_r_cop;
00208   Gtk::Label  *lab_l_cop;
00209   Gtk::Label  *lab_r_total_weight;
00210   Gtk::Label  *lab_l_total_weight;
00211   Gtk::Label  *lab_chest_button;
00212   Gtk::Label  *lab_touch_front;
00213   Gtk::Label  *lab_touch_middle;
00214   Gtk::Label  *lab_touch_rear;
00215   Gtk::Label  *lab_l_bumper_l;
00216   Gtk::Label  *lab_l_bumper_r;
00217   Gtk::Label  *lab_r_bumper_l;
00218   Gtk::Label  *lab_r_bumper_r;
00219   Gtk::Label  *lab_accel_x;
00220   Gtk::Label  *lab_accel_y;
00221   Gtk::Label  *lab_accel_z;
00222   Gtk::Label  *lab_gyro_x;
00223   Gtk::Label  *lab_gyro_y;
00224   Gtk::Label  *lab_gyro_ref;
00225   Gtk::Label  *lab_angles_xy;
00226   Gtk::Label  *lab_ultrasonic_direction;
00227   Gtk::Label  *lab_ultrasonic_left0;
00228   Gtk::Label  *lab_ultrasonic_left1;
00229   Gtk::Label  *lab_ultrasonic_left2;
00230   Gtk::Label  *lab_ultrasonic_left3;
00231   Gtk::Label  *lab_ultrasonic_right0;
00232   Gtk::Label  *lab_ultrasonic_right1;
00233   Gtk::Label  *lab_ultrasonic_right2;
00234   Gtk::Label  *lab_ultrasonic_right3;
00235   Gtk::Label  *lab_battery_charge;
00236   Gtk::ToggleButton *but_us_auto;
00237   Gtk::Button       *but_us_emit;
00238   Gtk::ComboBox     *cmb_us_direction;
00239 
00240   Gtk::Button *but_sv_copy;
00241 
00242   Gtk::Button *but_stiffness_read;
00243   Gtk::Button *but_stiffness_write;
00244   Gtk::SpinButton *spb_stiffness_global;
00245   Gtk::CheckButton *chb_stiffness_global;
00246   Gtk::SpinButton *spb_HeadYaw;
00247   Gtk::SpinButton *spb_HeadPitch;
00248   Gtk::SpinButton *spb_RShoulderPitch;
00249   Gtk::SpinButton *spb_RShoulderRoll;
00250   Gtk::SpinButton *spb_RElbowYaw;
00251   Gtk::SpinButton *spb_RElbowRoll;
00252   Gtk::SpinButton *spb_RWristYaw;
00253   Gtk::SpinButton *spb_RHand;
00254   Gtk::SpinButton *spb_LShoulderPitch;
00255   Gtk::SpinButton *spb_LShoulderRoll;
00256   Gtk::SpinButton *spb_LElbowYaw;
00257   Gtk::SpinButton *spb_LElbowRoll;
00258   Gtk::SpinButton *spb_LWristYaw;
00259   Gtk::SpinButton *spb_LHand;
00260   Gtk::SpinButton *spb_RHipYawPitch;
00261   Gtk::SpinButton *spb_RHipPitch;
00262   Gtk::SpinButton *spb_RHipRoll;
00263   Gtk::SpinButton *spb_RKneePitch;
00264   Gtk::SpinButton *spb_RAnklePitch;
00265   Gtk::SpinButton *spb_RAnkleRoll;
00266   Gtk::SpinButton *spb_LHipYawPitch;
00267   Gtk::SpinButton *spb_LHipPitch;
00268   Gtk::SpinButton *spb_LHipRoll;
00269   Gtk::SpinButton *spb_LKneePitch;
00270   Gtk::SpinButton *spb_LAnklePitch;
00271   Gtk::SpinButton *spb_LAnkleRoll;
00272 
00273   Gtk::Label *lab_stiff_HeadYaw;
00274   Gtk::Label *lab_stiff_HeadPitch;
00275   Gtk::Label *lab_stiff_RShoulderPitch;
00276   Gtk::Label *lab_stiff_RShoulderRoll;
00277   Gtk::Label *lab_stiff_RElbowYaw;
00278   Gtk::Label *lab_stiff_RElbowRoll;
00279   Gtk::Label *lab_stiff_RWristYaw;
00280   Gtk::Label *lab_stiff_RHand;
00281   Gtk::Label *lab_stiff_LShoulderPitch;
00282   Gtk::Label *lab_stiff_LShoulderRoll;
00283   Gtk::Label *lab_stiff_LElbowYaw;
00284   Gtk::Label *lab_stiff_LElbowRoll;
00285   Gtk::Label *lab_stiff_LWristYaw;
00286   Gtk::Label *lab_stiff_LHand;
00287   Gtk::Label *lab_stiff_RHipYawPitch;
00288   Gtk::Label *lab_stiff_RHipPitch;
00289   Gtk::Label *lab_stiff_RHipRoll;
00290   Gtk::Label *lab_stiff_RKneePitch;
00291   Gtk::Label *lab_stiff_RAnklePitch;
00292   Gtk::Label *lab_stiff_RAnkleRoll;
00293   Gtk::Label *lab_stiff_LHipYawPitch;
00294   Gtk::Label *lab_stiff_LHipPitch;
00295   Gtk::Label *lab_stiff_LHipRoll;
00296   Gtk::Label *lab_stiff_LKneePitch;
00297   Gtk::Label *lab_stiff_LAnklePitch;
00298   Gtk::Label *lab_stiff_LAnkleRoll;
00299 
00300   Gtk::RadioButton *rad_motion_fawkes;
00301   Gtk::RadioButton *rad_motion_naoqi;
00302   Gtk::Button *but_stop;
00303   Gtk::Entry  *ent_ws_distance;
00304   Gtk::Button *but_ws_exec;
00305   Gtk::Entry  *ent_wsw_distance;
00306   Gtk::Button *but_wsw_exec;
00307   Gtk::Entry  *ent_wa_angle;
00308   Gtk::Entry  *ent_wa_radius;
00309   Gtk::Button *but_wa_exec;
00310   Gtk::Entry  *ent_turn_angle;
00311   Gtk::Button *but_turn_exec;
00312   Gtk::ComboBox *cmb_kick_leg;
00313   Gtk::Entry  *ent_kick_strength;
00314   Gtk::Button *but_kick_exec;
00315   Gtk::ComboBox *cmb_standup_from;
00316   Gtk::Button *but_standup_exec;
00317 
00318   Gtk::Entry  *ent_walkvel_x;
00319   Gtk::Entry  *ent_walkvel_y;
00320   Gtk::Entry  *ent_walkvel_theta;
00321   Gtk::Entry  *ent_walkvel_speed;
00322   Gtk::Button *but_walkvel_exec;
00323 
00324   Gtk::Entry  *ent_nav_x;
00325   Gtk::Entry  *ent_nav_y;
00326   Gtk::Entry  *ent_nav_ori;
00327   Gtk::Button *but_nav_exec;
00328 
00329   Gtk::Entry *ent_tts;
00330   Gtk::Button *but_tts_exec;
00331   Gtk::Label *lab_tts_active;
00332 
00333   Gtk::Scale *scl_chest_r;
00334   Gtk::Scale *scl_chest_g;
00335   Gtk::Scale *scl_chest_b;
00336   Gtk::Scale *scl_left_eye_r;
00337   Gtk::Scale *scl_left_eye_g;
00338   Gtk::Scale *scl_left_eye_b;
00339   Gtk::Scale *scl_right_eye_r;
00340   Gtk::Scale *scl_right_eye_g;
00341   Gtk::Scale *scl_right_eye_b;
00342   Gtk::Scale *scl_left_foot_r;
00343   Gtk::Scale *scl_left_foot_g;
00344   Gtk::Scale *scl_left_foot_b;
00345   Gtk::Scale *scl_right_foot_r;
00346   Gtk::Scale *scl_right_foot_g;
00347   Gtk::Scale *scl_right_foot_b;
00348 
00349   Gtk::ToggleButton *tb_left_ear_0;
00350   Gtk::ToggleButton *tb_left_ear_36;
00351   Gtk::ToggleButton *tb_left_ear_72;
00352   Gtk::ToggleButton *tb_left_ear_108;
00353   Gtk::ToggleButton *tb_left_ear_144;
00354   Gtk::ToggleButton *tb_left_ear_180;
00355   Gtk::ToggleButton *tb_left_ear_216;
00356   Gtk::ToggleButton *tb_left_ear_252;
00357   Gtk::ToggleButton *tb_left_ear_288;
00358   Gtk::ToggleButton *tb_left_ear_324;
00359 
00360   Gtk::ToggleButton *tb_right_ear_0;
00361   Gtk::ToggleButton *tb_right_ear_36;
00362   Gtk::ToggleButton *tb_right_ear_72;
00363   Gtk::ToggleButton *tb_right_ear_108;
00364   Gtk::ToggleButton *tb_right_ear_144;
00365   Gtk::ToggleButton *tb_right_ear_180;
00366   Gtk::ToggleButton *tb_right_ear_216;
00367   Gtk::ToggleButton *tb_right_ear_252;
00368   Gtk::ToggleButton *tb_right_ear_288;
00369   Gtk::ToggleButton *tb_right_ear_324;
00370 
00371   Gtk::ToggleButton *tb_control_leds;
00372 
00373   Gtk::Button *but_chestbut;
00374   Gtk::Button *but_head_front;
00375   Gtk::Button *but_head_middle;
00376   Gtk::Button *but_head_rear;
00377   Gtk::Button *but_lfoot_bumper;
00378   Gtk::Button *but_rfoot_bumper;
00379 
00380   /// @cond INTERNALS
00381   typedef struct {
00382     Gtk::Label  *lab_enabled;
00383     Gtk::Label  *lab_history;
00384     Gtk::Label  *lab_value;
00385     Gtk::Label  *lab_short;
00386     Gtk::Label  *lab_long;
00387     Gtk::Label  *lab_total;
00388   } ButtonLabelSet;
00389   /// @endcond
00390   std::map<std::string, ButtonLabelSet> button_labels;
00391   std::map<std::string, fawkes::SwitchInterface *> button_ifs;
00392 
00393   unsigned int update_cycle;
00394 };
00395 
00396 #endif