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 <std_msgs/Int8.h>
00034 #include <std_msgs/Empty.h>
00035 #include <sensor_msgs/JointState.h>
00036
00037 #include <icl_core/EnumHelper.h>
00038
00039 #include <stdlib.h>
00040 #include <time.h>
00041
00042
00043
00044
00045 const double loop_rate = 50;
00046
00047 const double sin_duration = 10;
00048
00049
00050
00051 bool running = true;
00052
00053
00054
00055
00056 void runCallback(const std_msgs::Empty&)
00057 {
00058 running = !running;
00059 }
00060
00061
00062
00063
00064
00065 int main(int argc, char **argv)
00066 {
00067
00068 ros::init(argc, argv, "svh_sine_test");
00069 ros::NodeHandle nh("~");
00070
00071
00072 ros::Subscriber run_sub = nh.subscribe("toggle_run", 1, runCallback);
00073
00074
00075 ros::Publisher channel_pos_pub = nh.advertise<sensor_msgs::JointState>("channel_targets", 1);
00076
00077
00078 sensor_msgs::JointState channel_pos;
00079 channel_pos.name.resize(9);
00080 channel_pos.position.resize(9, 0.0);
00081
00082
00083 channel_pos.name[0] = "Thumb_Flexion";
00084 channel_pos.name[1] = "Thumb_Opposition";
00085 channel_pos.name[2] = "Index_Finger_Distal";
00086 channel_pos.name[3] = "Index_Finger_Proximal";
00087 channel_pos.name[4] = "Middle_Finger_Distal";
00088 channel_pos.name[5] = "Middle_Finger_Proximal";
00089 channel_pos.name[6] = "Ring_Finger";
00090 channel_pos.name[7] = "Pinky";
00091 channel_pos.name[8] = "Finger_Spread";
00092
00093
00094 ros::Time counter = ros::Time::now();
00095 double normalized_time = 0;
00096
00097
00098 srand (time(NULL));
00099
00100
00101 ros::Rate rate(50);
00102
00103
00104 while (nh.ok())
00105 {
00106
00107 if (running)
00108 {
00109
00110 if ((ros::Time::now() - counter) > ros::Duration(sin_duration))
00111 {
00112 counter = ros::Time::now();
00113 }
00114 else
00115 {
00116 normalized_time = (ros::Time::now() - counter).toSec() / sin_duration;
00117 }
00118
00119
00120
00121 for (size_t channel = 0; channel < 9; ++channel)
00122 {
00123
00124 double cur_pos = 0.0;
00125
00126 channel_pos.position[channel] = cur_pos;
00127 }
00128
00129
00130 channel_pos.position[8] = 0.5;
00131
00132 double cur_pos = sin(normalized_time*3.14);
00133
00134 channel_pos.position[7] = cur_pos;
00135 channel_pos.position[2] = cur_pos;
00136 channel_pos.position[3] = cur_pos;
00137 channel_pos.position[4] = cur_pos;
00138 channel_pos.position[5] = cur_pos;
00139 channel_pos.position[6] = cur_pos;
00140
00141
00142 channel_pos_pub.publish(channel_pos);
00143 }
00144 rate.sleep();
00145 ros::spinOnce();
00146
00147
00148
00149
00150 }
00151
00152 return 0;
00153 }