projector_controller.cpp
Go to the documentation of this file.
1 
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2009, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the Willow Garage nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
36 #include "ros/console.h"
38 
40 
41 using std::string;
42 using namespace controller;
43 
45 {
46  ROS_DEBUG("creating controller...");
47 }
48 
49 ProjectorController::~ProjectorController()
50 {
51 }
52 
54 {
56  uint32_t rising = projector_->state_.rising_timestamp_us_;
57  uint32_t falling = projector_->state_.falling_timestamp_us_;
58  double curtime = robot_->getTime().toSec();
59  double delta = curtime - start_time_;
60  delta -= fmod(delta, 0.001);
61 
63 
64  if (falling != old_falling_)
65  {
66  old_falling_ = falling;
67  if (falling_edge_pub_ && falling_edge_pub_->trylock())
68  {
69  //falling_edge_pub_->msg_.stamp = ros::Time(curtime - (stamp - falling) * 1e-6);
70  //falling_edge_pub_->msg_.stamp = ros::Time((stamp - falling) * 1e-6);
71  falling_edge_pub_->msg_.stamp = ros::Time(delta);
72  falling_edge_pub_->unlockAndPublish();
73  }
74  }
75  if (rising != old_rising_)
76  {
77  old_rising_ = rising;
78  if (rising_edge_pub_ && rising_edge_pub_->trylock())
79  {
80  //rising_edge_pub_->msg_.stamp = ros::Time(curtime - (stamp - rising) * 1e-6);
81  //rising_edge_pub_->msg_.stamp = ros::Time((stamp - rising) * 1e-6);
82  rising_edge_pub_->msg_.stamp = ros::Time(delta);
83  rising_edge_pub_->unlockAndPublish();
84  }
85  }
86 }
87 
89 {
90  projector_->command_.enable_ = true;
92  //projector_->command_.M_ = 0xf;
95  start_time_ = 0;//robot_->getTime().toSec();
96 }
97 
99 {
100  projector_->command_.enable_ = false;
102  //projector_->command_.M_ = 0x0;
104 }
105 
107 {
108  node_handle_ = n;
109 
110  assert(robot);
111  robot_=robot;
112 
113  ROS_DEBUG("ProjectorController::init starting");
114 
115  // Get the actuator name.
116 
117  if (!n.getParam("actuator", actuator_name_)){
118  ROS_ERROR("ProjectorController was not given an actuator.");
119  return false;
120  }
121 
122  rising_edge_pub_.reset(new realtime_tools::RealtimePublisher<std_msgs::Header>(n, "rising_edge_timestamps", 10));
123  falling_edge_pub_.reset(new realtime_tools::RealtimePublisher<std_msgs::Header>(n, "falling_edge_timestamps", 10));
124 
126  ROS_DEBUG("Got projector: %p\n", projector_);
127  if (!projector_)
128  {
129  ROS_ERROR("ProjectorController could not find digital out named \"%s\".",
130  actuator_name_.c_str());
131  return false;
132  }
133 
134  n.param("current", current_setting_, 27.0);
135  ROS_DEBUG("Projector current = %f", current_setting_);
136 
137  return true;
138 }
boost::scoped_ptr< realtime_tools::RealtimePublisher< std_msgs::Header > > falling_edge_pub_
bool init(pr2_mechanism_model::RobotState *robot, ros::NodeHandle &n)
pr2_hardware_interface::HardwareInterface * hw_
boost::scoped_ptr< realtime_tools::RealtimePublisher< std_msgs::Header > > rising_edge_pub_
pr2_hardware_interface::Projector * projector_
PLUGINLIB_EXPORT_CLASS(pr2_mechanism_model::PR2BeltCompensatorTransmission, pr2_mechanism_model::Transmission) namespace pr2_mechanism_model
bool param(const std::string &param_name, T &param_val, const T &default_val) const
bool getParam(const std::string &key, std::string &s) const
pr2_mechanism_model::RobotState * robot_
#define ROS_ERROR(...)
#define ROS_DEBUG(...)
Projector * getProjector(const std::string &name) const


ethercat_trigger_controllers
Author(s): Blaise Gassend
autogenerated on Wed Jun 5 2019 19:33:55