Skip to content

Commit 6a6b81e

Browse files
authored
Add support for VINT networkhub (#172)
This is a port of #127 to ROS2. Closes #135.
1 parent 1f5b7dc commit 6a6b81e

File tree

22 files changed

+176
-0
lines changed

22 files changed

+176
-0
lines changed

phidgets_accelerometer/include/phidgets_accelerometer/accelerometer_ros_i.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class AccelerometerRosI final : public rclcpp::Node
6161
void timerCallback();
6262
rclcpp::TimerBase::SharedPtr timer_;
6363
double publish_rate_;
64+
std::string server_name_;
65+
std::string server_ip_;
6466

6567
rclcpp::Time ros_time_zero_;
6668
bool synchronize_timestamps_{true};

phidgets_accelerometer/src/accelerometer_ros_i.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ AccelerometerRosI::AccelerometerRosI(const rclcpp::NodeOptions& options)
9090
throw std::runtime_error("Publish rate must be <= 1000");
9191
}
9292

93+
this->declare_parameter("server_name",
94+
rclcpp::ParameterType::PARAMETER_STRING);
95+
this->declare_parameter("server_ip",
96+
rclcpp::ParameterType::PARAMETER_STRING);
97+
if (this->get_parameter("server_name", server_name_) &&
98+
this->get_parameter("server_ip", server_ip_))
99+
{
100+
PhidgetNet_addServer(server_name_.c_str(), server_ip_.c_str(), 5661, "",
101+
0);
102+
103+
RCLCPP_INFO(get_logger(), "Using phidget server %s at IP %s",
104+
server_name_.c_str(), server_ip_.c_str());
105+
}
106+
93107
RCLCPP_INFO(
94108
get_logger(),
95109
"Connecting to Phidgets Accelerometer serial %d, hub port %d ...",

phidgets_analog_inputs/include/phidgets_analog_inputs/analog_inputs_ros_i.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class AnalogInputsRosI final : public rclcpp::Node
6161
void timerCallback();
6262
rclcpp::TimerBase::SharedPtr timer_;
6363
double publish_rate_;
64+
std::string server_name_;
65+
std::string server_ip_;
6466

6567
void publishLatest(int index);
6668

phidgets_analog_inputs/src/analog_inputs_ros_i.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ AnalogInputsRosI::AnalogInputsRosI(const rclcpp::NodeOptions& options)
6767
throw std::runtime_error("Publish rate must be <= 1000");
6868
}
6969

70+
this->declare_parameter("server_name",
71+
rclcpp::ParameterType::PARAMETER_STRING);
72+
this->declare_parameter("server_ip",
73+
rclcpp::ParameterType::PARAMETER_STRING);
74+
if (this->get_parameter("server_name", server_name_) &&
75+
this->get_parameter("server_ip", server_ip_))
76+
{
77+
PhidgetNet_addServer(server_name_.c_str(), server_ip_.c_str(), 5661, "",
78+
0);
79+
80+
RCLCPP_INFO(get_logger(), "Using phidget server %s at IP %s",
81+
server_name_.c_str(), server_ip_.c_str());
82+
}
83+
7084
RCLCPP_INFO(
7185
get_logger(),
7286
"Connecting to Phidgets AnalogInputs serial %d, hub port %d ...",

phidgets_analog_outputs/include/phidgets_analog_outputs/analog_outputs_ros_i.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class AnalogOutputsRosI final : public rclcpp::Node
6868
std::vector<std::unique_ptr<AnalogOutputSetter>> out_subs_;
6969

7070
rclcpp::Service<phidgets_msgs::srv::SetAnalogOutput>::SharedPtr out_srv_;
71+
std::string server_name_;
72+
std::string server_ip_;
7173

7274
bool setSrvCallback(
7375
const std::shared_ptr<phidgets_msgs::srv::SetAnalogOutput::Request> req,

phidgets_analog_outputs/src/analog_outputs_ros_i.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ AnalogOutputsRosI::AnalogOutputsRosI(const rclcpp::NodeOptions& options)
4949
int serial_num =
5050
this->declare_parameter("serial", -1); // default open any device
5151

52+
this->declare_parameter("server_name",
53+
rclcpp::ParameterType::PARAMETER_STRING);
54+
this->declare_parameter("server_ip",
55+
rclcpp::ParameterType::PARAMETER_STRING);
56+
if (this->get_parameter("server_name", server_name_) &&
57+
this->get_parameter("server_ip", server_ip_))
58+
{
59+
PhidgetNet_addServer(server_name_.c_str(), server_ip_.c_str(), 5661, "",
60+
0);
61+
62+
RCLCPP_INFO(get_logger(), "Using phidget server %s at IP %s",
63+
server_name_.c_str(), server_ip_.c_str());
64+
}
65+
5266
int hub_port = this->declare_parameter(
5367
"hub_port", 0); // only used if the device is on a VINT hub_port
5468

phidgets_digital_inputs/include/phidgets_digital_inputs/digital_inputs_ros_i.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class DigitalInputsRosI final : public rclcpp::Node
5959
void timerCallback();
6060
rclcpp::TimerBase::SharedPtr timer_;
6161
double publish_rate_;
62+
std::string server_name_;
63+
std::string server_ip_;
6264

6365
void publishLatest(int index);
6466

phidgets_digital_inputs/src/digital_inputs_ros_i.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ DigitalInputsRosI::DigitalInputsRosI(const rclcpp::NodeOptions& options)
6565
throw std::runtime_error("Publish rate must be <= 1000");
6666
}
6767

68+
this->declare_parameter("server_name",
69+
rclcpp::ParameterType::PARAMETER_STRING);
70+
this->declare_parameter("server_ip",
71+
rclcpp::ParameterType::PARAMETER_STRING);
72+
if (this->get_parameter("server_name", server_name_) &&
73+
this->get_parameter("server_ip", server_ip_))
74+
{
75+
PhidgetNet_addServer(server_name_.c_str(), server_ip_.c_str(), 5661, "",
76+
0);
77+
78+
RCLCPP_INFO(get_logger(), "Using phidget server %s at IP %s",
79+
server_name_.c_str(), server_ip_.c_str());
80+
}
81+
6882
RCLCPP_INFO(
6983
get_logger(),
7084
"Connecting to Phidgets DigitalInputs serial %d, hub port %d ...",

phidgets_digital_outputs/include/phidgets_digital_outputs/digital_outputs_ros_i.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class DigitalOutputsRosI final : public rclcpp::Node
6868
std::vector<std::unique_ptr<DigitalOutputSetter>> out_subs_;
6969

7070
rclcpp::Service<phidgets_msgs::srv::SetDigitalOutput>::SharedPtr out_srv_;
71+
std::string server_name_;
72+
std::string server_ip_;
7173

7274
void setSrvCallback(
7375
const std::shared_ptr<phidgets_msgs::srv::SetDigitalOutput::Request>

phidgets_digital_outputs/src/digital_outputs_ros_i.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ DigitalOutputsRosI::DigitalOutputsRosI(const rclcpp::NodeOptions& options)
4848

4949
RCLCPP_INFO(get_logger(), "Starting Phidgets Digital Outputs");
5050

51+
this->declare_parameter("server_name",
52+
rclcpp::ParameterType::PARAMETER_STRING);
53+
this->declare_parameter("server_ip",
54+
rclcpp::ParameterType::PARAMETER_STRING);
55+
if (this->get_parameter("server_name", server_name_) &&
56+
this->get_parameter("server_ip", server_ip_))
57+
{
58+
PhidgetNet_addServer(server_name_.c_str(), server_ip_.c_str(), 5661, "",
59+
0);
60+
61+
RCLCPP_INFO(get_logger(), "Using phidget server %s at IP %s",
62+
server_name_.c_str(), server_ip_.c_str());
63+
}
64+
5165
int serial_num =
5266
this->declare_parameter("serial", -1); // default open any device
5367

0 commit comments

Comments
 (0)