After banging around a bit I found a solution, thanks tician.
1. Call service SetupChannel-type
2. Publish Digital.msg-type
It doesn't matter if the Digital.msg publisher already publishes to the led_1-topic, so the order is not important.
Putting the service call in main didn't work for me, maybe had to wait for the arbotix-service to come up, so I put it into callback (not the best solution).
#include <ros/ros.h>
#include <sensor_msgs/RegionOfInterest.h>
#include <arbotix_msgs/Digital.h>
#include <arbotix_msgs/SetupChannel.h>
ros::Subscriber ROIs;
ros::Publisher LEDp;
arbotix_msgs::Digital dmsg;
ros::ServiceClient client;
unsigned int sq = 0;
void roi_cb(const sensor_msgs::RegionOfInterest msg)
{sq++;
arbotix_msgs::SetupChannel srv;
srv.request.pin = 6;
srv.request.rate = 10;
srv.request.topic_name = "led_1";
srv.request.value = 255;
if (client.call(srv))
ROS_INFO("yes");
else
ROS_ERROR("no");
dmsg.header.seq = sq;
dmsg.header.frame_id = "led_1_pin6";
dmsg.header.stamp = ros::Time::now();
dmsg.value = 255;
dmsg.direction = 255;
LEDp.publish(dmsg);
}
int main(int argc, char** argv)
{ros::init(argc, argv, "pan_tilt");
ros::NodeHandle nh;
ROIs = nh.subscribe("roi", 100, &roi_cb);
LEDp = nh.advertise<arbotix_msgs::Digital>("/arbotix/led_1", 1000);
client = nh.serviceClient<arbotix_msgs::SetupChannel>("/arbotix/SetupDigitalOut");
ros::spin();
return (0);
}
Bookmarks