trigger.cpp
Go to the documentation of this file.
2 
3 namespace trigger
4 {
5 Trigger::Trigger() : vimba_system_(AVT::VmbAPI::VimbaSystem::GetInstance()), pnh_("~")
6 {
7 }
8 
10 {
12 }
13 
15 {
16  VmbErrorType return_value = vimba_system_.Startup();
17 
18  if (return_value != VmbErrorSuccess)
19  {
20  ROS_ERROR_STREAM("Failed to start Vimba system, vimba error code: " << return_value);
21  ros::shutdown();
22  }
23 
24  LoadParams();
26 
27  if (trigger_src_ == "timer")
28  {
30  }
31  else if (trigger_src_ == "subscriber")
32  {
33  trigger_sub_ = nh_.subscribe("trigger_input", 10, &Trigger::TriggerCb, this);
34  }
35  else
36  {
37  ROS_ERROR("Unknown trigger_src %s", trigger_src_.c_str());
38  ros::shutdown();
39  }
40 }
41 
43 {
44  std::string destination_ip;
45  pnh_.param<std::string>("destination_ip", destination_ip, "192.168.3.40");
46  pnh_.param<std::string>("trigger_src", trigger_src_, "timer");
47  pnh_.param<float>("timer_period", timer_period_, 0.1);
48  pnh_.param<int>("action_device_key", action_device_key_, 1);
49  pnh_.param<int>("action_group_key", action_group_key_, 1);
50  pnh_.param<int>("action_group_mask", action_group_mask_, 1);
51 
52  if (inet_aton(destination_ip.c_str(), &destination_ip_) == 0)
53  {
54  ROS_ERROR("Unable to parse desination_ip: %s", destination_ip.c_str());
55  ros::shutdown();
56  }
57 }
58 
60 {
61  VmbErrorType return_value = VmbErrorSuccess;
62 
63  if (!SetIntFeatureValue("GevActionDestinationIPAddress", destination_ip_.s_addr))
64  {
65  ROS_ERROR("Could not set destination address");
66  }
67 
68  ROS_INFO("Destination address set");
69 }
70 
72 {
73  return (SetIntFeatureValue("ActionDeviceKey", action_device_key_) && SetIntFeatureValue("ActionGroupKey", action_group_key_) &&
74  SetIntFeatureValue("ActionGroupMask", action_group_mask_));
75 }
76 
77 // Sets an integer feature value on the vimba system
78 bool Trigger::SetIntFeatureValue(const std::string& name, int64_t value)
79 {
80  VmbErrorType return_value = VmbErrorSuccess;
81 
82  AVT::VmbAPI::FeaturePtr feature_ptr;
83  return_value = vimba_system_.GetFeatureByName(name.c_str(), feature_ptr);
84 
85  if (return_value != VmbErrorSuccess)
86  {
87  ROS_ERROR_STREAM("Failed to get feature, vimba error code: " << return_value);
88  return false;
89  }
90  else
91  {
92  return_value = feature_ptr->SetValue((VmbInt64_t)value);
93  }
94 
95  return (return_value == VmbErrorSuccess);
96 }
97 
99 {
101 }
102 
103 void Trigger::TriggerCb(const std_msgs::Bool::ConstPtr& msg)
104 {
106 }
107 
109 {
110  if (!PrepareActionCommand())
111  {
112  ROS_ERROR_THROTTLE(1.0, "Failed to prepare action command");
113  return;
114  }
115 
116  VmbErrorType return_value = VmbErrorSuccess;
117 
118  AVT::VmbAPI::FeaturePtr lFeature;
119  return_value = vimba_system_.GetFeatureByName("ActionCommand", lFeature);
120 
121  if (return_value == VmbErrorSuccess)
122  {
123  return_value = lFeature->RunCommand();
124  }
125 
126  if (return_value == VmbErrorSuccess)
127  {
128  ROS_DEBUG("Action command sent");
129  }
130  else
131  {
132  ROS_ERROR_THROTTLE(1.0, "Failed to send action command");
133  }
134 }
135 
136 } // namespace trigger
trigger::Trigger::Init
void Init()
Definition: trigger.cpp:14
ROS_ERROR_THROTTLE
#define ROS_ERROR_THROTTLE(period,...)
trigger::Trigger::SendActionCommand
void SendActionCommand()
Definition: trigger.cpp:108
trigger::Trigger::TriggerCb
void TriggerCb(const std_msgs::Bool::ConstPtr &msg)
Definition: trigger.cpp:103
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(args)
trigger::Trigger::trigger_src_
std::string trigger_src_
Definition: trigger.h:43
trigger::Trigger::SetIntFeatureValue
bool SetIntFeatureValue(const std::string &name, int64_t value)
Definition: trigger.cpp:78
trigger::Trigger::nh_
ros::NodeHandle nh_
Definition: trigger.h:36
AVT
Definition: AncillaryData.h:35
VmbErrorType
VmbErrorType
Definition: VmbCommonTypes.h:106
ros::shutdown
ROSCPP_DECL void shutdown()
trigger::Trigger::action_group_mask_
int action_group_mask_
Definition: trigger.h:47
AVT::VmbAPI::VimbaSystem::Startup
IMEXPORT VmbErrorType Startup()
Definition: VimbaSystem.cpp:93
ROS_DEBUG
#define ROS_DEBUG(...)
trigger::Trigger::~Trigger
~Trigger()
Definition: trigger.cpp:9
trigger::Trigger::InitializeAddress
void InitializeAddress()
Definition: trigger.cpp:59
trigger::Trigger::destination_ip_
struct in_addr destination_ip_
Definition: trigger.h:42
AVT::VmbAPI::FeatureContainer::GetFeatureByName
IMEXPORT VmbErrorType GetFeatureByName(const char *pName, FeaturePtr &pFeature)
Definition: FeatureContainer.cpp:72
trigger::Trigger::timer_period_
float timer_period_
Definition: trigger.h:44
trigger::Trigger::PrepareActionCommand
bool PrepareActionCommand()
Definition: trigger.cpp:71
VmbErrorSuccess
@ VmbErrorSuccess
Definition: VmbCommonTypes.h:108
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
ros::TimerEvent
trigger::Trigger::Trigger
Trigger()
Definition: trigger.cpp:5
VmbInt64_t
long long VmbInt64_t
Definition: VmbCommonTypes.h:75
trigger::Trigger::pnh_
ros::NodeHandle pnh_
Definition: trigger.h:35
trigger::Trigger::TimerCb
void TimerCb(const ros::TimerEvent &event)
Definition: trigger.cpp:98
trigger::Trigger::LoadParams
void LoadParams()
Definition: trigger.cpp:42
trigger::Trigger::vimba_system_
AVT::VmbAPI::VimbaSystem & vimba_system_
Definition: trigger.h:32
AVT::VmbAPI::VimbaSystem::Shutdown
IMEXPORT VmbErrorType Shutdown()
Definition: VimbaSystem.cpp:113
trigger.h
ROS_ERROR
#define ROS_ERROR(...)
trigger::Trigger::action_group_key_
int action_group_key_
Definition: trigger.h:46
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
trigger::Trigger::action_device_key_
int action_device_key_
Definition: trigger.h:45
trigger
Definition: trigger.h:12
ROS_INFO
#define ROS_INFO(...)
ros::NodeHandle::createTimer
Timer createTimer(Duration period, const TimerCallback &callback, bool oneshot=false, bool autostart=true) const
ros::Duration
trigger::Trigger::trigger_timer_
ros::Timer trigger_timer_
Definition: trigger.h:38
trigger::Trigger::trigger_sub_
ros::Subscriber trigger_sub_
Definition: trigger.h:39


avt_vimba_camera
Author(s): Allied Vision Technologies, Miquel Massot
autogenerated on Sat Jun 3 2023 02:14:12