Go to the documentation of this file.00001 #include<ros/ros.h>
00002 #include<std_msgs/Float64.h>
00003 #include<dynamixel_msgs/JointState.h>
00004 #include<cmath>
00005 #include<laser_assembler/AssembleScans.h>
00006 #include<ros/time.h>
00007 #include<std_msgs/Time.h>
00008 #include<std_msgs/Empty.h>
00009
00010
00011
00012
00013
00014 using namespace std;
00015
00016
00017 float error;
00018 int max_angle;
00019 int min_angle;
00020 float pause_time;
00021
00022
00023 void obtainValues(const dynamixel_msgs::JointState &msg) {
00024 error = msg.error;
00025 }
00026
00027
00028 class Dynamixel {
00029 private:
00030 ros::NodeHandle nh;
00031 ros::Publisher pub_1;
00032 ros::Publisher pub_2;
00033 ros::Publisher pub_3;
00034 ros::Subscriber sub;
00035
00036 public:
00037 Dynamixel();
00038 void checkError();
00039 void moveMotor(double position);
00040 void startTime();
00041 void endTime();
00042 };
00043
00044
00045 Dynamixel::Dynamixel() {
00046
00047 pub_1 = nh.advertise<std_msgs::Float64>("/tilt_controller/command", 10);
00048
00049 pub_2 = nh.advertise<std_msgs::Time>("/time/start_time", 1);
00050
00051 pub_3 = nh.advertise<std_msgs::Time>("/time/end_time", 1);
00052
00053 sub = nh.subscribe("/tilt_controller/state", 1, &obtainValues);
00054 }
00055
00056
00057 void Dynamixel::moveMotor(double position) {
00058 double convert = (position * 3.14/180);
00059 std_msgs::Float64 aux;
00060 aux.data = convert;
00061 pub_1.publish(aux);
00062 ROS_INFO_STREAM(aux);
00063 }
00064
00065
00066 void Dynamixel::checkError() {
00067 ros::spinOnce();
00068
00069 while((abs (error))>0.05) {
00070 ros::Duration(.1).sleep();
00071 ros::spinOnce();
00072 }
00073 }
00074
00075
00076 void Dynamixel::startTime() {
00077 std_msgs::Time msg;
00078 msg.data = ros::Time::now();
00079 pub_2.publish(msg);
00080 }
00081
00082
00083 void Dynamixel::endTime() {
00084 std_msgs::Time msg;
00085 msg.data = ros::Time::now();
00086 pub_3.publish(msg);
00087 }
00088
00089
00090 void initialize() {
00091 Dynamixel motor_1;
00092
00093 motor_1.moveMotor(min_angle);
00094 ros::Duration(pause_time).sleep();
00095 motor_1.checkError();
00096 ros::Duration(pause_time).sleep();
00097 }
00098
00099
00100 void sweep(const std_msgs::Empty &msg) {
00101 Dynamixel motor;
00102
00103 motor.startTime();
00104 motor.moveMotor(max_angle);
00105 ros::Duration(pause_time).sleep();
00106 motor.checkError();
00107 ros::Duration(pause_time).sleep();
00108
00109 motor.moveMotor(min_angle);
00110 ros::Duration(pause_time).sleep();
00111 motor.checkError();
00112 motor.endTime();
00113 ros::Duration(pause_time).sleep();
00114 ROS_INFO("Finished One Sweep!");
00115 }
00116
00117
00118 int main(int argc, char **argv) {
00119
00120
00121 ros::init(argc, argv, "Motor_Tilt");
00122 ros::NodeHandle nh;
00123
00124
00125 int max;
00126 int min;
00127 double pause;
00128 Dynamixel motor;
00129
00130
00131 nh.param("maximum", max, 92);
00132 nh.param("minimum", min, -92);
00133 nh.param("pause", pause, 0.1);
00134
00135
00136 max_angle = max;
00137 min_angle = min;
00138 pause_time = pause;
00139
00140
00141 ros::topic::waitForMessage<dynamixel_msgs::JointState>("/tilt_controller/state", ros::Duration(100));
00142
00143
00144 ros::Subscriber sub=nh.subscribe("/perform_sweep", 1, &sweep);
00145
00146
00147 ros::Duration(1).sleep();
00148 initialize();
00149
00150
00151 ros::spin();
00152 }