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()
00101 {
00102 Dynamixel motor;
00103
00104 motor.startTime();
00105 motor.moveMotor(max_angle);
00106 ros::Duration(pause_time).sleep();
00107 motor.checkError();
00108 ros::Duration(pause_time).sleep();
00109
00110 motor.moveMotor(min_angle);
00111 ros::Duration(pause_time).sleep();
00112 motor.checkError();
00113 motor.endTime();
00114 ros::Duration(pause_time).sleep();
00115 ROS_INFO("Finished One Sweep!");
00116 }
00117
00118
00119 int main(int argc, char **argv) {
00120
00121
00122 ros::init(argc, argv, "Motor_Tilt");
00123 ros::NodeHandle nh;
00124
00125
00126 int max;
00127 int min;
00128 double pause;
00129 Dynamixel motor;
00130
00131
00132 nh.param("maximum", max, 92);
00133 nh.param("minimum", min, -92);
00134 nh.param("pause", pause, 0.1);
00135
00136
00137 max_angle = max;
00138 min_angle = min;
00139 pause_time = pause;
00140
00141
00142 ros::topic::waitForMessage<dynamixel_msgs::JointState>("/tilt_controller/state", ros::Duration(100));
00143
00144
00145 ros::Duration(1).sleep();
00146 initialize();
00147
00148
00149 while(ros::ok()) {
00150 sweep();
00151 }
00152 }