-
Notifications
You must be signed in to change notification settings - Fork 180
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
Add CapnProto Publisher and Subscriber to Python API #1089
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
674a53d
Add CapnPublisher to python binding
CruxDevStuff b6928a0
Add CapnSubsriber to python binding
CruxDevStuff 0849ff7
Fix : make topic type consistent with C++
CruxDevStuff e8e1d6a
Merge branch 'eclipse-ecal:master' into master
CruxDevStuff 68744bd
Add capnp python examples
CruxDevStuff b6da781
Update: README formatting
CruxDevStuff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,23 @@ | ||
## Capnp Publisher and Subscriber Example | ||
|
||
Minimal Publisher - publishes an example Imu message | ||
``` | ||
python3 pub.py | ||
``` | ||
|
||
Minimal Subscriber - subscribes to the Imu message | ||
``` | ||
python3 sub.py | ||
``` | ||
|
||
Capnp Message Struct | ||
|
||
``` | ||
struct Imu { | ||
timestamp @0: Int64; | ||
accel @1: List(Float32); | ||
gyro @2: List(Float32); | ||
} | ||
``` | ||
|
||
|
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,8 @@ | ||
@0xb6249c5df1f7e512; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you use the same message like is used for the c++ samples? this way we can communicate the samples with python send / c++ receive and vice versa. |
||
|
||
struct Imu { | ||
timestamp @0: Int64; | ||
accel @1: List(Float32); | ||
gyro @2: List(Float32); | ||
} | ||
|
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 @@ | ||
import sys | ||
import time | ||
import capnp | ||
import random | ||
import time | ||
import messages_capnp as msgs | ||
import ecal.core.core as ecal_core | ||
from ecal.core.publisher import StringPublisher, MessagePublisher, CapnPublisher | ||
|
||
if __name__ == "__main__": | ||
ecal_core.initialize(sys.argv, "CapnProto Message Publisher") | ||
|
||
# Create a CapnProto Publisher that publishes on the topic "sensor_imu" | ||
pub = CapnPublisher("sensor_imu", msgs.Imu) | ||
|
||
# Infinite loop (using ecal_core.ok() will enable us to gracefully shutdown | ||
# the process from another application) | ||
while ecal_core.ok(): | ||
# Create a capnproto Imu message, populate it with random values and publish it to the topic | ||
imu_msg = msgs.Imu.new_message() | ||
imu_msg.timestamp = time.monotonic_ns() | ||
imu_msg.accel = [round(random.uniform(2.0, 20.0), 2), round(random.uniform(2.0, 20.0), 2), round(random.uniform(2.0, 20.0), 2)] | ||
imu_msg.gyro = [round(random.uniform(0.0, 4.3), 2), round(random.uniform(0.0, 4.3), 2), round(random.uniform(0.0, 4.3), 2)] | ||
|
||
print("Sending: {}".format(imu_msg)) | ||
pub.send(imu_msg) | ||
|
||
# Sleep 500 ms | ||
time.sleep(0.5) | ||
|
||
# finalize eCAL API | ||
ecal_core.finalize() |
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,28 @@ | ||
import sys | ||
import time | ||
import capnp | ||
import messages_capnp as msgs | ||
import ecal.core.core as ecal_core | ||
from ecal.core.subscriber import CapnSubscriber | ||
|
||
# callback function for the subscriber | ||
def callback(topic_name, msg, time): | ||
# print the received message | ||
print(msg) | ||
|
||
if __name__ == "__main__": | ||
# Initialize eCAL | ||
ecal_core.initialize(sys.argv, "CapnProto Message Subscriber") | ||
|
||
# Create a subscriber that listenes on the "sensor_imu" topic | ||
sub = CapnSubscriber("sensor_imu", msgs.Imu) | ||
|
||
# Set the callback | ||
sub.set_callback(callback) | ||
|
||
# infinite loop that keeps the script alive | ||
while ecal_core.ok(): | ||
time.sleep(0.5) | ||
|
||
# finalize eCAL API | ||
ecal_core.finalize() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are now two ProtoSubscriber classes. Can you please remove one of them?