Skip to content

Commit

Permalink
Merge pull request #27 from rgleichman/master
Browse files Browse the repository at this point in the history
Issue #26 quick fix and add service client example
  • Loading branch information
acowley committed Dec 18, 2014
2 parents cd5a9fd + 509150d commit b712476
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 3 deletions.
15 changes: 15 additions & 0 deletions Examples/AddTwoIntsClient/AddTwoIntsClient.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Name: ROS-AddTwoIntsClient
Version: 0.0
Synopsis: I am code
Cabal-version: >=1.6
Category: Robotics
Build-type: Custom

Executable AddTwoIntsClient
Build-Depends: base >= 4.2 && < 6,
roshask == 0.2.*,
ROS-rospy-tutorials-msgs

GHC-Options: -O2
Hs-Source-Dirs: src
Main-Is: Main.hs
32 changes: 32 additions & 0 deletions Examples/AddTwoIntsClient/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

# Set the build type. Options are:
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
# Debug : w/ debug symbols, w/o optimization
# Release : w/o debug symbols, w/ optimization
# RelWithDebInfo : w/ debug symbols, w/ optimization
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)

rosbuild_init()

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

#uncomment if you have defined messages
#rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()

#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(example examples/example.cpp)
#target_link_libraries(example ${PROJECT_NAME})

add_custom_target(roshask ALL roshask dep ${PROJECT_SOURCE_DIR} COMMAND cd ${PROJECT_SOURCE_DIR} && cabal install)
1 change: 1 addition & 0 deletions Examples/AddTwoIntsClient/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(shell rospack find mk)/cmake.mk
12 changes: 12 additions & 0 deletions Examples/AddTwoIntsClient/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This project shows the simple interface to the service client. Main.hs calls the AddTwoInts service from the ROS tutorials (http://wiki.ros.org/ROS/Tutorials/WritingServiceClient). You can find service definition and the original server code in the rospy_tutorials ROS package.

Before you begin, install roshask. Directions are on the GitHub wiki: https://github.com/acowley/roshask/wiki

To run src/Main.hs:

1. cd <path to roshask>/Examples/AddTwoIntsClient
2. run "roshask dep" (this generates the Haskell Request and Response types from rospy_tutorials/srv/AddTwoInts.srv)
3. In another terminal run "roscore": This starts the ROS master.
4.a In another terminal cd <path to roshask>/Examples/AddTwoIntsClient/src
4.b run "python add_two_ints.py": This starts the add_two_ints server.
3. In the original terminal run "cabal run": This compiles and runs "Main.hs". You should see "Right (AddTwoIntsResponse {sum = 15})" printed out. In the termial where add_two_ints_server.py is running you should see "Returning [10 + 5 = 15]". You can also do "runhaskell Main.hs" in Examples/AddTwoIntsClient/src.
5 changes: 5 additions & 0 deletions Examples/AddTwoIntsClient/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Distribution.Simple
import Ros.Internal.SetupUtil

main = defaultMainWithHooks $
simpleUserHooks { confHook = rosConf }
14 changes: 14 additions & 0 deletions Examples/AddTwoIntsClient/mainpage.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
\mainpage
\htmlinclude manifest.html

\b AddTwoIntsClient

<!--
Provide an overview of your package.
-->

-->


*/
15 changes: 15 additions & 0 deletions Examples/AddTwoIntsClient/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<package>
<description brief="AddTwoIntsClient">

AddTwoIntsClient

</description>
<author>robbie</author>
<license>BSD</license>
<review status="unreviewed" notes=""/>
<url>http://ros.org/wiki/AddTwoIntsClient</url>
<depend package="rospy_tutorials"/>

</package>


12 changes: 12 additions & 0 deletions Examples/AddTwoIntsClient/src/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Main (main) where
import qualified Ros.Rospy_tutorials.AddTwoIntsRequest as Req
import qualified Ros.Rospy_tutorials.AddTwoIntsResponse as Res
import Ros.Service (callService)
import Ros.Service.ServiceTypes

type Response a = IO (Either ServiceResponseExcept a)

main :: IO ()
main = do
response <- callService "/add_two_ints" Req.AddTwoIntsRequest{Req.a=10, Req.b=5} :: Response Res.AddTwoIntsResponse
print response
56 changes: 56 additions & 0 deletions Examples/AddTwoIntsClient/src/add_two_ints_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2008, Willow Garage, Inc.
# All rights reserved.
#
# 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 products 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.
#
# Revision $Id$

## Simple demo of a rospy service that add two integers

NAME = 'add_two_ints_server'

# import the AddTwoInts service
from rospy_tutorials.srv import *
import rospy

def add_two_ints(req):
print("Returning [%s + %s = %s]" % (req.a, req.b, (req.a + req.b)))
return AddTwoIntsResponse(req.a + req.b)

def add_two_ints_server():
rospy.init_node(NAME)
s = rospy.Service('add_two_ints', AddTwoInts, add_two_ints)

# spin() keeps Python from exiting until node is shutdown
rospy.spin()

if __name__ == "__main__":
add_two_ints_server()
5 changes: 2 additions & 3 deletions src/executable/PkgInit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ prepCabal pkgName rosDeps = B.writeFile (pkgName</>(pkgName++".cabal")) $
, " vector > 0.7,"
, " time >= 1.1,"
, " ROS-rosgraph-msgs,"
, B.append " roshask == 0.1.*" moreDeps
, B.append " roshask == 0.2.*" moreDeps
, rosDeps
, " GHC-Options: -O2"
, " Hs-Source-Dirs: src"
Expand All @@ -67,7 +67,7 @@ prepCabal pkgName rosDeps = B.writeFile (pkgName</>(pkgName++".cabal")) $
, " Build-Depends: base >= 4.2 && < 6,"
, " vector > 0.7,"
, " time >= 1.1,"
, B.append " roshask == 0.1.*" moreDeps
, B.append " roshask == 0.2.*" moreDeps
, rosDeps
, " GHC-Options: -O2"
, B.concat [" Exposed-Modules: ", pkgName']
Expand Down Expand Up @@ -109,4 +109,3 @@ prepLib pkgName = writeFile (pkgName</>"src"</>pkgName'++".hs") . concat $
, nodeName++" = return ()\n"]
where pkgName' = toUpper (head pkgName) : tail pkgName
nodeName = toLower (head pkgName) : tail pkgName

0 comments on commit b712476

Please sign in to comment.