LaserHeightEstimation::LaserHeightEstimation(ros::NodeHandle nh, ros::NodeHandle nh_private): nh_(nh), nh_private_(nh_private), first_time_(true) { ROS_INFO("Starting LaserHeightEstimation"); initialized_ = false; floor_height_ = 0.0; prev_height_ = 0.0; world_to_base_.setIdentity(); ros::NodeHandle nh_mav (nh_, "mav"); // **** parameters if (!nh_private_.getParam ("fixed_frame", world_frame_)) world_frame_ = "/world"; if (!nh_private_.getParam ("base_frame", base_frame_)) base_frame_ = "base_link"; if (!nh_private_.getParam ("footprint_frame", footprint_frame_)) footprint_frame_ = "base_footprint"; if (!nh_private_.getParam ("min_values", min_values_)) min_values_ = 5; if (!nh_private_.getParam ("max_stdev", max_stdev_)) max_stdev_ = 0.10; if (!nh_private_.getParam ("max_height_jump", max_height_jump_)) max_height_jump_ = 0.25; if (!nh_private_.getParam ("use_imu", use_imu_)) use_imu_ = true; if (!nh_private_.getParam ("use_segmentation", use_segmentation_)) use_segmentation_ = true; if (!nh_private_.getParam ("bin_size", bin_size_)) bin_size_ = 0.02; // **** publishers height_to_base_publisher_ = nh_mav.advertise<mav_msgs::Height>( "height_to_base", 5); height_to_footprint_publisher_ = nh_mav.advertise<mav_msgs::Height>( "height_to_footprint", 5); floor_publisher_ = nh_mav.advertise<mav_msgs::Height>( "floor_height", 5); // **** subscribers scan_subscriber_ = nh_.subscribe( "scan", 5, &LaserHeightEstimation::scanCallback, this); if (use_imu_) { imu_subscriber_ = nh_.subscribe( "imu", 5, &LaserHeightEstimation::imuCallback, this); } }
LaserHeightEstimation::LaserHeightEstimation(ros::NodeHandle nh, ros::NodeHandle nh_private): nh_(nh), nh_private_(nh_private), first_time_(true) { ROS_INFO("Starting LaserHeight"); initialized_ = false; prev_height_ = 0.0; world_to_base_.setIdentity(); ros::NodeHandle nh_mav (nh_, "quad_height"); // Parameters nh_private_.param<std::string>("global_frame", world_frame_, "map"); nh_private_.param<std::string>("stabilized_frame", stabilized_frame_, "base_stabilized"); nh_private_.param<std::string>("base_frame", base_frame_, "base_link"); nh_private_.param<std::string>("imu_topic", imu_topic_, "/imu/data"); nh_private_.param<std::string>("scan_topic", scan_topic_, "scan"); nh_private_.param("min_values", min_values_, 5); nh_private_.param("max_stdev", max_stdev_, 0.1); nh_private_.param("max_height_jump", max_height_jump_, 0.25); nh_private_.param("bin_size", bin_size_, 0.2); nh_private_.param<bool>("use_imu", use_imu_, true); nh_private_.param<bool>("use_segmentation", use_segmentation_, true); // Publishers height_to_base_publisher_ = nh_mav.advertise<mav_msgs::Height>("height_to_base", 5); height_to_footprint_publisher_ = nh_mav.advertise<mav_msgs::Height>("height_to_footprint", 5); // Subscribers scan_subscriber_ = nh_.subscribe(scan_topic_, 5, &LaserHeightEstimation::scanCallback, this); if (use_imu_){ imu_subscriber_ = nh_.subscribe(imu_topic_, 5, &LaserHeightEstimation::imuCallback, this); } }
FlyerInterface::FlyerInterface(ros::NodeHandle nh, ros::NodeHandle nh_private): nh_(nh), nh_private_(nh_private), cfg_ctrl_srv_(ros::NodeHandle(nh_private_, "ctrl")), cfg_x_srv_(ros::NodeHandle(nh_private_, "ctrl/pid_x")), cfg_y_srv_(ros::NodeHandle(nh_private_, "ctrl/pid_y")), cfg_z_srv_(ros::NodeHandle(nh_private_, "ctrl/pid_z")), cfg_vx_srv_(ros::NodeHandle(nh_private_, "ctrl/pid_vx")), cfg_vy_srv_(ros::NodeHandle(nh_private_, "ctrl/pid_vy")), cfg_vz_srv_(ros::NodeHandle(nh_private_, "ctrl/pid_vz")), cfg_yaw_srv_(ros::NodeHandle(nh_private_, "ctrl/pid_yaw")), cfg_comm_srv_(ros::NodeHandle(nh_private_, "comm")), connected_(false) { ROS_INFO("Starting FlyerInterface"); ros::NodeHandle nh_mav (nh_, "mav"); // **** initialize vaiables cmd_roll_ = 0.0; cmd_pitch_ = 0.0; cmd_yaw_rate_ = 0.0; cmd_thrust_ = 0.0; cpu_load_index_ = 0; cpu_loads_.resize(50); // **** get parameters initializeParams(); // **** dynamic reconfigure services CfgZServer::CallbackType f1 = boost::bind(&FlyerInterface::reconfig_z_callback, this, _1, _2); cfg_z_srv_.setCallback(f1); CfgXServer::CallbackType f2 = boost::bind(&FlyerInterface::reconfig_x_callback, this, _1, _2); cfg_x_srv_.setCallback(f2); CfgYServer::CallbackType f3 = boost::bind(&FlyerInterface::reconfig_y_callback, this, _1, _2); cfg_y_srv_.setCallback(f3); CfgYawServer::CallbackType f4 = boost::bind(&FlyerInterface::reconfig_yaw_callback, this, _1, _2); cfg_yaw_srv_.setCallback(f4); CfgCommServer::CallbackType f5 = boost::bind(&FlyerInterface::reconfig_comm_callback, this, _1, _2); cfg_comm_srv_.setCallback(f5); CfgCtrlServer::CallbackType f6 = boost::bind(&FlyerInterface::reconfig_ctrl_callback, this, _1, _2); cfg_ctrl_srv_.setCallback(f6); CfgVXServer::CallbackType f7 = boost::bind(&FlyerInterface::reconfig_vx_callback, this, _1, _2); cfg_vx_srv_.setCallback(f7); CfgVYServer::CallbackType f8 = boost::bind(&FlyerInterface::reconfig_vy_callback, this, _1, _2); cfg_vy_srv_.setCallback(f8); CfgVZServer::CallbackType f9 = boost::bind(&FlyerInterface::reconfig_vz_callback, this, _1, _2); cfg_vz_srv_.setCallback(f9); // **** connect connected_ = comm_.connect(serial_port_rx_, serial_port_tx_, baudrate_); if (!connected_) { ROS_ERROR("unable to connect"); return; } // **** configure sendCommConfig(); sendKFConfig(true); // configure and reset to 0 state sendPIDConfig(); sendCtrlConfig(); // *** register publishers if (publish_pose_) { pose_publisher_ = nh_mav.advertise<geometry_msgs::PoseStamped>( "pose", 10); } vel_publisher_ = nh_mav.advertise<geometry_msgs::TwistStamped>( "vel", 10); imu_publisher_ = nh_mav.advertise<sensor_msgs::Imu>( "imu", 10); flight_state_publisher_ = nh_mav.advertise<std_msgs::UInt8>( "status/flight_state", 1); battery_voltage_publisher_ = nh_mav.advertise<std_msgs::Float32>( "status/battery_voltage", 1); cpu_load_publisher_ = nh_mav.advertise<std_msgs::Float32>( "status/cpu_load", 1); cpu_load_avg_publisher_ = nh_mav.advertise<std_msgs::Float32>( "status/cpu_load_avg", 1); if (publish_debug_) { debug_cmd_roll_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/cmd/roll", 1); debug_cmd_pitch_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/cmd/pitch", 1); debug_cmd_yaw_rate_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/cmd/yaw_rate", 1); debug_cmd_thrust_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/cmd/thrust", 1); debug_cmd_yaw_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/cmd/yaw", 1); debug_pid_x_i_term_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/pid/x_i_term", 1); debug_pid_y_i_term_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/pid/y_i_term", 1); debug_pid_yaw_i_term_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/pid/yaw_i_term", 1); debug_pid_z_i_term_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/pid/z_i_term", 1); debug_roll_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/roll", 1); debug_pitch_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/pitch", 1); debug_yaw_publisher_ = nh_mav.advertise<std_msgs::Float32>( "debug/yaw", 1); debug_err_x_bf_publisher_= nh_mav.advertise<std_msgs::Float32>( "debug/pid/err_x_bf", 1); debug_err_y_bf_publisher_= nh_mav.advertise<std_msgs::Float32>( "debug/pid/err_y_bf", 1); debug_err_vx_bf_publisher_= nh_mav.advertise<std_msgs::Float32>( "debug/pid/err_vx_bf", 1); debug_err_vy_bf_publisher_= nh_mav.advertise<std_msgs::Float32>( "debug/pid/err_vy_bf", 1); debug_ax_bf_publisher_= nh_mav.advertise<std_msgs::Float32>( "debug/pid/acc_x_bf", 1); debug_ay_bf_publisher_= nh_mav.advertise<std_msgs::Float32>( "debug/pid/acc_y_bf", 1); debug_az_publisher_= nh_mav.advertise<std_msgs::Float32>( "debug/pid/dvz", 1); debug_vx_bf_publisher_= nh_mav.advertise<std_msgs::Float32>( "debug/pid/vx_bf", 1); debug_vy_bf_publisher_= nh_mav.advertise<std_msgs::Float32>( "debug/pid/vy_bf", 1); debug_imu_wf_publisher_ = nh_mav.advertise<sensor_msgs::Imu>( "debug/imu_wf", 1); } // **** register callbacks for packets from serial port comm_.registerCallback(MAV_IMU_PKT_ID, &FlyerInterface::processImuData, this); comm_.registerCallback(MAV_POSE_PKT_ID, &FlyerInterface::processPoseData, this); comm_.registerCallback(MAV_RCDATA_PKT_ID, &FlyerInterface::processRCData, this); comm_.registerCallback(MAV_FLIGHT_STATE_PKT_ID, &FlyerInterface::processFlightStateData, this); comm_.registerCallback(MAV_TIMESYNC_PKT_ID, &FlyerInterface::processTimeSyncData, this); comm_.registerCallback(MAV_STATUS_PKT_ID, &FlyerInterface::processStatusData, this); if (publish_debug_) comm_.registerCallback(MAV_CTRL_DEBUG_PKT_ID, &FlyerInterface::processCtrlDebugData, this); // **** register subscribers // Synchronize inputs. Topic subscriptions happen on demand in the connection callback. int queue_size = 5; laser_pose_subscriber_.reset(new PoseStampedSubscriber( nh_mav, "laser_pose_f", queue_size)); laser_vel_subscriber_.reset(new TwistStampedSubscriber( nh_mav, "laser_vel_f", queue_size)); sync_.reset(new Synchronizer( SyncPolicy(queue_size), *laser_pose_subscriber_, *laser_vel_subscriber_)); sync_->registerCallback(boost::bind(&FlyerInterface::laserCallback, this, _1, _2)); height_subscriber_ = nh_mav.subscribe( "laser_height_f", 10, &FlyerInterface::heightCallback, this); cmd_roll_subscriber_ = nh_mav.subscribe( "cmd/roll", 10, &FlyerInterface::cmdRollCallback, this); cmd_pitch_subscriber_ = nh_mav.subscribe( "cmd/pitch", 10, &FlyerInterface::cmdPitchCallback, this); cmd_yaw_rate_subscriber_ = nh_mav.subscribe( "cmd/yaw_rate", 10, &FlyerInterface::cmdYawRateCallback, this); cmd_thrust_subscriber_ = nh_mav.subscribe( "cmd/thrust", 10, &FlyerInterface::cmdThrustCallback, this); cmd_pose_subscriber_ = nh_mav.subscribe( "cmd/pose", 10, &FlyerInterface::cmdPoseCallback, this); cmd_vel_subscriber_ = nh_mav.subscribe( "cmd/vel", 10, &FlyerInterface::cmdVelCallback, this); // **** timers cmd_timer_ = nh_private_.createTimer( ros::Duration(0.05), &FlyerInterface::cmdTimerCallback, this); // **** services advance_state_srv_ = nh_mav.advertiseService( "advanceState", &FlyerInterface::advanceState, this); retreat_state_srv_ = nh_mav.advertiseService( "retreatState", &FlyerInterface::retreatState, this); estop_srv_ = nh_mav.advertiseService( "estop", &FlyerInterface::estop, this); toggle_engage_srv_ = nh_mav.advertiseService( "toggleEngage", &FlyerInterface::toggleEngage, this); takeoff_srv_ = nh_mav.advertiseService( "takeoff", &FlyerInterface::takeoff, this); land_srv_ = nh_mav.advertiseService( "land", &FlyerInterface::land, this); get_flight_state_srv_ = nh_mav.advertiseService( "getFlightState", &FlyerInterface::getFlightState, this); set_ctrl_type_srv_ = nh_mav.advertiseService( "setCtrlType", &FlyerInterface::setCtrlType, this); }
CtrlInterface::CtrlInterface(ros::NodeHandle nh, ros::NodeHandle nh_private): nh_(nh), nh_private_(nh_private), tf_listener_(ros::Duration(10.0)) { ROS_INFO("Starting CtrlInterface"); ros::NodeHandle nh_mav (nh_, "mav"); // **** get parameters initializeParams(); // **** initialize vaiables ctrl_type_ = mav::PositionCtrl; des_vel_.linear.x = 0.0; des_vel_.linear.y = 0.0; des_vel_.linear.z = 0.0; des_vel_.angular.x = 0.0; des_vel_.angular.y = 0.0; des_vel_.angular.z = 0.0; tf::Pose identity; identity.setIdentity(); tf::poseTFToMsg(identity, cur_pose_.pose); cur_pose_.header.frame_id = fixed_frame_; cur_goal_ = des_pose_ = cur_pose_; ////////navfn_.initialize("my_navfn_planner", &costmap_); // *** register publishers cmd_pose_publisher_ = nh_mav.advertise<geometry_msgs::PoseStamped>( "cmd/pose", 10); cmd_vel_publisher_ = nh_mav.advertise<geometry_msgs::TwistStamped>( "cmd/vel", 10); goal_publisher_= nh_mav.advertise<geometry_msgs::PoseStamped>( "cmd/goal", 10); /*plan_publisher_ = nh_mav.advertise<nav_msgs::Path>( "plan", 10); array_publisher_ = nh_mav.advertise<geometry_msgs::PoseArray>( "plan_array", 10);*/ printf("ASDFF!\n"); // **** register subscribers cur_pose_subscriber_ = nh_mav.subscribe( "pose", 10, &CtrlInterface::curPoseCallback, this); goal2D_subscriber_ = nh_mav.subscribe( "goal2D_rviz", 10, &CtrlInterface::goal2Dcallback, this); cmd_joy_vel_subscriber_ = nh_mav.subscribe( "cmd_joy/vel", 10, &CtrlInterface::cmdJoyVelCallback, this); /*cmd_plan_vel_subscriber_ = nh_mav.subscribe( "cmd_plan/vel", 10, &CtrlInterface::cmdPlanVelCallback, this);*/ // **** register service servers change_des_pose_srv_ = nh_mav.advertiseService( "changeDesPose", &CtrlInterface::changeDesPose, this); pos_hold_srv_ = nh_mav.advertiseService( "positionHold", &CtrlInterface::positionHold, this); vel_hold_srv_ = nh_mav.advertiseService( "velocityHold", &CtrlInterface::velocityHold, this); set_ctrl_type_client_ = nh_mav.serviceClient<mav_srvs::SetCtrlType>( "setCtrlType"); // **** timers cmd_timer_ = nh_private_.createTimer( ros::Duration(0.100), &CtrlInterface::cmdTimerCallback, this); /*plan_timer_ = nh_private_.createTimer( ros::Duration(0.100), &CtrlInterface::planTimerCallback, this);*/ }