Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00027
00028
00029
00030 #include <ros/ros.h>
00031
00032
00033 #include <sensor_msgs/JointState.h>
00034 #include <std_msgs/Float32.h>
00035 #include <std_msgs/Empty.h>
00036 #include <std_msgs/Int8.h>
00037
00038 #include <icl_core/EnumHelper.h>
00039
00040 #include <stdlib.h>
00041 #include <time.h>
00042
00043
00044
00045
00046 double loop_rate = 50;
00047
00048
00049 double sin_duration = 10;
00050
00051
00052
00053 bool running = true;
00054
00055
00056
00057
00058 void runCallback(const std_msgs::Empty&)
00059 {
00060 running = !running;
00061 }
00062
00063 void speedCallback(const std_msgs::Float32ConstPtr &msg){
00064 sin_duration = msg->data;
00065 }
00066 void loopCallback(const std_msgs::Float32ConstPtr &msg){
00067 loop_rate = msg->data;
00068 }
00069
00070
00071
00072
00073
00074
00075 int main(int argc, char** argv)
00076 {
00079 std::string name_prefix;
00080
00081
00082 ros::init(argc, argv, "svh_sine_test");
00083 ros::NodeHandle nh("~");
00084
00085 try
00086 {
00087 nh.param<std::string>("name_prefix", name_prefix, "left_hand");
00088 }
00089 catch (ros::InvalidNameException e)
00090 {
00091 ROS_ERROR("Parameter Error!");
00092 }
00093
00094
00095 ros::Subscriber run_sub = nh.subscribe("toggle_run", 1, runCallback);
00096 ros::Subscriber speed_sub = nh.subscribe("speed", 1, speedCallback);
00097 ros::Subscriber loop_sub = nh.subscribe("loop", 1, loopCallback);
00098
00099
00100 ros::Publisher channel_pos_pub = nh.advertise<sensor_msgs::JointState>("channel_targets", 1);
00101
00102
00103 sensor_msgs::JointState channel_pos;
00104 channel_pos.name.resize(9);
00105 channel_pos.position.resize(9, 0.0);
00106
00107
00108 channel_pos.name[0] = name_prefix + "_" + "Thumb_Flexion";
00109 channel_pos.name[1] = name_prefix + "_" + "Thumb_Opposition";
00110 channel_pos.name[2] = name_prefix + "_" + "Index_Finger_Distal";
00111 channel_pos.name[3] = name_prefix + "_" + "Index_Finger_Proximal";
00112 channel_pos.name[4] = name_prefix + "_" + "Middle_Finger_Distal";
00113 channel_pos.name[5] = name_prefix + "_" + "Middle_Finger_Proximal";
00114 channel_pos.name[6] = name_prefix + "_" + "Ring_Finger";
00115 channel_pos.name[7] = name_prefix + "_" + "Pinky";
00116 channel_pos.name[8] = name_prefix + "_" + "Finger_Spread";
00117
00118
00119 ros::Time counter = ros::Time::now();
00120 double normalized_time = 0;
00121
00122
00123 srand(time(NULL));
00124
00125
00126
00127
00128 while (nh.ok())
00129 {
00130
00131 if (running)
00132 {
00133
00134 if ((ros::Time::now() - counter) > ros::Duration(sin_duration))
00135 {
00136 counter = ros::Time::now();
00137 normalized_time = 0;
00138 }
00139 else
00140 {
00141 normalized_time = (ros::Time::now() - counter).toSec() / sin_duration;
00142 }
00143
00144
00145
00146 for (size_t channel = 0; channel < 9; ++channel)
00147 {
00148 double cur_pos = 0.0;
00149
00150 channel_pos.position[channel] = cur_pos;
00151 }
00152
00153 channel_pos.header.stamp = ros::Time::now();
00154
00155
00156
00157 double cur_pos = 0.4 + 0.3 * sin(normalized_time * 2 * 3.14);
00158
00159
00160 channel_pos.position[8] = 0.3;
00161
00162 channel_pos.position[0] = 1 - cur_pos;
00163
00164
00165 channel_pos.position[7] = cur_pos;
00166 channel_pos.position[2] = cur_pos;
00167 channel_pos.position[3] = cur_pos;
00168 channel_pos.position[4] = cur_pos;
00169 channel_pos.position[5] = cur_pos;
00170 channel_pos.position[6] = cur_pos;
00171
00172
00173 channel_pos_pub.publish(channel_pos);
00174 }
00175
00176 ros::Rate rate(loop_rate);
00177 rate.sleep();
00178 ros::spinOnce();
00179
00180
00181
00182
00183
00184 }
00185
00186 return 0;
00187 }