Skip to content

Commit

Permalink
Merge pull request #7 from ProjectLadon/master
Browse files Browse the repository at this point in the history
Adding MKR1000 support
  • Loading branch information
frankjoshua committed Sep 24, 2019
2 parents fbb2181 + d4b48b6 commit c0e2b75
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 27 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ sentence=Use an Arduino as a ROS publisher/subscriber
paragraph=Works with http://wiki.ros.org/rosserial, requires a rosserial node to connect
category=Communication
url=https://github.com/frankjoshua/rosserial_arduino_lib
architectures=avr
architectures=*
includes=ros.h
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Use an Arduino as a ROS publisher/subscriber

Works with http://wiki.ros.org/rosserial, requires a rosserial node to connect

This fork exists for the purpose of implementing MKR1000 support.
78 changes: 78 additions & 0 deletions src/MKR1000Hardware.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Software License Agreement (BSD License)
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote prducts derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef MKR1000HARDWARE_H
#define MKR1000HARDWARE_H

#include <WiFi101.h>

class MKR1000Hardware {
public:
MKR1000Hardware()
{
}

void setConnection(IPAddress &server, int port = 11411) {
this->server = server;
this->serverPort = port;
}

IPAddress getLocalIP() {
return WiFi.localIP();
}

void init() {
this->tcp.connect(this->server, this->serverPort);
}

int read() {
if (this->tcp.connected()) {
return tcp.read();
} else {
this->tcp.connect(this->server, this->serverPort);
}
return -1;
};

void write(const uint8_t* data, size_t length) {
tcp.write(data, length);
}

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

protected:
WiFiClient tcp;
IPAddress server;
uint16_t serverPort = 11411;
};

#endif // MKR1000HARDWARE_H
59 changes: 33 additions & 26 deletions src/ros.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2011, Willow Garage, Inc.
Expand Down Expand Up @@ -41,6 +41,9 @@
#if defined(ESP8266)
#include "Esp8266Hardware.h"
#endif
#if defined(MKR1000)
#include "MKR1000Hardware.h"
#endif

#define FLASH_CONVERTER_BUFFER 150

Expand All @@ -54,38 +57,38 @@ namespace ros
private:
char* buffer_;
int buffer_index_;

const char* readFromFlash( const __FlashStringHelper * what )
{
PGM_P lp_p = (PGM_P) what ;

int offset = buffer_index_;
while ( buffer_index_ < FLASH_CONVERTER_BUFFER - 1 )

while ( buffer_index_ < FLASH_CONVERTER_BUFFER - 1 )
{
buffer_[ buffer_index_ ] = pgm_read_byte( lp_p++ );

if ( buffer_[ buffer_index_ ] == 0)
{
buffer_index_++;

break;
}

buffer_index_++;
}

if ( buffer_index_ >= FLASH_CONVERTER_BUFFER - 1 )
{
read_out_error_ = DefaultReadOutBuffer_::BufferOverflow;
}

return buffer_ + offset ;
}

protected:
ReadoutError read_out_error_;

// overrider of method from DefaultReadOutBuffer_
virtual const char * readTopic( const char * topic, bool from_flash )
{
Expand All @@ -98,36 +101,36 @@ namespace ros
return topic;
}
}

public:
FlashReadOutBuffer_()
FlashReadOutBuffer_()
{
buffer_index_ = 0;

buffer_ = new char[ FLASH_CONVERTER_BUFFER ];

buffer_[0] = 0; //zero termination at beginning
buffer_[ FLASH_CONVERTER_BUFFER - 1 ] = 0; // assure zero termination
}
virtual ~FlashReadOutBuffer_()

virtual ~FlashReadOutBuffer_()
{
delete buffer_;
}

// for md5sum / msg type
virtual const char * readMsgInfo( const char * msg_info )
{
return readFromFlash( reinterpret_cast<const __FlashStringHelper*>( msg_info ) );
}

// for log msgs
const char * readLog( const __FlashStringHelper * msg )
{
return readFromFlash( msg );
}
};

#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega168__)
/* downsize our buffers */
typedef NodeHandle_<ArduinoHardware, 6, 6, 150, 150, FlashReadOutBuffer_> NodeHandle;
Expand All @@ -139,22 +142,26 @@ namespace ros
#elif defined(ESP8266)

typedef NodeHandle_<Esp8266Hardware> NodeHandle;


#elif defined(MKR1000)

typedef NodeHandle_<MKR1000Hardware> NodeHandle;

#elif defined(SPARK)
typedef NodeHandle_<ArduinoHardware, 10, 10, 2048, 2048> NodeHandle;

#elif defined(BOARD_ID_Pilo)
#include <ZRos.h> // refers to git@github.com:zoubworldArduino/ZRos.git
#include <ZRos.h> // refers to git@github.com:zoubworldArduino/ZRos.git
typedef NodeHandle_<ArduinoHardwareSerial, 24, 24, 128, 128> NodeHandle;

#elif defined(BOARD_ID_Captor)
#include <ZRos.h> // refers to git@github.com:zoubworldArduino/ZRos.git
#include <ZRos.h> // refers to git@github.com:zoubworldArduino/ZRos.git
typedef NodeHandle_<ArduinoHardwareSerial, 24, 24, 128, 128> NodeHandle;
#else
typedef NodeHandle_<ArduinoHardware, 25, 25, 512, 512, FlashReadOutBuffer_> NodeHandle;

#endif
#endif

}

#endif

0 comments on commit c0e2b75

Please sign in to comment.