<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Issues understanding the USBSerial class in usb_serial.h for ROS</title>
		<link>http://forums.leaflabs.com/topic.php?id=1113</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:25:29 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=1113" rel="self" type="application/rss+xml" />

		<item>
			<title>David Mangus on "Issues understanding the USBSerial class in usb_serial.h for ROS"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1113#post-7126</link>
			<pubDate>Wed, 09 Nov 2011 14:46:53 +0000</pubDate>
			<dc:creator>David Mangus</dc:creator>
			<guid isPermaLink="false">7126@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Basically, the developers of ROS made a predefined package to work with their program.  The whole idea of this program is to turn a microcontroller into a information node.  That being said, they gave a template which is the header file you see above.  Which just gives the package they have implemented the ability to use the serial on the microcontroller to serialize/deserialize information.  There really isn't a direct call to this header from my code, its more of a gateway.  I've been programming in C++ for 2 years now, so I'm no expert by any means nor have I done any programming for anything on a large scale.  I've had the writing function working,  but the microcontroller is supposed to sync up with the computer that I'm using through ROS.  Which is not happening so I'm having issues debugging this.  This is a working version of what I'm trying to accomplish with this except for Arduino.&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://kforge.ros.org/rosserial/hg/file/424ee55dd300/rosserial_arduino/src/ros_lib/ArduinoHardware.h&#34; rel=&#34;nofollow&#34;&#62;https://kforge.ros.org/rosserial/hg/file/424ee55dd300/rosserial_arduino/src/ros_lib/ArduinoHardware.h&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Issues understanding the USBSerial class in usb_serial.h for ROS"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1113#post-7114</link>
			<pubDate>Mon, 07 Nov 2011 18:51:59 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7114@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;David Mangus - I took the liberty of adding code quotes to make your code easier to read.&#60;/p&#62;
&#60;p&#62;Which functions do work? Can you post a link (maybe to paste bin) to the main program which is calling this?&#60;/p&#62;
&#60;p&#62;This looks rather strange to me. Have you done much C++?&#60;br /&#62;
I normally only have declarations and inline functions in C++ header files, and not functions.&#60;br /&#62;
I assume this is a header because of the :&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;#ifndef MAPLEHARDWARE_H_
#define MAPLEHARDWARE_H_
...
#endif&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;A small point which won't fix anything, but:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;...
  if (numUnread &#38;gt; 0) {
    return Serial2.read();
  }
  else{return -1;}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;can be written more simply as:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;...
  if (numUnread &#38;gt; 0) {
    return Serial2.read();
  }
  return -1;&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>David Mangus on "Issues understanding the USBSerial class in usb_serial.h for ROS"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1113#post-7112</link>
			<pubDate>Mon, 07 Nov 2011 15:14:45 +0000</pubDate>
			<dc:creator>David Mangus</dc:creator>
			<guid isPermaLink="false">7112@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Here is my updated code.  I switched from the USB to Serial2 on the board using a converter from usb to my computer.  I can't seem to get the read function to work correctly.  I'm not quite sure at this point why.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#ifndef MAPLEHARDWARE_H_
#define MAPLEHARDWARE_H_

#include &#38;quot;WProgram.h&#38;quot;
#include &#38;lt;HardwareSerial.h&#38;gt;

class MapleHardware {
public:

MapleHardware(){
	baud_ =  57600;
	}

void init(){
Serial2.begin(baud_);
}

int read(){
  numUnread = Serial2.available();

  if (numUnread &#38;gt; 0) {
    return Serial2.read();
  }
  else{return -1;}
}

void write(uint8_t* data, int length){
for(int i=0; i&#38;lt;length; i++) Serial2.print(data[i]);
}

unsigned long time(){return millis();}

protected:
uint32 baud_;
int numUnread;
};

#endif&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>poslathian on "Issues understanding the USBSerial class in usb_serial.h for ROS"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1113#post-6849</link>
			<pubDate>Wed, 12 Oct 2011 15:54:43 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">6849@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;cool project, we love ROS - keep us posted!&#60;/p&#62;
&#60;p&#62;You shouldnt need to initialize the USBSerial object, but its something of a singleton. Set your USBSerial* iostream equal to the pre-existing SerialUSB object and you should be OK. Make sure to use the newest libmaple as there were some problems in earlier versions with the SerialUSB. &#60;/p&#62;
&#60;p&#62;Also, you might consider dropping down to the lower level usb functions to give you more control - USBSerial is essentially a wrapper. These (better) functions are in libmaple/usb/usb.h ( &#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/master/libmaple/usb/usb.h&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/master/libmaple/usb/usb.h&#60;/a&#62; ) and allow you to directly copy bytes into and out of the USB buffer. You should be able to build a stream out of that.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>David Mangus on "Issues understanding the USBSerial class in usb_serial.h for ROS"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1113#post-6839</link>
			<pubDate>Wed, 12 Oct 2011 13:51:42 +0000</pubDate>
			<dc:creator>David Mangus</dc:creator>
			<guid isPermaLink="false">6839@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Right now I'm trying to get ROS (Robot Operating System) to communicate with the Maple board.  ROS has a serialization/deserialization package already set up.  Unfortunately for the moment its only set up for Arduino.  This page &#60;a href=&#34;http://www.ros.org/wiki/rosserial_client/Tutorials/Porting%20ROSSerial%20Client&#34; rel=&#34;nofollow&#34;&#62;http://www.ros.org/wiki/rosserial_client/Tutorials/Porting%20ROSSerial%20Client&#60;/a&#62; gives the rough outline of what I need to communicate with the package they have set up.  I looked through what they did for the Arduino board thinking it would be a semi easy port over to the maple but I would like to use the SerialUSB port to do the communication.  I started off looking into the usb_serial.h file and got this set of code.  Sorry ahead of time for not having a link to the code instead of straight code.  The compiler is not giving me errors anymore, but the connection still doesn't work like it should (yes I know that issue is vague)  I'm curious as to what I should use to initialize the USBSerial class as far as getting the usb port to open for this classes use.&#60;/p&#62;
&#60;p&#62;#ifndef MAPLEHARDWARE_H_&#60;br /&#62;
#define MAPLEHARDWARE_H_&#60;/p&#62;
&#60;p&#62;#include &#34;WProgram.h&#34;&#60;br /&#62;
#include &#38;lt;usb_serial.h&#38;gt;&#60;/p&#62;
&#60;p&#62;class MapleHardware {&#60;br /&#62;
public:&#60;/p&#62;
&#60;p&#62;	MapleHardware(){}&#60;/p&#62;
&#60;p&#62;	void init(){&#60;br /&#62;
		iostream-&#38;gt;begin();&#60;br /&#62;
	}&#60;/p&#62;
&#60;p&#62;	int read(){return iostream-&#38;gt;read();};&#60;/p&#62;
&#60;p&#62;	void write(uint8_t* data, int length){&#60;br /&#62;
		for(int i=0; i&#38;lt;length; i++) iostream-&#38;gt;write(data[i]);&#60;br /&#62;
	}&#60;/p&#62;
&#60;p&#62;	unsigned long time(){return millis();}&#60;/p&#62;
&#60;p&#62;protected:&#60;br /&#62;
	USBSerial* iostream;&#60;br /&#62;
};&#60;/p&#62;
&#60;p&#62;#endif
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
