-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from rgleichman/master
Issue #26 quick fix and add service client example
- Loading branch information
Showing
10 changed files
with
164 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(shell rospack find mk)/cmake.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
--> | ||
|
||
--> | ||
|
||
|
||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters