38 #ifndef WIIMOTE_WIIMOTE_CONTROLLER_H 39 #define WIIMOTE_WIIMOTE_CONTROLLER_H 42 #include "sensor_msgs/JoyFeedbackArray.h" 43 #include "std_srvs/Empty.h" 44 #include "sensor_msgs/Imu.h" 49 #include <bluetooth/bluetooth.h> 55 #define zeroedByCal(raw, zero, one) \ 56 (((raw - zero) * 1.0) / ((one - zero) * 1.0)) 63 char *getBluetoothAddr();
64 void setBluetoothAddr(
const char *bt_str);
65 bool pairWiimote(
int flags,
int timeout);
69 void checkConnection();
72 void setLedState(uint8_t led_state);
73 void setRumbleState(uint8_t rumble);
76 void setReportMode(uint8_t rpt_mode);
77 void checkFactoryCalibrationData();
78 void resetMotionPlusState();
79 void resetNunchukState();
80 void resetClassicState();
102 void joySetFeedbackCallback(
const sensor_msgs::JoyFeedbackArray::ConstPtr& feedback);
103 bool serviceImuCalibrateCallback(std_srvs::Empty::Request&, std_srvs::Empty::Response&);
105 bool isCollectingWiimote();
106 bool isCollectingNunchuk();
107 bool isCollectingClassic();
108 bool isCollectingMotionplus();
110 bool isPresentNunchuk();
111 bool isPresentClassic();
112 bool isPresentMotionplus();
114 bool calibrateJoystick(uint8_t stick[2], uint8_t (¢er)[2],
const char *name);
115 void updateJoystickMinMax(uint8_t stick[2], uint8_t (&stick_min)[2],
116 uint8_t (&stick_max)[2],
const char *name);
117 void calculateJoystickAxisXY(uint8_t stick_current[2], uint8_t stick_min[2],
118 uint8_t stick_max[2], uint8_t stick_center[2],
double (&stick)[2]);
121 void publishImuData();
122 void publishWiimoteState();
123 bool publishWiimoteNunchukCommon();
124 void publishWiimoteNunchuk();
125 void publishWiimoteClassic();
127 bool getStateSample();
129 void setLEDBit(uint8_t led,
bool on);
130 void setRumbleBit(
bool on);
150 struct wiimote_c::cwiid_state wiimote_state_;
151 void initializeWiimoteState();
160 struct wiimote_c::acc_cal wiimote_cal_;
165 const uint8_t JOYSTICK_NUNCHUK_DEFAULT_CENTER_ = 127;
166 const uint8_t JOYSTICK_NUNCHUK_20PERCENT_MAX_ = 205;
167 const uint8_t JOYSTICK_NUNCHUK_20PERCENT_MIN_ = 50;
168 const uint8_t JOYSTICK_CLASSIC_LEFT_DEFAULT_CENTER_ = 31;
169 const uint8_t JOYSTICK_CLASSIC_LEFT_20PERCENT_MAX_ = 50;
170 const uint8_t JOYSTICK_CLASSIC_LEFT_20PERCENT_MIN_ = 13;
171 const uint8_t JOYSTICK_CLASSIC_RIGHT_DEFAULT_CENTER_ = 15;
172 const uint8_t JOYSTICK_CLASSIC_RIGHT_20PERCENT_MAX_ = 25;
173 const uint8_t JOYSTICK_CLASSIC_RIGHT_20PERCENT_MIN_ = 6;
176 struct wiimote_c::acc_cal nunchuk_cal_;
179 uint8_t nunchuk_stick_center_[2];
181 uint8_t nunchuk_stick_max_[2];
182 uint8_t nunchuk_stick_min_[2];
185 uint8_t classic_stick_left_center_[2];
187 uint8_t classic_stick_left_max_[2];
188 uint8_t classic_stick_left_min_[2];
189 uint8_t classic_stick_right_center_[2];
191 uint8_t classic_stick_right_max_[2];
192 uint8_t classic_stick_right_min_[2];
194 const int IGNORE_DATA_POINTS_ = 100;
195 const int COVARIANCE_DATA_POINTS_ = 100;
201 uint8_t led_state_ = 0;
204 uint64_t wiimote_errors = 0;
207 const double EARTH_GRAVITY_ = 9.80665;
230 const double GYRO_SCALE_FACTOR_ = 0.001055997;
233 #endif // WIIMOTE_WIIMOTE_CONTROLLER_H ros::Time calibration_time_
ros::Subscriber joy_set_feedback_sub_
StatVector3d angular_velocity_stat_
ros::Publisher wiimote_state_pub_
bool classic_stick_right_calibrated_
static wiimote_c::cwiid_err_t cwiidErrorCallback
ros::Publisher imu_is_calibrated_pub_
boost::array< double, 9 > angular_velocity_covariance_
wiimote_c::cwiid_wiimote_t * wiimote_
ros::Publisher wiimote_nunchuk_pub_
bool classic_stick_left_calibrated_
bool nunchuk_stick_calibrated_
StatVector3d linear_acceleration_stat_
boost::array< double, 9 > linear_acceleration_covariance_
bool nunchuk_failed_calibration_
ros::ServiceServer imu_calibrate_srv_
ros::Publisher wiimote_classic_pub_
ros::Publisher imu_data_pub_