Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.5 #5

Merged
merged 2 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Regenerate the python stubs whenever changes are made to the *src/main/proto/ros

## RosBridge Usage

The *ros-grpc-bridge* jar files are published to [Jitpack.io](https://jitpack.io/#athenian-robotics/ros-grpc-bridge/1.0.4).
The *ros-grpc-bridge* jar files are published to [Jitpack.io](https://jitpack.io/#athenian-robotics/ros-grpc-bridge/1.0.5).

### Gradle

Expand All @@ -48,7 +48,7 @@ Add the JitPack repository and dependecy to your root *build.gradle*:

```groovy
dependencies {
compile 'com.github.athenian-robotics:ros-grpc-bridge:1.0.4'
compile 'com.github.athenian-robotics:ros-grpc-bridge:1.0.5'
}
```

Expand All @@ -69,7 +69,7 @@ Add the JitPack repository and dependecy to your *pom.xml*:
<dependency>
<groupId>com.github.athenian-robotics</groupId>
<artifactId>ros-grpc-bridge</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</dependency>
```

Expand Down
94 changes: 94 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
group = 'org.athenian'
version = '1.0.0-SNAPSHOT'
//archivesBaseName = 'ros-grpc-bridge'

//sourceCompatibility = 1.8
//targetCompatibility = 1.8

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'com.google.protobuf'

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
}
}

repositories {
mavenCentral()
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile 'io.grpc:grpc-all:1.9.0'
compile 'com.beust:jcommander:1.72'
compile 'org.slf4j:jul-to-slf4j:1.7.25'
compile 'com.typesafe:config:1.3.2'
compile 'org.assertj:assertj-core:3.9.0'
}

protobuf {
protoc {
// The version of protoc must match protobuf-java. If you don't depend on
// protobuf-java directly, you will be transitively depending on the
// protobuf-java version that grpc depends on.
artifact = 'com.google.protobuf:protoc:3.5.1-1'
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.9.0'
}
}

generateProtoTasks.generatedFilesBaseDir = "${projectDir}/src/generated"

generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}


sourceSets {
main {
java {
srcDirs 'src/generated/main/grpc'
srcDirs 'src/generated/main/java'
}
}
}

jar {
manifest {
attributes "Main-Class": "org.athenian.RosBridge"
}

archiveName 'ros-grpc-bridge.jar'
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}

idea {
module {
sourceDirs += file("${projectDir}/src/generated/main/java");
sourceDirs += file("${projectDir}/src/generated/main/grpc");
}
}

clean {
delete "${projectDir}/src/generated"
}

// Let intellij projects refer to generated code
//idea {
// module {
// sourceDirs += file('${projectDir}/src/generated/main/java');
// sourceDirs += file('${projectDir}/src/generated/main/grpc');
// }
//}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>org.athenian</groupId>
<artifactId>ros-grpc-bridge</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5-SNAPSHOT</version>


<properties>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/athenian/core/RosBridgeServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public void onCompleted() {
}

@Override
public void readEncoderData(EncoderDesc request, StreamObserver<EncoderData> responseObserver) {
public void readEncoderData(EncoderDesc request, StreamObserver<EncoderData> observer) {
logger.info("Returning encoder data for: " + request.getName());
for (int i = 0; i < 20; i++)
responseObserver.onNext(EncoderData.newBuilder().setValue(i).build());
responseObserver.onCompleted();
observer.onNext(EncoderData.newBuilder().setValue(i).build());
observer.onCompleted();
}
}
2 changes: 2 additions & 0 deletions src/main/python/ros_rosbridge_example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import logging
import rospy
from arc852.utils import setup_logging
from geometry_msgs.msg import Twist

from rosbridge_client import RosBridgeClient

logger = logging.getLogger(__name__)
setup_logging()


def main():
Expand Down
3 changes: 3 additions & 0 deletions src/main/python/rosbridge_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ def write_twist(self, twist_data):
self.__stub.writeTwistData(twist_data)
except BaseException as e:
self.__log_error("Failed to reach gRPC server at {0} [{1}]".format(self.__hostname, e))
raise e

def stream_twist(self, iter_val):
try:
self.__stub.streamTwistData(iter_val)
except BaseException as e:
self.__log_error("Failed to reach gRPC server at {0} [{1}]".format(self.__hostname, e))
raise e

def read_encoder(self, encoder_name):
try:
return self.__stub.readEncoderData(EncoderDesc(name=encoder_name))
except BaseException as e:
self.__log_error("Failed to reach gRPC server at {0} [{1}]".format(self.__hostname, e))
raise e

@staticmethod
def newTwistData(lin, ang):
Expand Down
15 changes: 7 additions & 8 deletions src/main/python/rosbridge_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging
import time
from arc852.utils import setup_logging

from rosbridge_client import RosBridgeClient


# logger = logging.getLogger(__name__)

logger = logging.getLogger(__name__)
setup_logging()

def main():
bridge = RosBridgeClient("localhost:50051")
Expand All @@ -15,28 +16,26 @@ def main():
start1 = time.time()
for i in range(count):
twist_data = RosBridgeClient.newTwistData(i, i + 3)
# print("Sending data")
bridge.write_twist(twist_data)
end1 = time.time()
print("Non-streaming elapsed: " + str(end1 - start1))
logger.info("Non-streaming elapsed: " + str(end1 - start1))

# Streaming version
def twist_gen(cnt):
for i in range(cnt):
twist_data = RosBridgeClient.newTwistData(i, i + 2)
# print("Streaming data")
yield twist_data

start2 = time.time()
bridge.stream_twist(twist_gen(count))
end2 = time.time()
print("Streaming elapsed: " + str(end2 - start2))
logger.info("Streaming elapsed: " + str(end2 - start2))

time.sleep(2)

# Read streming encoder values
for data in bridge.read_encoder("wheel2"):
print("Read encoder value: " + str(data.value))
logger.info("Read encoder value: " + str(data.value))


if __name__ == "__main__":
Expand Down