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

better klang #1

Merged
merged 5 commits into from
Sep 24, 2024
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
55 changes: 55 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Contributing to Klang

Thank you for your interest in contributing to Klang! We welcome contributions from everyone. This document provides guidelines and instructions for contributing to the project.

## Development Setup

1. Ensure you have Rust and Cargo installed. If not, follow the instructions [here](https://www.rust-lang.org/tools/install).

2. Build the project:

```
cargo build
```

3. Run the tests:

```
cargo test
```

## Development Workflow

1. Create a new branch for your feature or bug fix:

```
git checkout -b feature-or-fix-name
```

2. Make your changes and commit them with a clear commit message.

3. Push your changes to your fork:

```
git push origin feature-or-fix-name
```

4. Open a pull request against the main repository.

## Coding Standards

- Follow the Rust style guide. You can use `rustfmt` to automatically format your code:

```
cargo fmt
```

- Run `clippy` to catch common mistakes and improve your code:

```
cargo clippy
```

## Running Klang

To run the Klang interpreter:
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@
# klang

`klang` is a domain-specific language (DSL) for programming robots. It is used to program robots running the K-Scale operating system.

## Running the Parser

To run the parser on the example file, use the following command:

```bash
cargo run -- examples/clean_up_cans.k
```
69 changes: 29 additions & 40 deletions examples/clean_up_cans.k
Original file line number Diff line number Diff line change
@@ -1,51 +1,40 @@
# This program is designed to get a robot to clean up soda cans.
from robot import move, ppo_standing, nn

action <Find {item}> {
notes {
prefer [Move quickly]
avoid [Bumping into other objects]
avoid [Moving too hastily]
avoid [Moving slowly or staying in the same place for a long time]
}

outcomes {
success [Found {item}]
failure [Haven't moved in a while]
retry [Actively looking for {item}]
}
fn pick_up_apple_manual() : "Pick up an apple manually" {
x = 30deg;
y = 30deg;
*move(limb="left_arm", joint=2, pos=x + y);
}

action <Pick up {item}> {
outcomes {
success [Holding {item}]
failure [Knocked over {item}]
retry [Not holding {item}]
}
fn pick_up_apple() : "Pick up an apple" {
*nn(
"Pick up the apple",
pos=["Move hand close to the apple"],
neg=["Move quickly"],
on_failure=pick_up_apple_manual,
);
}

action <Put {item} into {container}> {
outcomes {
success [{item} is inside {container} and we are not holding it]
failure [Dropped {item} outside the {container}]
retry [Still holding {item}]
fn random_arm_movement() : "Move the arm in a random manner" {
for i : [1, 2, 3] {
*(
move(limb="right_arm", joint=2, pos=30deg + i * 0.1rad),
move(limb="right_arm", joint=3, pos=30deg + i * 0.5rad),
);
}
}

action <Empty the soda can into the sink> {
outcomes {
success [Successfully emptied the soda can into the sink]
failure [Spilled soda outside the sink]
retry [There is still soda in the can]
counter = 0;
flag = true;
while counter < 5 {
*(
move("right_arm", joint=2, pos=30deg + (flag ? 0.1rad : -0.1rad)),
move("right_arm", joint=3, pos=30deg + (flag ? 0.5rad : -0.5rad)),
);
flag = !flag;
counter += 1;
}
}

loop {
<Find a soda can>
<Pick up the soda can>
<Find the sink>
<Empty the soda can into the sink>
<Find the recycling bin>
<Put the soda can into the recycling bin>
} until {
[No more soda cans]
fn main() {
*(pick_up_apple(), ppo_standing(), random_arm_movement());
}
13 changes: 11 additions & 2 deletions klang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ edition = "2021"

[dependencies]

pest = "2.6"
pest_derive = "2.6"
pest = "2.5"
pest_derive = "2.5"
thiserror = "1.0"
lazy_static = "1.4.0"

[[bin]]

name = "klang"
path = "src/main.rs"

[[test]]
name = "integration_test"
path = "src/test.rs"

[lib]
name = "klang"
path = "src/lib.rs"
Loading
Loading