Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Implement simple quadcopter control. #22

Open
wants to merge 62 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
662071a
Allow control of Zubax Myxa ESCs via Cyphal.
inusha47 Jan 25, 2024
55c9502
Restore sensible repository content by diff-ing to main.
aentinger Mar 11, 2024
fc3fdc5
Subscribe to IMU data.
aentinger Mar 11, 2024
58daa2f
Update Node.cpp
inusha47 Jan 25, 2024
774563c
Node.cpp
inusha47 Jan 25, 2024
317662d
Node.cpp
inusha47 Jan 25, 2024
e168f6d
Update Node.h
inusha47 Jan 25, 2024
56def38
Node.cpp
inusha47 Jan 25, 2024
6052804
Update Node.cpp
inusha47 Jan 26, 2024
2be7365
a
inusha47 Jan 26, 2024
6af765c
code
inusha47 Jan 26, 2024
94a14a2
Update Node.cpp
inusha47 Jan 27, 2024
c68bfa8
Update Node.h
inusha47 Jan 27, 2024
8e0c650
up
inusha47 Jan 27, 2024
c449ab8
uavcan -> zubax
inusha47 Jan 27, 2024
f14e562
Vector 4 -> Vector31.1.0
inusha47 Jan 27, 2024
6baa1fc
31.1.0 - > 31
inusha47 Jan 27, 2024
eb47121
Fix all those bugs in the implementation.
aentinger Jan 29, 2024
767bdd4
vector 31 -> 4
inusha47 Jan 31, 2024
8266824
Vector 4_1_0
inusha47 Jan 31, 2024
9e879a6
Update README.md
inusha47 Jan 31, 2024
c370e0c
Update README.md
inusha47 Jan 31, 2024
423af1d
test text
inusha47 Jan 31, 2024
57a5f75
Update README.md
inusha47 Jan 31, 2024
bb39d60
Update Node.cpp
inusha47 Jan 31, 2024
1ea2829
Update Node.cpp
inusha47 Jan 31, 2024
7007d67
pub - > sub
inusha47 Jan 31, 2024
9affb3e
[] remove
inusha47 Jan 31, 2024
5e605bc
Update Node.cpp
inusha47 Jan 31, 2024
caedff1
Update Node.h
inusha47 Jan 31, 2024
5f10bbb
Update Node.h
inusha47 Jan 31, 2024
0f56204
Update Node.h
inusha47 Jan 31, 2024
c21858b
Update Node.h
inusha47 Jan 31, 2024
f528268
code rev
inusha47 Jan 31, 2024
f2f0615
re
inusha47 Jan 31, 2024
58c00a4
Update viper-quad.py
inusha47 Jan 31, 2024
c09c915
Update Node.cpp
inusha47 Jan 31, 2024
521a3be
Update Node.cpp
inusha47 Jan 31, 2024
7faf400
Update viper-quad.py
inusha47 Jan 31, 2024
cda1864
Update viper-quad.py
inusha47 Jan 31, 2024
5cbe6ee
Update viper-quad.py
inusha47 Jan 31, 2024
60ff99e
Update Node.cpp
inusha47 Jan 31, 2024
c3a5a2b
can bitrate
inusha47 Jan 31, 2024
48582eb
Update Node.cpp
inusha47 Jan 31, 2024
29c7c9f
Speed increase // 100 ->500
inusha47 Feb 1, 2024
0775491
Update viper-quad.py
inusha47 Feb 1, 2024
16c6c30
Update Node.cpp
inusha47 Feb 1, 2024
cff4a40
Update Node.cpp
inusha47 Feb 1, 2024
0fdd495
Update Node.cpp
inusha47 Feb 1, 2024
a50f14e
Update Node.cpp
inusha47 Feb 1, 2024
82292d3
Update Node.cpp
inusha47 Feb 1, 2024
af43afe
Update Node.cpp
inusha47 Feb 1, 2024
cf45e84
Update Node.cpp
inusha47 Feb 8, 2024
107bd3e
Update Node.cpp
inusha47 Feb 8, 2024
7cc8c1b
Update Node.cpp
inusha47 Feb 8, 2024
6879ea9
viper imu
inusha47 Feb 22, 2024
cdbb802
Merge branch '107-systems:main' into main
inusha47 Mar 28, 2024
bcbd7fc
Modification on viper.py to display imu data
inusha47 Apr 11, 2024
b6da5d7
Remove additional code on imu data display
inusha47 Apr 11, 2024
a8d884f
Mimimal test for minimal control.
inusha47 May 14, 2024
21a1d09
Launch file IMU fetch
inusha47 Jun 2, 2024
31b5d55
4 motor control with IMU
inusha47 Jun 3, 2024
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
34 changes: 34 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/

**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.next
**/.cache
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
**/build
**/dist
LICENSE
README.md
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ endif()
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
##########################################################################
add_subdirectory(external/107-Arduino-Cyphal)
Expand All @@ -29,7 +30,7 @@ add_executable(${VIPER_TARGET}
target_link_libraries(${VIPER_TARGET} cyphal++ socketcan mp-units)
#######################################################################################
target_compile_features(${VIPER_TARGET} PRIVATE cxx_std_20)
ament_target_dependencies(${VIPER_TARGET} rclcpp std_msgs geometry_msgs)
ament_target_dependencies(${VIPER_TARGET} rclcpp std_msgs sensor_msgs geometry_msgs)
#######################################################################################
install(TARGETS ${VIPER_TARGET} DESTINATION lib/${PROJECT_NAME})
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})
Expand Down
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# syntax=docker/dockerfile:1

# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/

# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7

ARG NODE_VERSION=Viper

FROM node:${NODE_VERSION}-alpine

# Use production node environment by default.
ENV NODE_ENV production


WORKDIR /usr/src/app

# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /root/.npm to speed up subsequent builds.
# Leverage a bind mounts to package.json and package-lock.json to avoid having to copy them into
# into this layer.
RUN --mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=package-lock.json,target=package-lock.json \
--mount=type=cache,target=/root/.npm \
npm ci --omit=dev

# Run the application as a non-root user.
USER node

# Copy the rest of the source files into the image.
COPY . .

# Expose the port that the application listens on.
EXPOSE 8088

# Run the application.
CMD ros2 launch viper viper-quad.py
22 changes: 22 additions & 0 deletions README.Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Building and running your application

When you're ready, start your application by running:
`docker compose up --build`.

Your application will be available at http://localhost:8088.

### Deploying your application to the cloud

First, build your image, e.g.: `docker build -t myapp .`.
If your cloud uses a different CPU architecture than your development
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
you'll want to build the image for that platform, e.g.:
`docker build --platform=linux/amd64 -t myapp .`.

Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.

Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/)
docs for more detail on building and pushing.

### References
* [Docker's Node.js guide](https://docs.docker.com/language/nodejs/)
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ Generic ROS based drone flight stack for the [Pika Spark](https://pika-spark.io/
#### How-to-build
Note: Don't forget to install the [dependencies](https://github.com/107-systems/viper#install-dependencies) (see at the end of this file).
```bash
cd $COLCON_WS/src
cd my_colcon_ws/src
git clone --recursive https://github.com/107-systems/viper
cd $COLCON_WS
cd my_colcon_ws
cd Documents/DEV/src
git clone --recursive https://github.com/inusha47/viper-WOP.git
cd Documents/DEV
source /opt/ros/humble/setup.bash
colcon build --packages-select viper
```

#### How-to-run
```bash
cd $COLCON_WS
cd my_colcon_ws
. install/setup.bash
ros2 launch viper viper-quad.py
```
Expand Down
51 changes: 51 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Docker compose reference guide at
# https://docs.docker.com/go/compose-spec-reference/

# Here the instructions define your application as a service called "server".
# This service is built from the Dockerfile in the current directory.
# You can add other services your application may depend on here, such as a
# database or a cache. For examples, see the Awesome Compose repository:
# https://github.com/docker/awesome-compose
services:
server:
build:
context: .
environment:
NODE_ENV: production
ports:
- 8088:8088

# The commented out section below is an example of how to define a PostgreSQL
# database that your application can use. `depends_on` tells Docker Compose to
# start the database before your application. The `db-data` volume persists the
# database data between container restarts. The `db-password` secret is used
# to set the database password. You must create `db/password.txt` and add
# a password of your choosing to it before running `docker-compose up`.
# depends_on:
# db:
# condition: service_healthy
# db:
# image: postgres
# restart: always
# user: postgres
# secrets:
# - db-password
# volumes:
# - db-data:/var/lib/postgresql/data
# environment:
# - POSTGRES_DB=example
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
# expose:
# - 5432
# healthcheck:
# test: [ "CMD", "pg_isready" ]
# interval: 10s
# timeout: 5s
# retries: 5
# volumes:
# db-data:
# secrets:
# db-password:
# file: db/password.txt

31 changes: 29 additions & 2 deletions include/viper/Node.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* Copyright (c) 2023 LXRobotics GmbH.
* Author: Alexander Entinger <[email protected]>
* Contributors: https://github.com/107-systems/viper/graphs/contributors.
Expand All @@ -16,6 +16,7 @@

#include <std_msgs/msg/float32.hpp>

#include <sensor_msgs/msg/imu.hpp>
#include <geometry_msgs/msg/twist.hpp>

#include <cyphal++/cyphal++.h>
Expand Down Expand Up @@ -76,9 +77,35 @@ class Node : public rclcpp::Node
quantity<rad/s> _target_angular_velocity_x, _target_angular_velocity_y, _target_angular_velocity_z;
void init_teleop_sub();

rclcpp::QoS _imu_qos_profile;
rclcpp::SubscriptionOptions _imu_sub_options;
rclcpp::Subscription<sensor_msgs::msg::Imu>::SharedPtr _imu_sub;
sensor_msgs::msg::Imu _imu_data;
void init_imu_sub();


static uint16_t constexpr CYPHAL_DEMO_PORT_ID = 1234;
cyphal::Publisher<uavcan::primitive::scalar::Integer8_1_0> _cyphal_demo_pub;

static uint16_t constexpr SETPOINT_VELOCITY_ID_1 = 113;
cyphal::Publisher<zubax::primitive::real16::Vector4_1_0> _setpoint_velocity_pub_1;

static uint16_t constexpr SETPOINT_VELOCITY_ID_2 = 114;
cyphal::Publisher<zubax::primitive::real16::Vector4_1_0> _setpoint_velocity_pub_2;


static uint16_t constexpr SETPOINT_VELOCITY_ID_3 = 115;
cyphal::Publisher<zubax::primitive::real16::Vector4_1_0> _setpoint_velocity_pub_3;

static uint16_t constexpr SETPOINT_VELOCITY_ID_4 = 116;
cyphal::Publisher<zubax::primitive::real16::Vector4_1_0> _setpoint_velocity_pub_4;







static std::chrono::milliseconds constexpr CTRL_LOOP_RATE{10};
rclcpp::TimerBase::SharedPtr _ctrl_loop_timer;
void ctrl_loop();
Expand All @@ -88,4 +115,4 @@ class Node : public rclcpp::Node
* NAMESPACE
**************************************************************************************/

} /* viper */
} /* viper */
44 changes: 27 additions & 17 deletions launch/viper-quad.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
from launch import LaunchDescription
from launch.actions import ExecuteProcess
from launch_ros.actions import Node

def generate_launch_description():
return LaunchDescription([
Node(
package='viper',
executable='viper_node',
name='viper',
namespace='viper',
output='screen',
emulate_tty=True,
parameters=[
{'can_iface' : 'can0'},
{'can_node_id' : 100},
{'teleop_topic': 'cmd_vel'},
{'teleop_topic_deadline_ms': 100},
{'teleop_topic_liveliness_lease_duration': 1000},
]
)
])
return LaunchDescription([
Node(
package='viper',
executable='viper_node',
name='viper',
namespace='viper',
output='screen',
emulate_tty=True,
parameters=[
{'can_iface': 'can0'},
{'can_node_id': 100},
{'teleop_topic': 'cmd_vel'},
{'teleop_topic_deadline_ms': 100},
{'teleop_topic_liveliness_lease_duration': 1000},
{'imu_topic': '/imu'},
{'imu_topic_deadline_ms': 100},
{'imu_topic_liveliness_lease_duration': 1000},
]
),
ExecuteProcess(
cmd=['ros2', 'topic', 'echo', 'imu'],
output='screen',
additional_env={'period': '0.1', 'msg': '[100, 100, 100, 100]', 'topic': '113:zubax.primitive.real16.Vector4'}
),

])
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<depend>rclcpp</depend>
<depend>std_msgs</depend>
<depend>sensor_msgs</depend>
<depend>geometry_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
Expand Down
Loading