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

protobuf plumbing. #9

Merged
merged 10 commits into from
Oct 25, 2022
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
8 changes: 4 additions & 4 deletions .github/workflows/ci_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install pip latest
run: pip3 install -U pip
- name: Install dependencies
working-directory: py
run: pip3 install -e .[dev]
- name: Run Tests
working-directory: py
run: pytest -v tests/ --mypy
run: pytest -v py/tests/ --mypy
11 changes: 9 additions & 2 deletions protos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
farm_ng_add_protobufs(amiga_brain_api_proto_defs
NAMESPACE amiga_brain_api
INCLUDE_DIRS
${Sophus_PROTO_DIR}
PROTO_FILES
farm_ng/oak/oak.proto
farm_ng/canbus/canbus.proto
farm_ng/controller/controller.proto
farm_ng/state_estimator/state_estimator.proto
farm_ng/oak/oak.proto
farm_ng/canbus/canbus.proto
DEPENDENCIES
Sophus::sophus_linalg_proto_defs
Sophus::sophus_lie_proto_defs
)
99 changes: 99 additions & 0 deletions protos/farm_ng/controller/controller.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
syntax = "proto3";

import "sophus/linalg.proto";
import "sophus/lie.proto";

package farm_ng.controller.proto;

// import "farm_ng/amiga/temp_imports.proto";

service ControllerService {
// called from the gui
// Reports progress back to gui until it achieves the goal
// TODO how to cancel the request (possibly by cancelling the response stream? or using the input as a stream)
rpc moveToGoalPose(MoveToGoalPoseRequest)
returns (stream MoveToGoalPoseResult) {}

// Next week
// rpc followTrajectory(stream FollowTrajectorRequest)
// returns (stream FollowTrajectorResult) {}

rpc getServiceState(GetServiceStateRequest) returns (GetServiceStateResult) {}
rpc startService(StartServiceRequest) returns (StartServiceResult) {}
rpc stopService(StopServiceRequest) returns (StopServiceResult) {}
}


message MoveToGoalPoseRequest {
enum Command {
UNKNOWN=0;
CANCEL=1;
UPDATE_GOAL=2;
}
Command command = 1;
sophus.proto.Se3F64 world_pose_goal = 2;


// max speed to achieve the goal
double max_speed = 3;
// max angular rate to achieve the goal
double max_angular_rate = 4;
}

message MoveToGoalPoseResult {
sophus.proto.Se3F64 world_pose_goal = 1;
sophus.proto.Se3F64 world_pose_robot = 2;
// estimated time of arrival at the robot
double eta = 3;
enum State {
UNKNOWN=0;
FAILED = 1;
IN_PROGRESS = 2;
ACHIEVED = 3;
}
State state = 4;
ReplyStatus status = 5;

}

// message MoveToGoalPoseResults {
// repeated MoveToGoalPoseResult results = 1;
// }


////////////////////////////////////////////////
// From here down should be imported from elsewhere
// Need to understand desired protos architecture
////////////////////////////////////////////////

// Generic service protos
enum ReplyStatus {
OK = 0;
FAILED = 1;
}
enum ServiceState {
STOPPED = 0;
RUNNING = 1;
}
message GetServiceStateRequest {
string message = 1;
}
message GetServiceStateResult {
string state_name = 1;
ServiceState state = 2;
ReplyStatus status = 3;
}
message StartServiceRequest {
string message = 1;
}
message StartServiceResult {
string message = 1;
ReplyStatus status = 2;
}
message StopServiceRequest {
string message = 1;
}
message StopServiceResult {
string message = 1;
ReplyStatus status = 2;
}
114 changes: 114 additions & 0 deletions protos/farm_ng/state_estimator/state_estimator.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
syntax = "proto3";

package farm_ng.state_estimator.proto;

// import "farm_ng/amiga/temp_imports.proto";

service StateEstimator {
rpc robotDynamics(RobotDynamicsRequest)
returns (stream RobotDynamicsResult) {}

rpc robotCalibrationResult(RobotCalibrationRequest)
returns (stream RobotCalibrationResult) {}

rpc getServiceState(GetServiceStateRequest) returns (GetServiceStateResult) {}
rpc startService(StartServiceRequest) returns (StartServiceResult) {}
rpc stopService(StopServiceRequest) returns (StopServiceResult) {}
}

message RobotDynamicsRequest {
string device = 1;
}

message RobotDynamicsResult {
// Timestamp from farm-ng-core
// SE3d types from Sophus
Timestamp stamp = 1; // this contains which clock
SE3d world_pose_robot = 2;
// Rate of the robot in the robot's frame
SE3dLog robot_rate = 3;
}

message RobotCalibrationRequest {
Timestamp stamp = 1; // this contains which clock
// poses has
// robot -> oak0/right
// robot -> oak1/right
// robot -> wheel/0xA
// robot -> wheel/0xB
// robot -> wheel/0xC
// robot -> wheel/0xD
repeated NamedPose3d poses = 2;
repeated NamedWheel wheels = 3;
}

message RobotCalibrationResult {
// Timestamp from farm-ng-core
// SE3d types from Sophus
Timestamp stamp = 1; // this contains which clock
SE3d world_pose_robot = 2;
// Rate of the robot in the robot's frame
SE3dLog robot_rate = 3;
}

message NamedWheel {
// e.g. wheel/0xA
string name = 1;
double radius = 2;
}

////////////////////////////////////////////////
// From here down should be imported from elsewhere
// Need to understand desired protos architecture
////////////////////////////////////////////////

// Geometry/etc. protos
message SE3d {
string foo = 1;
}
message SE3dLog {
SE3d foo = 1;
}
message NamedPose3d {
string frame_a = 1;
string frame_b = 2;
SE3d a_pose_b = 3;
}
message Timestamp {
string clock_name = 1;
double seconds = 2;
string clock_type = 3;
}


// Generic service protos
enum ReplyStatus {
OK = 0;
FAILED = 1;
}
enum ServiceState {
STOPPED = 0;
RUNNING = 1;
}
message GetServiceStateRequest {
string message = 1;
}
message GetServiceStateResult {
string state_name = 1;
ServiceState state = 2;
ReplyStatus status = 3;
}
message StartServiceRequest {
string message = 1;
}
message StartServiceResult {
string message = 1;
ReplyStatus status = 2;
}
message StopServiceRequest {
string message = 1;
}
message StopServiceResult {
string message = 1;
ReplyStatus status = 2;
}
6 changes: 6 additions & 0 deletions py/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*venv*
*.egg*
*build*
*pycache*
*pb2*
*proto*
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions py/tests/test_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from farm_ng.controller import controller_pb2


class TestControllerPb2:
def test_smoke(self) -> None:
request = controller_pb2.MoveToGoalPoseRequest()
print(request)
9 changes: 9 additions & 0 deletions py/tests/test_package.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import farm_ng
from farm_ng.canbus import canbus_pb2
from farm_ng.controller import controller_pb2
from farm_ng.oak import oak_pb2
from farm_ng.state_estimator import state_estimator_pb2


def test_import() -> None:
assert farm_ng.core is not None
assert farm_ng.core.__version__ is not None
assert farm_ng.oak is not None
assert farm_ng.oak.__version__ is not None

assert canbus_pb2 is not None
assert controller_pb2 is not None
assert oak_pb2 is not None
assert state_estimator_pb2 is not None
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ skip-magic-trailing-comma = true

[tool.isort]
profile = "black"

[build-system]
requires = [
"setuptools",
"farm-ng-core @ git+https://github.com/farm-ng/farm-ng-core@main"
]
build-backend = "setuptools.build_meta"
38 changes: 31 additions & 7 deletions py/setup.cfg → setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ name = farm_ng_amiga
version = 0.0.1-dev
description = Amiga development kit for third party hardware or software extensions.
long_description = file: README.md
author = Farm-ng Inc.
author = farm-ng Inc.
author_email = info@farm-ng.com
url = https://github.com/farm-ng/amiga-dev-kit
download_url = https://github.com/farm-ng/amiga-dev-kit
keywords = robotics, open-source
url = https://github.com/farm-ng/amiga-brain-api
download_url = https://github.com/farm-ng/amiga-brain-api
keywords = robotics
license_files = LICENSE
classifiers =
Development Status :: 4 - Beta
Expand All @@ -23,23 +23,29 @@ python_requires = >=3.6
setup_requires =
wheel
grpcio-tools
farm_ng_core @ git+https://github.com/farm-ng/farm-ng-core@main
sophus @ git+https://github.com/strasdat/Sophus@23.04-beta

install_requires =
protobuf
grpcio
farm_ng_core @ git+https://github.com/farm-ng/farm-ng-core@main#subdirectory=py

farm_ng_core @ git+https://github.com/farm-ng/farm-ng-core@main
sophus @ git+https://github.com/strasdat/Sophus@23.04-beta
tests_require =
pytest
pytest-runner
pytest-asyncio
pytest-mypy
test_suite = tests

package_dir =
= py
packages =
farm_ng
farm_ng.canbus
farm_ng.oak
farm_ng.controller
farm_ng.state_estimator

[options.extras_require]
dev =
Expand All @@ -49,7 +55,25 @@ dev =
pylint-protobuf==0.20.2
pre-commit==2.20.0
mypy==0.971
types-protobuf
pylint
grpcio-tools
mypy-protobuf
pylint-protobuf==0.20.2

[mypy]
files = farm_ng, tests, examples
files = py/sophus, py/tests, py/examples
ignore_missing_imports = True

[options.package_data]
farm_ng.controller =
*.proto

farm_ng.oak =
*.proto

farm_ng.canbus =
*.proto

farm_ng.state_estimator =
*.proto
Loading