21 #include <boost/thread/thread.hpp> 26 #include "brunel_hand_ros/FingerPose.h" 27 #include "brunel_hand_ros/RawCommand.h" 28 #include "brunel_hand_ros/HandPrimitive.h" 80 ROS_INFO(
"SENDING: %s ", cmd.c_str() );
92 switch (hp.primitive) {
129 serial::Timeout::simpleTimeout(1000) ),
133 ROS_ERROR(
"Failed to connect using %s", devfile.c_str() );
138 ROS_INFO(
"Connected via %s", devfile.c_str() );
145 std::vector<int> fpose;
153 }
while (line[0] !=
'0' && line[0] !=
'1' && line[0] !=
'2' 154 && line[0] !=
'3' && line[0] !=
'4' && line[0] !=
'5' 155 && line[0] !=
'6' && line[0] !=
'7' && line[0] !=
'8' 161 std::string numstring;
162 while ((nextpos = line.find(
"," , thispos+1))
163 != std::string::npos) {
164 numstring = line.substr( thispos+1, nextpos-thispos-1 );
166 fpose.push_back( std::atoi( numstring.c_str() ) );
168 numstring = line.substr( thispos+1 );
169 if (numstring[0] !=
' ' 170 && numstring[0] !=
'\r' 171 && numstring[0] !=
'\n')
172 fpose.push_back( std::atoi( numstring.c_str() ) );
198 }
while (line.substr( 0, 8 ) !=
"CSV mode");
214 }
while (line.substr( 0, 14 ) !=
"Motors ENABLED");
225 int incoming_csvMode = -1;
226 int incoming_motorsEnabled = -1;
230 while (incoming_csvMode < 0 || incoming_motorsEnabled < 0) {
232 if (line.substr( 0, 5 ) ==
"Mode:") {
233 if (line.find(
"CSV" ) != std::string::npos) {
234 incoming_csvMode = 1;
236 incoming_csvMode = 0;
238 }
else if (line.substr( 0, 7 ) ==
"Motors:") {
239 if (line.find(
"ENABLED" ) != std::string::npos) {
240 incoming_motorsEnabled = 1;
242 incoming_motorsEnabled = 0;
247 csvMode = incoming_csvMode ?
true :
false;
252 int main(
int argc,
char **argv )
254 ros::init( argc, argv,
"brunel_hand_proxy" );
261 nh.
param(
"hand_dev_file", devfile, std::string(
"/dev/ttyACM0" ) );
267 posep = nh.
advertise<brunel_hand_ros::FingerPose>(
"fpose", 10, true );
270 submotprimitive = nh.
subscribe(
"/motion_primitive",
277 brunel_hand_ros::FingerPose currentpose;
size_t readline(std::string &buffer, size_t size=65536, std::string eol="\n")
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void callbackRawCommand(const brunel_hand_ros::RawCommand &rc)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void rawCommand(std::string cmd)
int main(int argc, char **argv)
std::vector< int > readFingersPose()
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool getMotorsEnabled() const
void callbackMotionPrimitive(const brunel_hand_ros::HandPrimitive &hp)
ROSCPP_DECL void spinOnce()
size_t write(const uint8_t *data, size_t size)