Skip to content

Commit

Permalink
WIP: Update to the merge of vulp into upkie
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-caron committed Jul 5, 2024
1 parent 1ea351c commit d2a22d4
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 104 deletions.
8 changes: 2 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ add_default_repositories()
load("@upkie//tools/workspace:default.bzl", add_upkie_repositories = "add_default_repositories")
add_upkie_repositories()

# @vulp was added by add_default_repositories
load("@vulp//tools/workspace:default.bzl", add_vulp_repositories = "add_default_repositories")
add_vulp_repositories()

# @palimpsest was added by add_vulp_repositories
# @palimpsest was added by add_upkie_repositories
load("@palimpsest//tools/workspace:default.bzl", add_palimpsest_repositories = "add_default_repositories")
add_palimpsest_repositories()

# @pi3hat was added by add_vulp_repositories
# @pi3hat was added by add_upkie_repositories
load("@pi3hat//tools/workspace:default.bzl", add_pi3hat_repositories = "add_default_repositories")
add_pi3hat_repositories()

Expand Down
44 changes: 21 additions & 23 deletions spines/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ cc_binary(
"@upkie_description",
],
deps = [
"@upkie//upkie/config:layout",
"@upkie//upkie/observers",
"@upkie//upkie/utils:datetime_now_string",
"@upkie//upkie:version",
"@vulp//vulp/actuation:bullet_interface",
"@vulp//vulp/observation",
"@vulp//vulp/observation/sources",
"@vulp//vulp/spine",
"@upkie//upkie/cpp/actuation:bullet_interface",
"@upkie//upkie/cpp/config:layout",
"@upkie//upkie/cpp/observers",
"@upkie//upkie/cpp/sensors",
"@upkie//upkie/cpp/spine",
"@upkie//upkie/cpp/utils:datetime_now_string",
"@upkie//upkie/cpp:version",
],
)

Expand All @@ -28,13 +27,12 @@ cc_binary(
"mock_spine.cpp",
],
deps = [
"@upkie//upkie/config:layout",
"@upkie//upkie/observers",
"@upkie//upkie:version",
"@vulp//vulp/actuation:mock_interface",
"@vulp//vulp/observation",
"@vulp//vulp/observation/sources",
"@vulp//vulp/spine",
"@upkie//upkie/cpp/actuation:mock_interface",
"@upkie//upkie/cpp/config:layout",
"@upkie//upkie/cpp/observers",
"@upkie//upkie/cpp/sensors",
"@upkie//upkie/cpp/spine",
"@upkie//upkie/cpp:version",
] + select({
"//:pi64_config": [
"@org_llvm_libcxx//:libcxx",
Expand All @@ -50,15 +48,15 @@ cc_binary(
"pi3hat_spine.cpp",
],
deps = [
"@upkie//upkie/config:layout",
"@upkie//upkie/observers",
"@upkie//upkie/utils:datetime_now_string",
"@upkie//upkie:version",
"@vulp//vulp/observation",
"@vulp//vulp/observation/sources",
"@vulp//vulp/spine",
"@upkie//upkie/cpp/config:layout",
"@upkie//upkie/cpp/observation",
"@upkie//upkie/cpp/observation/sources",
"@upkie//upkie/cpp/observers",
"@upkie//upkie/cpp/spine",
"@upkie//upkie/cpp/utils:datetime_now_string",
"@upkie//upkie/cpp:version",
] + select({
"//:pi64_config": ["@vulp//vulp/actuation:pi3hat_interface"],
"//:pi64_config": ["@upkie//upkie/cpp/actuation:pi3hat_interface"],
"//conditions:default": [],
}),
target_compatible_with = select({
Expand Down
51 changes: 24 additions & 27 deletions spines/bullet_spine.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: Apache-2.0

#include <vulp/actuation/BulletInterface.h>
#include <vulp/observation/ObserverPipeline.h>
#include <vulp/observation/sources/CpuTemperature.h>

#ifndef __APPLE__
#include <vulp/observation/sources/Joystick.h>
#endif

#include <vulp/spine/Spine.h>
#include <upkie/actuation/BulletInterface.h>
#include <upkie/cpp/config/layout.h>
#include <upkie/cpp/observers/FloorContact.h>
#include <upkie/cpp/observers/WheelOdometry.h>
#include <upkie/cpp/utils/datetime_now_string.h>
#include <upkie/cpp/version.h>
#include <upkie/observers/ObserverPipeline.h>
#include <upkie/sensors/CpuTemperature.h>
#include <upkie/spine/Spine.h>

#include <algorithm>
#include <cstdlib>
Expand All @@ -20,27 +20,24 @@
#include <string>
#include <vector>

#include "upkie/config/layout.h"
#include "upkie/observers/FloorContact.h"
#include "upkie/observers/WheelOdometry.h"
#include "upkie/utils/datetime_now_string.h"
#include "upkie/version.h"
#ifndef __APPLE__
#include <upkie/cpp/sensors/Joystick.h>
#endif

namespace spines::bullet {

using palimpsest::Dictionary;
using upkie::observers::FloorContact;
using upkie::observers::WheelOdometry;
using vulp::actuation::BulletInterface;
using vulp::observation::ObserverPipeline;
using vulp::observation::sources::CpuTemperature;
using upkie::BulletInterface;
using upkie::FloorContact;
using upkie::WheelOdometry;
using upkie::observers::ObserverPipeline;
using upkie::sensors::CpuTemperature;
using upkie::spine::Spine;

#ifndef __APPLE__
using vulp::observation::sources::Joystick;
using upkie::sensors::Joystick;
#endif

using vulp::spine::Spine;

//! Command-line arguments for the Bullet spine.
class CommandLineArguments {
public:
Expand Down Expand Up @@ -130,7 +127,7 @@ class CommandLineArguments {
unsigned nb_substeps = 0u;

//! Name for the shared memory file
std::string shm_name = "/vulp";
std::string shm_name = "/upkie";

//! Show Bullet GUI
bool show = false;
Expand Down Expand Up @@ -198,8 +195,8 @@ int main(const char* argv0, const CommandLineArguments& args) {
// Observation: Floor contact
FloorContact::Parameters floor_contact_params;
floor_contact_params.dt = 1.0 / args.spine_frequency;
floor_contact_params.upper_leg_joints = upkie::config::upper_leg_joints();
floor_contact_params.wheels = upkie::config::wheel_joints();
floor_contact_params.upper_leg_joints = upkie::upper_leg_joints();
floor_contact_params.wheels = upkie::wheel_joints();
auto floor_contact = std::make_shared<FloorContact>(floor_contact_params);
observation.append_observer(floor_contact);

Expand All @@ -213,7 +210,7 @@ int main(const char* argv0, const CommandLineArguments& args) {
// a "b3AlignedObjectArray reserve out-of-memory" error below.

// Simulator
const auto servo_layout = upkie::config::servo_layout();
const auto servo_layout = upkie::servo_layout();
const double base_altitude = args.space ? 0.0 : 0.6; // [m]
BulletInterface::Parameters bullet_params(Dictionary{});
bullet_params.argv0 = argv0;
Expand All @@ -229,7 +226,7 @@ int main(const char* argv0, const CommandLineArguments& args) {
// Spine
Spine::Parameters spine_params;
spine_params.frequency = args.spine_frequency;
const auto now = upkie::utils::datetime_now_string();
const auto now = upkie::datetime_now_string();
spine_params.log_path = args.log_dir + "/" + now + "_bullet_spine.mpack";
spine_params.shm_name = args.shm_name;
spdlog::info("Spine data logged to {}", spine_params.log_path);
Expand Down
43 changes: 21 additions & 22 deletions spines/mock_spine.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// SPDX-License-Identifier: Apache-2.0

#include <vulp/actuation/MockInterface.h>
#include <vulp/observation/ObserverPipeline.h>
#include <vulp/observation/sources/CpuTemperature.h>
#include <vulp/observation/sources/Joystick.h>
#include <vulp/spine/Spine.h>
#include <vulp/utils/realtime.h>
#include <upkie/cpp/actuation/MockInterface.h>
#include <upkie/cpp/config/layout.h>
#include <upkie/cpp/observers/FloorContact.h>
#include <upkie/cpp/observers/ObserverPipeline.h>
#include <upkie/cpp/observers/WheelOdometry.h>
#include <upkie/cpp/sensors/CpuTemperature.h>
#include <upkie/cpp/sensors/Joystick.h>
#include <upkie/cpp/spine/Spine.h>
#include <upkie/cpp/utils/realtime.h>
#include <upkie/cpp/version.h>

#include <algorithm>
#include <future>
Expand All @@ -16,21 +20,16 @@
#include <string>
#include <vector>

#include "upkie/config/layout.h"
#include "upkie/observers/FloorContact.h"
#include "upkie/observers/WheelOdometry.h"
#include "upkie/version.h"

namespace spines::mock {

using palimpsest::Dictionary;
using upkie::observers::FloorContact;
using upkie::observers::WheelOdometry;
using vulp::actuation::MockInterface;
using vulp::observation::ObserverPipeline;
using vulp::observation::sources::CpuTemperature;
using vulp::observation::sources::Joystick;
using vulp::spine::Spine;
using upkie::CpuTemperature;
using upkie::FloorContact;
using upkie::Joystick;
using upkie::MockInterface;
using upkie::ObserverPipeline;
using upkie::Spine;
using upkie::WheelOdometry;

//! Command-line arguments for the mock spine.
class CommandLineArguments {
Expand Down Expand Up @@ -96,7 +95,7 @@ class CommandLineArguments {
};

int main(const CommandLineArguments& args) {
if (!vulp::utils::lock_memory()) {
if (!upkie::lock_memory()) {
spdlog::error("could not lock process memory to RAM");
return -4;
}
Expand All @@ -117,8 +116,8 @@ int main(const CommandLineArguments& args) {
// Observation: Floor contact
FloorContact::Parameters floor_contact_params;
floor_contact_params.dt = 1.0 / args.spine_frequency;
floor_contact_params.upper_leg_joints = upkie::config::upper_leg_joints();
floor_contact_params.wheels = upkie::config::wheel_joints();
floor_contact_params.upper_leg_joints = upkie::upper_leg_joints();
floor_contact_params.wheels = upkie::wheel_joints();
auto floor_contact = std::make_shared<FloorContact>(floor_contact_params);
observation.append_observer(floor_contact);

Expand All @@ -129,7 +128,7 @@ int main(const CommandLineArguments& args) {
observation.append_observer(odometry);

// Mock actuators
const auto servo_layout = upkie::config::servo_layout();
const auto servo_layout = upkie::servo_layout();
const double dt = 1.0 / args.spine_frequency;
MockInterface actuation(servo_layout, dt);

Expand Down
52 changes: 28 additions & 24 deletions spines/pi3hat_spine.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// SPDX-License-Identifier: Apache-2.0

#include <unistd.h>
#include <vulp/actuation/Pi3HatInterface.h>
#include <vulp/observation/ObserverPipeline.h>
#include <vulp/observation/sources/CpuTemperature.h>
#include <vulp/observation/sources/Joystick.h>
#include <vulp/spine/Spine.h>
#include <vulp/utils/realtime.h>
#include <upkie/cpp/actuation/Pi3HatInterface.h>
#include <upkie/cpp/config/layout.h>
#include <upkie/cpp/observers/FloorContact.h>
#include <upkie/cpp/observers/ObserverPipeline.h>
#include <upkie/cpp/observers/WheelOdometry.h>
#include <upkie/cpp/sensors/CpuTemperature.h>
#include <upkie/cpp/sensors/Joystick.h>
#include <upkie/cpp/spine/Spine.h>
#include <upkie/cpp/utils/datetime_now_string.h>
#include <upkie/cpp/utils/realtime.h>
#include <upkie/cpp/version.h>

#include <algorithm>
#include <cstdlib>
Expand All @@ -19,23 +24,17 @@
#include <string>
#include <vector>

#include "upkie/config/layout.h"
#include "upkie/observers/FloorContact.h"
#include "upkie/observers/WheelOdometry.h"
#include "upkie/utils/datetime_now_string.h"
#include "upkie/version.h"

namespace spines::pi3hat {

using Pi3Hat = ::mjbots::pi3hat::Pi3Hat;
using palimpsest::Dictionary;
using upkie::observers::FloorContact;
using upkie::observers::WheelOdometry;
using vulp::actuation::Pi3HatInterface;
using vulp::observation::ObserverPipeline;
using vulp::observation::sources::CpuTemperature;
using vulp::observation::sources::Joystick;
using vulp::spine::Spine;
using upkie::CpuTemperature;
using upkie::FloorContact;
using upkie::Joystick;
using upkie::ObserverPipeline;
using upkie::Pi3HatInterface;
using upkie::Spine;
using upkie::WheelOdometry;

//! Command-line arguments for the Bullet spine.
class CommandLineArguments {
Expand Down Expand Up @@ -125,7 +124,7 @@ class CommandLineArguments {
std::string log_dir = "";

//! Name for the shared memory file.
std::string shm_name = "/vulp";
std::string shm_name = "/upkie";

//! CPUID for the spine thread (-1 to disable realtime).
int spine_cpu = 1;
Expand Down Expand Up @@ -161,7 +160,7 @@ int main(const CommandLineArguments& args) {
spdlog::error("Calibration needed: did you run `upkie_tool rezero`?");
return -3;
}
if (!vulp::utils::lock_memory()) {
if (!upkie::lock_memory()) {
spdlog::error("Could not lock process memory to RAM");
return -4;
}
Expand Down Expand Up @@ -190,8 +189,8 @@ int main(const CommandLineArguments& args) {
// Observation: Floor contact
FloorContact::Parameters floor_contact_params;
floor_contact_params.dt = 1.0 / args.spine_frequency;
floor_contact_params.upper_leg_joints = upkie::config::upper_leg_joints();
floor_contact_params.wheels = upkie::config::wheel_joints();
floor_contact_params.upper_leg_joints = upkie::upper_leg_joints();
floor_contact_params.wheels = upkie::wheel_joints();
auto floor_contact = std::make_shared<FloorContact>(floor_contact_params);
observation.append_observer(floor_contact);

Expand All @@ -210,14 +209,19 @@ int main(const CommandLineArguments& args) {
pi3hat_config.mounting_deg.yaw = 0.;

// pi3hat interface
const auto servo_layout = upkie::config::servo_layout();
const auto servo_layout = upkie::servo_layout();
Pi3HatInterface interface(servo_layout, args.can_cpu, pi3hat_config);

// Spine
Spine::Parameters spine_params;
spine_params.cpu = args.spine_cpu;
spine_params.frequency = args.spine_frequency;
<<<<<<< HEAD
spine_params.log_path = get_log_path(args.log_dir);
=======
const auto now = upkie::datetime_now_string();
spine_params.log_path = args.log_dir + "/" + now + "_pi3hat_spine.mpack";
>>>>>>> 10824f1 (WIP: Update to the merge of vulp into upkie)
spdlog::info("Spine data logged to {}", spine_params.log_path);
Spine spine(spine_params, interface, observation);
spine.run();
Expand Down
4 changes: 2 additions & 2 deletions tools/workspace/upkie/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ def upkie_repository():
git_repository(
name = "upkie",
remote = "https://github.com/upkie/upkie.git",
commit = "d6b91e4bcacc60e814637e9a59faba1a0e092eb3",
shallow_since = "1711032853 +0100",
commit = "b086cbf733167fee7b090e86b9c706c3fa35525f",
shallow_since = "1720024110 +0200",
)

0 comments on commit d2a22d4

Please sign in to comment.