19 #include <asr_msgs/AsrObject.h> 20 #include <geometry_msgs/PoseStamped.h> 21 #include <sensor_msgs/JointState.h> 25 #include <boost/thread.hpp> 26 #include <boost/date_time/posix_time/posix_time.hpp> 33 #define RAD_TO_DEG (180.0 / M_PI) 34 #define DEG_TO_RAD (1 / RAD_TO_DEG) 72 void fobCB(
const asr_msgs::AsrObject& fob_msg) {
74 if(!fob_msg.sampledPoses.size()){
75 std::cerr <<
"Got a AsrObject without poses." << std::endl;
79 if (!fob_msg.identifier.empty() && strcmp(fob_msg.identifier.c_str(), fob_tracking_point_left.c_str()) == 0) {
81 fob_pose_left = fob_msg.sampledPoses.front().pose;
82 }
else if (!fob_msg.identifier.empty() && strcmp(fob_msg.identifier.c_str(), fob_tracking_point_right.c_str()) == 0) {
84 fob_pose_right = fob_msg.sampledPoses.front().pose;
89 void ptuCB(
const sensor_msgs::JointState& ptu_msg) {
90 ptuPosition = ptu_msg.position;
96 nh.
getParam(
"ptu_pub_topic", ptu_state_cmd);
97 nh.
getParam(
"ptu_sub_topic", ptu_state);
98 nh.
getParam(
"fob_sub_topic", fob_topic);
99 nh.
getParam(
"fob_tracking_point_left", fob_tracking_point_left);
100 nh.
getParam(
"fob_tracking_point_right", fob_tracking_point_right);
102 nh.
getParam(
"panAmount", panAmount);
103 nh.
getParam(
"tiltAmount", tiltAmount);
105 std::string fob_frame, ptu_frame;
106 nh.
getParam(
"tracker_frame", fob_frame);
107 nh.
getParam(
"ptu_base_frame", ptu_frame);
113 fobPoint.header.frame_id = fob_frame;
115 ptuPoint.header.frame_id = ptu_frame;
118 boost::thread trackerThread(
spin,
this);
120 trackerThread.interrupt();
123 tcsetattr(STDIN_FILENO, TCSANOW, &
oldt);
142 double panAngle = (p.
x < 0)? 1 : -1;
145 double tiltAngle = (p.
z > 0)? -1 : 1;
148 pantilt.
x = panAngle;
149 pantilt.
y = tiltAngle;
155 if(c!=
'l' && c !=
'r'){
161 fobPoint.point.x = fob_pose_left.position.x;
162 fobPoint.point.y = fob_pose_left.position.y;
163 fobPoint.point.z = fob_pose_left.position.z;
165 fobPoint.point.x = fob_pose_right.position.x;
166 fobPoint.point.y = fob_pose_right.position.y;
167 fobPoint.point.z = fob_pose_right.position.z;
175 ROS_INFO(
"Target pan tilt angle: ([%f %f])", pan, tilt);
177 sensor_msgs::JointState pantiltState;
180 pantiltState.name.push_back(
"pan");
181 pantiltState.name.push_back(
"tilt");
183 pantiltState.position.push_back(pan);
184 pantiltState.position.push_back(tilt);
186 pantiltState.velocity.push_back(0);
187 pantiltState.velocity.push_back(0);
192 pan = pan + ptuPosition[0];
193 tilt = tilt + ptuPosition[1];
202 tcgetattr(STDIN_FILENO, &
oldt);
204 newt.c_lflag &= ~(ICANON | ECHO);
205 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
207 tcsetattr(STDIN_FILENO, TCSANOW, &
oldt);
222 ROS_INFO(
"Press <l> to move PTU to left tracker.");
223 ROS_INFO(
"Press <r> to move PTU to right tracker.");
224 ROS_INFO(
"Use Arrowkeys to move PTU (do not hold key down).");
227 char c = tracker->
getKey();
229 if(c ==
'l' || c ==
'r'){
240 boost::this_thread::sleep(boost::posix_time::milliseconds(100));
245 int main(
int argc,
char** argv)
249 new ::PTUTracker(nh);
geometry_msgs::Pose fob_pose_right
std::vector< double > ptuPosition
void publish(const boost::shared_ptr< M > &message) const
geometry_msgs::Pose fob_pose_left
Point2f toSphereCoords(geometry_msgs::PointStamped p)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
geometry_msgs::PointStamped ptuPoint
ROSCPP_DECL void spin(Spinner &spinner)
void ptuCB(const sensor_msgs::JointState &ptu_msg)
void rotPTUAbsolute(double pan, double tilt)
static void spin(PTUTracker *tracker)
Point2f toSphereCoords(Point3f pt)
std::string fob_tracking_point_right
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
tf::TransformBroadcaster tb
void fobCB(const asr_msgs::AsrObject &fob_msg)
bool getParam(const std::string &key, std::string &s) const
std::string ptu_state_cmd
PTUTracker(ros::NodeHandle nh)
geometry_msgs::PointStamped fobPoint
void rotPTURelative(double pan, double tilt)
std::string fob_tracking_point_left