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

Individual wheel speeds #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
build
build
binaries
.idea
cmake-build-debug
52 changes: 39 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# `iRobot® Create® 3 robot ROS2 server and client library`

Holds a ROS2 C++ server for communicating with the iRobot® Create® 3 robot and an associated client library for communicating
with said server. The server can then be packaged into a Docker image, allowing the client to remain free of ROS2 dependencies.
Holds a ROS2 C++ server for communicating with the iRobot® Create® 3 robot and an associated client library for
communicating
with said server. The server can then be packaged into a Docker image, allowing the client to remain free of ROS2
dependencies.

The RPC between client and server is handled by Cap'n Proto.

## Dependencies

### Common
- C++ Compiler with C++17 support
- CMake >3.5

- C++ Compiler with C++17 support
- CMake >3.5

### Server
- ROS 2

- ROS 2

## Building

Expand All @@ -22,16 +26,36 @@ cmake -Bbuild
cmake --build build
```

### Building the Client with Docker

When building with Docker, run `build_docker.sh`. This will build the project using a docker container, where all
dependencies are installed and produce a .deb file, for later installation.

This will also 'cross-compile' the project for the arm64 architecture, which is the architecture of the KIPR Wombat.

The built binary will be placed in the `binaries` directory.

### Building the Server with Docker

The [create3_docker](https://github.com/kipr/create3_docker) repository contains the instructions for building the server
into a wombat compatible docker image.

#### Customizing the Docker Build

If the build is needed for a different platform, the `Dockerfile` can be modified to use a different base image.
Right now it uses `arm64v8/python:3.11.2-bullseye`, which is a arm64 image with python 3.11.2 installed.

### Build Options

- `-Dserver=ON|OFF` (Default: `ON`) - Controls whether the server is built.
- `-Dclient=ON|OFF` (Default: `ON`) - Controls whether the client library is built.
- `-Dcmder=ON|OFF` (Default: `ON`) - Controls whether the create3 CLI is built.
- `-Dtests=ON|OFF` (Default: `ON`) - Controls whether tests are generated that can be run with `ctest`.
- `-Dserver=ON|OFF` (Default: `ON`) - Controls whether the server is built.
- `-Dclient=ON|OFF` (Default: `ON`) - Controls whether the client library is built.
- `-Dcmder=ON|OFF` (Default: `ON`) - Controls whether the create3 CLI is built.
- `-Dtests=ON|OFF` (Default: `ON`) - Controls whether tests are generated that can be run with `ctest`.

For most scenarios:
- Use `-Dserver=OFF` for the client (eg. dev machine)
- Use `-Dclient=OFF -Dcmder=OFF` for the server (eg. Docker image)

- Use `-Dserver=OFF` for the client (eg. dev machine)
- Use `-Dclient=OFF -Dcmder=OFF` for the server (eg. Docker image)

Use `--parallel <n>` to build with multiple threads in `cmake --build build` step.

Expand All @@ -40,15 +64,17 @@ Use `--parallel <n>` to build with multiple threads in `cmake --build build` ste
To configure cmake for a windows build, replace `cmake -Bbuild` with:

```

cmake -Bbuild -GNinja -Dserver=OFF

```

The reminaing instructions are the same.


## Examples

Examples are configured to connect to a KIPR Wombat running the docker instance of the server. Users may want to change the IP address in the examples to match their own setup.
Examples are configured to connect to a KIPR Wombat running the docker instance of the server. Users may want to change
the IP address in the examples to match their own setup.

Examples may be run after building by executing:

Expand Down
13 changes: 13 additions & 0 deletions build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
IMAGE_NAME="create3-builder:python-3.11.2"

if [[ "$(docker images -q ${IMAGE_NAME} 2> /dev/null)" == "" ]]; then
docker build -t ${IMAGE_NAME} -f docker/Dockerfile .
fi

docker run --cpus="$(nproc)" \
-v "$(pwd)":/app \
${IMAGE_NAME} bash -c "bash docker/build.sh $*"

docker stop $(docker ps -a --filter "ancestor=${IMAGE_NAME}" -q)
docker rm $(docker ps -a --filter "ancestor=${IMAGE_NAME}" -q)
27 changes: 27 additions & 0 deletions client/examples/08_move_wheels.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <kipr/create3/client/client.h>
#include <stdio.h>

int main()
{
printf("Connecting to Create3 robot...\n");

create3_connect_manual("192.168.125.1", 50051);

printf("Connected!\n");


printf("Moving left wheel forward at 0.5 m/s for 1 second...\n");

// Move left wheel forward at 0.5 m/s for 1 second
create3_set_wheels(0.5, 0);

// Wait for 1 second
usleep(1000000);

// Stop
create3_set_wheels(0.0, 0.0);

printf("Done!\n");

return 0;
}
11 changes: 11 additions & 0 deletions client/include/kipr/create3/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,17 @@ void create3_velocity_set_components(const double linear_x, const double angular
*/
void create3_wait();

/**
* @brief Set the wheels of the iRobot Create 3.
* @details This will set the left and right wheels of the iRobot Create 3 to the given speeds in m/s.
*
* @param left The speed of the left wheel in meters per second.
* @param right The speed of the right wheel in meters per second.
*
* @example `create3_set_wheels(1.0, 1.0); // Set both wheels to 1 m/s.`
*/
void create3_set_wheels(const double left, const double right);

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions client/src/kipr/create3/client/client_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,11 @@ void create3_wait()

global_client->wait();
}

void create3_set_wheels(const double left_wheel_speed, const double right_wheel_speed)
{
const double creat3_wheel_distance= 0.235;
double linear_x = (left_wheel_speed + right_wheel_speed) / 2;
double angular_z = (right_wheel_speed - left_wheel_speed) / creat3_wheel_distance;
create3_velocity_set_components(linear_x, angular_z);
}
12 changes: 12 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM arm64v8/python:3.11.2-bullseye
LABEL authors="Tobias Madlberger"

RUN apt-get update && apt-get install -y git wget libx11-dev zlib1g-dev cmake swig ninja-build \
build-essential libc-dev libasio-dev libc6-dev libpthread-stubs0-dev libssl-dev \
libzbar-dev libopencv-dev libjpeg-dev python-dev doxygen yasm git build-essential \
cmake libzbar-dev libopencv-dev libjpeg-dev python-dev doxygen swig yasm \
libcurl4-openssl-dev

WORKDIR /app
ENV CMAKE_GENERATOR=Ninja
ENV CMAKE_BUILD_PARALLEL_LEVEL=12
9 changes: 9 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# This file should not be run manually, it is used by the Dockerfile

cmake -Bbuild "$@" -Dserver=OFF
cd build || exit 1
ninja
cpack
mkdir -p "/app/binaries"
mv create3-0.1.0-Linux.deb /app/binaries