main.cpp
Go to the documentation of this file.
00001 #include "ros/ros.h"
00002 #include "geometry_msgs/PointStamped.h"
00003 #include "quad_can_driver/Attitude.h"
00004 
00005 #define PI 3.14159256
00006 
00007 // limit 10 degrees
00008 #define angle_MAX 0.1745
00009 #define angle_MIN -0.1745
00010 
00011 
00012 quad_can_driver::Attitude att_msg;
00013 ros::Publisher att_pub;
00014 double K;
00015 std::string _pixels_topic_subscribe;
00016 
00017 typedef struct{
00018     double roll;
00019     double pitch;
00020 }direction_vector;
00021 
00022 direction_vector roll_pitch;
00023 
00024 
00025 void Callback_pixels_disp(const geometry_msgs::PointStamped pixel_disp){
00026 
00027     double x_des = pixel_disp.point.x;
00028     double y_des = pixel_disp.point.y;
00029 
00030 
00031 
00032 
00033     roll_pitch.roll = -K * x_des;
00034     roll_pitch.pitch = K * y_des;
00035 
00036 }
00037 
00038 
00039 int main(int argc, char **argv){
00040 
00041     roll_pitch.roll = roll_pitch.pitch = 0.0;
00042 
00043     ros::init(argc, argv, "quad_position_pixels");
00044     ros::NodeHandle nh("~");
00045 
00046     ros::Rate rate(50);
00047 
00048     nh.param<double>("K", K, 0.01);
00049     nh.param<std::string>("pixels_topic_subscribe", _pixels_topic_subscribe, "/pixel_disp");
00050 
00051     ros::Subscriber sub = nh.subscribe(_pixels_topic_subscribe,5,Callback_pixels_disp);
00052 
00053     //Publishing
00054     att_pub = nh.advertise<quad_can_driver::Attitude>("/AttitudeCtrl", 5);
00055 
00056     while(ros::ok()){
00057 
00058         if(roll_pitch.roll > angle_MAX)
00059             roll_pitch.roll=angle_MAX;
00060 
00061         if(roll_pitch.roll < angle_MIN)
00062             roll_pitch.roll=angle_MIN;
00063 
00064         if(roll_pitch.pitch > angle_MAX)
00065             roll_pitch.pitch=angle_MAX;
00066 
00067         if(roll_pitch.pitch < angle_MIN)
00068             roll_pitch.pitch=angle_MIN;
00069 
00070 
00071 
00072         // reduce the value incrementally
00073         roll_pitch.roll *= 0.8;
00074         roll_pitch.pitch *= 0.8;
00075 
00076 
00077         att_msg.roll=roll_pitch.roll;
00078         att_msg.pitch=roll_pitch.pitch;
00079 
00080         att_pub.publish( att_msg );
00081         ROS_INFO("roll: %lf , pitch: %lf",att_msg.roll,att_msg.pitch);
00082 
00083         ros::spinOnce();
00084         rate.sleep();
00085     }
00086 
00087 
00088     return 0;
00089 
00090 }


quad_position_pixels
Author(s): tcarreira
autogenerated on Mon Jan 6 2014 11:48:34