27 : control_cycle_msec_(8),
45 result_[
"present_voltage"] = 0.0;
99 std::map<std::string, robotis_framework::Sensor *> sensors)
101 if (sensors[
"open-cr"] == NULL)
104 int16_t gyro_x = sensors[
"open-cr"]->sensor_state_->bulk_read_table_[
"gyro_x"];
105 int16_t gyro_y = sensors[
"open-cr"]->sensor_state_->bulk_read_table_[
"gyro_y"];
106 int16_t gyro_z = sensors[
"open-cr"]->sensor_state_->bulk_read_table_[
"gyro_z"];
108 int16_t acc_x = sensors[
"open-cr"]->sensor_state_->bulk_read_table_[
"acc_x"];
109 int16_t acc_y = sensors[
"open-cr"]->sensor_state_->bulk_read_table_[
"acc_y"];
110 int16_t acc_z = sensors[
"open-cr"]->sensor_state_->bulk_read_table_[
"acc_z"];
112 uint16_t present_volt = sensors[
"open-cr"]->sensor_state_->bulk_read_table_[
"present_voltage"];
132 update_time.
sec = sensors[
"open-cr"]->sensor_state_->update_time_stamp_.sec_;
133 update_time.
nsec = sensors[
"open-cr"]->sensor_state_->update_time_stamp_.nsec_;
135 if ((update_duration.
sec * 1000000000 + update_duration.
nsec) > 100000000)
138 uint8_t button_flag = sensors[
"open-cr"]->sensor_state_->bulk_read_table_[
"button"];
139 result_[
"button_mode"] = button_flag & 0x01;
140 result_[
"button_start"] = (button_flag & 0x02) >> 1;
141 result_[
"button_user"] = (button_flag & 0x04) >> 2;
147 result_[
"present_voltage"] = present_volt * 0.1;
173 imu_msg_.header.frame_id =
"body_link";
174 double filter_alpha = 0.4;
178 int _arrd_length = 2;
192 double roll = atan2(
result_[
"acc_y"],
194 double pitch = atan2(-result_[
"acc_x"],
195 sqrt(result_[
"acc_y"] * result_[
"acc_y"] + result_[
"acc_z"] * result_[
"acc_z"]));
200 imu_msg_.orientation.x = orientation.x();
201 imu_msg_.orientation.y = orientation.y();
202 imu_msg_.orientation.z = orientation.z();
203 imu_msg_.orientation.w = orientation.w();
210 std::string button_key =
"button_" + button_name;
211 std::string button_published =
"published_" + button_name;
213 bool pushed = (
result_[button_key] == 1.0);
217 if (pushed ==
true &&
buttons_[button_published] ==
false)
221 if (button_duration.
toSec() > 2.0)
241 if (button_duration.
toSec() < 2.0)
252 std_msgs::String button_msg;
253 button_msg.data = button_name;
256 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_INFO,
"Button : " + button_name);
261 double voltage_ratio = 0.4;
273 last_msg_time_ = now;
276 std::stringstream log_stream;
279 (present_volt_ < 11 ?
280 robotis_controller_msgs::StatusMsg::STATUS_WARN : robotis_controller_msgs::StatusMsg::STATUS_INFO),
288 robotis_controller_msgs::StatusMsg status_msg;
290 status_msg.type = type;
291 status_msg.module_name =
"SENSOR";
292 status_msg.status_msg = msg;
299 robotis_controller_msgs::SyncWriteItem sync_write_msg;
300 sync_write_msg.item_name =
"dynamixel_power";
301 sync_write_msg.joint_name.push_back(
"open-cr");
302 sync_write_msg.value.push_back(value);
309 double filtered_value = alpha * x_new + (1.0 - alpha) * x_old;
310 x_old = filtered_value;
312 return filtered_value;
void process(std::map< std::string, robotis_framework::Dynamixel * > dxls, std::map< std::string, robotis_framework::Sensor * > sensors)
ros::Publisher button_pub_
void publish(const boost::shared_ptr< M > &message) const
std::map< std::string, ros::Time > buttons_press_time_
ros::Publisher dxl_power_msg_pub_
Eigen::Quaterniond convertRPYToQuaternion(double roll, double pitch, double yaw)
void handleVoltage(double present_volt)
double lowPassFilter(double alpha, double x_new, double &x_old)
void publishStatusMsg(unsigned int type, std::string msg)
double getAccValue(int raw_value)
const double ACCEL_FACTOR
std::map< std::string, double > result_
boost::thread queue_thread_
ros::Publisher status_msg_pub_
void publishButtonMsg(const std::string &button_name)
void setCallbackQueue(CallbackQueueInterface *queue)
sensor_msgs::Imu imu_msg_
std::map< std::string, double > previous_result_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_INFO_COND(cond,...)
void publishDXLPowerMsg(unsigned int value)
void handleButton(const std::string &button_name)
double getGyroValue(int raw_value)
void initialize(const int control_cycle_msec, robotis_framework::Robot *robot)
std::map< std::string, bool > buttons_