Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 committed Mar 24, 2024
1 parent c3cf05a commit 48416ff
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 221 deletions.
4 changes: 2 additions & 2 deletions cmake/DARTFindDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ if(DART_BUILD_PROFILE)
include(FetchContent)
FetchContent_Declare(tracy
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
GIT_TAG v0.10
GIT_TAG master
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
Expand All @@ -124,7 +124,7 @@ if(DART_BUILD_PROFILE)
else()
target_compile_options(TracyClient PRIVATE -w)
endif()
target_compile_definitions(TracyClient PRIVATE TRACY_ENABLE)
target_compile_definitions(TracyClient PUBLIC TRACY_ENABLE)
endif()

find_package(Python3 COMPONENTS Interpreter Development)
Expand Down
6 changes: 2 additions & 4 deletions dart/simulation/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,9 @@ void World::reset()
//==============================================================================
void World::step(bool _resetCommand)
{
// DART_PROFILE_FRAME;

// Integrate velocity for unconstrained skeletons
{
// DART_PROFILE_SCOPED;
ZoneScoped;
DART_PROFILE_SCOPED;
for (auto& skel : mSkeletons) {
if (!skel->isMobile())
continue;
Expand Down Expand Up @@ -205,6 +202,7 @@ void World::step(bool _resetCommand)

mTime += mTimeStep;
mFrame++;
FrameMarkNamed("step");
}

//==============================================================================
Expand Down
30 changes: 30 additions & 0 deletions docker/dev/v6.14/Dockerfile.orbit
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Use Ubuntu 22.04 (Jammy Jellyfish) as the base image
FROM ubuntu:22.04

# Avoid prompts from apt
ENV DEBIAN_FRONTEND=noninteractive

# Update and install wget and software-properties-common (for add-apt-repository)
RUN apt-get update && apt-get install -y \
libgl1-mesa-glx \
libgl1-mesa-dri \
software-properties-common \
wget \
&& rm -rf /var/lib/apt/lists/*

# Add necessary repository for dependencies, if any (adjust as necessary)
# For example, universe might contain some dependencies
RUN add-apt-repository universe

# Download the orbit package from the provided URL
RUN wget https://github.com/google/orbit/releases/download/nightly-2024-03-21/orbit_1.86dev-478-g3493933c5-1.jammy1_amd64.deb

# Install the package with dpkg, then use apt-get to install any missing dependencies
# This step assumes all dependencies are available in the repositories added earlier
RUN dpkg -i orbit_1.86dev-478-g3493933c5-1.jammy1_amd64.deb || apt-get update && apt-get install -f -y

# Clean up
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Define the container's entry point
ENTRYPOINT ["vglrun /opt/orbitprofiler/Orbit"]
34 changes: 34 additions & 0 deletions docker/dev/v6.14/Dockerfile.tracy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Use an Ubuntu base image
FROM ubuntu:22.04

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Install build dependencies, X11 libraries, CA certificates, and Wayland protocols
RUN apt-get update && apt-get install -y \
build-essential \
cmake \
git \
libx11-dev \
libgl1-mesa-dev \
libgtk-3-dev \
xorg-dev \
ca-certificates \
wayland-protocols \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

# Clone the Tracy Profiler repository
RUN git clone --depth 1 https://github.com/wolfpld/tracy.git

# Build Tracy Profiler
WORKDIR /tracy/profiler/build/unix
RUN cmake ../.. && make

# Use the `entrypoint.sh` to start the profiler
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

# Reset the frontend to its default value
ENV DEBIAN_FRONTEND=
8 changes: 8 additions & 0 deletions docker/dev/v6.14/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# entrypoint.sh

# Use the host's display server for the GUI
export DISPLAY=host.docker.internal:0

# Start Tracy Profiler
./tracy/profiler/build/unix/Tracy-release
12 changes: 2 additions & 10 deletions examples/speed_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@ get_filename_component(example_name ${CMAKE_CURRENT_LIST_DIR} NAME)

project(${example_name})

set(required_components utils-urdf)
set(required_libraries dart dart-utils-urdf)

if(DART_IN_SOURCE_BUILD)
dart_build_example_in_source(${example_name} LINK_LIBRARIES ${required_libraries})
dart_build_example_in_source(${example_name} LINK_LIBRARIES )
target_link_libraries(${example_name} PUBLIC TracyClient pthread)
return()
endif()

find_package(DART 6.14.0 REQUIRED COMPONENTS ${required_components} CONFIG)

file(GLOB srcs "*.cpp" "*.hpp")
add_executable(${example_name} ${srcs})
target_link_libraries(${example_name} PUBLIC ${required_libraries})
226 changes: 21 additions & 205 deletions examples/speed_test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,221 +30,37 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#include "dart/utils/utils.hpp"
#include <tracy/Tracy.hpp>

#include <dart/dart.hpp>
#include <thread>
#include <iostream>

#include <chrono>
#include <numeric>

double testForwardKinematicSpeed(
dart::dynamics::SkeletonPtr skel,
bool position = true,
bool velocity = true,
bool acceleration = true,
std::size_t numTests = 100000)
{
if (nullptr == skel)
return 0;

dart::dynamics::BodyNode* bn = skel->getBodyNode(0);
while (bn->getNumChildBodyNodes() > 0)
bn = bn->getChildBodyNode(0);

std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();

for (std::size_t i = 0; i < numTests; ++i) {
for (std::size_t i = 0; i < skel->getNumDofs(); ++i) {
dart::dynamics::DegreeOfFreedom* dof = skel->getDof(i);
dof->setPosition(dart::math::Random::uniform(
std::max(dof->getPositionLowerLimit(), -1.0),
std::min(dof->getPositionUpperLimit(), 1.0)));
}

for (std::size_t i = 0; i < skel->getNumBodyNodes(); ++i) {
if (position)
skel->getBodyNode(i)->getWorldTransform();
if (velocity) {
skel->getBodyNode(i)->getSpatialVelocity();
skel->getBodyNode(i)->getPartialAcceleration();
}
if (acceleration)
skel->getBodyNode(i)->getSpatialAcceleration();
}
void worker1() {
while (true) {
ZoneScoped;
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
std::cout << "worker2..." << std::endl;
}

end = std::chrono::system_clock::now();

std::chrono::duration<double> elapsed_seconds = end - start;
return elapsed_seconds.count();
}

void runKinematicsTest(
std::vector<double>& results,
const std::vector<dart::simulation::WorldPtr>& worlds,
bool position,
bool velocity,
bool acceleration)
{
double totalTime = 0;
std::cout << "Testing: ";
if (position)
std::cout << "Position ";
if (velocity)
std::cout << "Velocity ";
if (acceleration)
std::cout << "Acceleration ";
std::cout << "\n";

// Test for updating the whole skeleton
for (std::size_t i = 0; i < worlds.size(); ++i) {
dart::simulation::WorldPtr world = worlds[i];
totalTime += testForwardKinematicSpeed(
world->getSkeleton(0), position, velocity, acceleration);
}
results.push_back(totalTime);
std::cout << "Result: " << totalTime << "s" << std::endl;
}

double testDynamicsSpeed(
dart::simulation::WorldPtr world, std::size_t numIterations = 10000)
{
if (nullptr == world)
return 0;

world->eachSkeleton([](dart::dynamics::Skeleton* skel) {
skel->resetPositions();
skel->resetVelocities();
skel->resetAccelerations();
});

std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();

for (std::size_t i = 0; i < numIterations; ++i) {
world->step();
}

end = std::chrono::system_clock::now();

std::chrono::duration<double> elapsed_seconds = end - start;
return elapsed_seconds.count();
}

void runDynamicsTest(
std::vector<double>& results,
const std::vector<dart::simulation::WorldPtr>& worlds)
{
double totalTime = 0;

for (std::size_t i = 0; i < worlds.size(); ++i) {
totalTime += testDynamicsSpeed(worlds[i]);
void worker2() {
while (true) {
ZoneScoped;
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "worker1..." << std::endl;
FrameMark;
}

results.push_back(totalTime);
std::cout << "Result: " << totalTime << "s" << std::endl;
}

void print_results(const std::vector<double>& result)
{
double sum = std::accumulate(result.begin(), result.end(), 0.0);
double mean = sum / result.size();
std::cout << "Average: " << mean << "\n";
std::vector<double> diff(result.size());
std::transform(
result.begin(),
result.end(),
diff.begin(),
std::bind(std::minus<double>(), mean, std::placeholders::_1));
double stddev = std::sqrt(
std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0)
/ result.size());
std::cout << "Std Dev: " << stddev << "\n";
}

std::vector<std::string> getSceneFiles()
{
std::vector<std::string> scenes;
scenes.push_back("dart://sample/skel/test/chainwhipa.skel");
scenes.push_back("dart://sample/skel/test/single_pendulum.skel");
scenes.push_back("dart://sample/skel/test/single_pendulum_euler_joint.skel");
scenes.push_back("dart://sample/skel/test/single_pendulum_ball_joint.skel");
scenes.push_back("dart://sample/skel/test/double_pendulum.skel");
scenes.push_back("dart://sample/skel/test/double_pendulum_euler_joint.skel");
scenes.push_back("dart://sample/skel/test/double_pendulum_ball_joint.skel");
scenes.push_back("dart://sample/skel/test/serial_chain_revolute_joint.skel");
scenes.push_back("dart://sample/skel/test/serial_chain_eulerxyz_joint.skel");
scenes.push_back("dart://sample/skel/test/serial_chain_ball_joint.skel");
scenes.push_back("dart://sample/skel/test/serial_chain_ball_joint_20.skel");
scenes.push_back("dart://sample/skel/test/serial_chain_ball_joint_40.skel");
scenes.push_back("dart://sample/skel/test/simple_tree_structure.skel");
scenes.push_back(
"dart://sample/skel/test/simple_tree_structure_euler_joint.skel");
scenes.push_back(
"dart://sample/skel/test/simple_tree_structure_ball_joint.skel");
scenes.push_back("dart://sample/skel/test/tree_structure.skel");
scenes.push_back("dart://sample/skel/test/tree_structure_euler_joint.skel");
scenes.push_back("dart://sample/skel/test/tree_structure_ball_joint.skel");
scenes.push_back("dart://sample/skel/fullbody1.skel");

return scenes;
}

std::vector<dart::simulation::WorldPtr> getWorlds()
int main()
{
std::vector<std::string> sceneFiles = getSceneFiles();
std::vector<dart::simulation::WorldPtr> worlds;
for (std::size_t i = 0; i < sceneFiles.size(); ++i)
worlds.push_back(dart::utils::SkelParser::readWorld(sceneFiles[i]));
std::cout << "starting.." << std::endl;

return worlds;
}
std::thread t1(worker1);
std::thread t2(worker2);

int main(int argc, char* argv[])
{
bool test_kinematics = false;
for (int i = 1; i < argc; ++i) {
if (std::string(argv[i]) == "-k")
test_kinematics = true;
}

std::vector<dart::simulation::WorldPtr> worlds = getWorlds();

if (test_kinematics) {
std::cout << "Testing Kinematics" << std::endl;
std::vector<double> acceleration_results;
std::vector<double> velocity_results;
std::vector<double> position_results;

for (std::size_t i = 0; i < 10; ++i) {
std::cout << "\nTrial #" << i + 1 << std::endl;
runKinematicsTest(acceleration_results, worlds, true, true, true);
runKinematicsTest(velocity_results, worlds, true, true, false);
runKinematicsTest(position_results, worlds, true, false, false);
}

std::cout << "\n\n --- Final Kinematics Results --- \n\n";

std::cout << "Position, Velocity, Acceleration\n";
print_results(acceleration_results);

std::cout << "\nPosition, Velocity\n";
print_results(velocity_results);

std::cout << "\nPosition\n";
print_results(position_results);

return 0;
}

std::cout << "Testing Dynamics" << std::endl;
std::vector<double> dynamics_results;
for (std::size_t i = 0; i < 10; ++i) {
std::cout << "\nTrial #" << i + 1 << std::endl;
runDynamicsTest(dynamics_results, worlds);
}
t1.join();
t2.join();

std::cout << "\n\n --- Final Dynamics Results --- \n\n";
print_results(dynamics_results);
return 0;
}

0 comments on commit 48416ff

Please sign in to comment.