Skip to content

Commit

Permalink
Merge pull request #190 from NASA-Tensegrity-Robotics-Toolkit/Structu…
Browse files Browse the repository at this point in the history
…reFileSpec

YAML Model Builder
  • Loading branch information
simonkotwicz committed Apr 2, 2016
2 parents c6d5a62 + ad64d1e commit 21b076b
Show file tree
Hide file tree
Showing 39 changed files with 2,314 additions and 86 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ src/.settings/org.eclipse.cdt.codan.core.prefs

*~
*#
*.DS_Store

*.pdfsync
*.bbl
Expand Down
219 changes: 219 additions & 0 deletions bin/setup/setup_yamlcpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
#!/bin/bash

# Copyright © 2012, United States Government, as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All rights reserved.
#
# The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
# under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

# Purpose: YamlCPP setup
# Date: 2015-12-12

##############################################################################
# START DO NOT MODIFY #
##############################################################################
SCRIPT_PATH="`dirname \"$0\"`"
SCRIPT_PATH="`( cd \"$SCRIPT_PATH\" && pwd )`"
##############################################################################
# END DO NOT MODIFY #
##############################################################################

# Add the relative path from this script to the helpers folder.
pushd "${SCRIPT_PATH}/helpers/" > /dev/null

##############################################################################
# START DO NOT MODIFY #
##############################################################################
if [ ! -f "helper_functions.sh" ]; then
echo "Could not find helper_functions.sh. Are we in the bash helpers folder?"
exit 1;
fi

# Import our common files
source "helper_functions.sh"
source "helper_paths.sh"
source "helper_definitions.sh"

# Get out of the bash helpers folder.
popd > /dev/null
##############################################################################
# END DO NOT MODIFY #
##############################################################################

#Source this package's configuration
source_conf "general.conf"
source_conf "yamlcpp.conf"

# Variables
yamlcpp_pkg=`echo $YAMLCPP_URL|awk -F/ '{print $NF}'` # get the package name from the url

# Check to see if yamlcpp has been built already
function check_yamlcpp_built()
{
# Check for a library that's created when yamlcpp is built
fname=$(find "$YAMLCPP_BUILD_DIR" -iname libyaml-cpp* 2>/dev/null)
if [ -f "$fname" ]; then
return $TRUE
fi
return $FALSE
}

# Download the package to env/downloads
function download_yamlcpp()
{

yamlcpp_pkg_path="$DOWNLOADS_DIR/$yamlcpp_pkg"

if [ -f "$yamlcpp_pkg_path" ]; then
echo "- YamlCPP package already exists ('$yamlcpp_pkg_path') -- skipping download."
return
fi

echo "Downloading $yamlcpp_pkg to $yamlcpp_pkg_path"
download_file "$YAMLCPP_URL" "$yamlcpp_pkg_path"
}

# Unpack to the build directory specified in install.conf
function unpack_yamlcpp()
{
# Create directory and unpack
if check_directory_exists "$YAMLCPP_BUILD_DIR"; then
echo "- YamlCPP is already unpacked to '$YAMLCPP_BUILD_DIR' -- skipping."
return
fi

echo "Unpacking yamlcpp to $YAMLCPP_BUILD_DIR (this may take a minute...)"
# TODO: Do we need to remove the dir if it already exists?
create_directory_if_noexist $YAMLCPP_BUILD_DIR

# Unzip
pushd "$YAMLCPP_BUILD_DIR" > /dev/null
unzip "$DOWNLOADS_DIR/$yamlcpp_pkg" || { echo "- ERROR: Failed to unpack YamlCPP"; exit 1; }
mv yaml*/* .
popd > /dev/null
}

# Build the package under the build directory specified in in install.conf
function build_yamlcpp()
{

echo "- Building YamlCPP under $YAMLCPP_BUILD_DIR"
pushd "$YAMLCPP_BUILD_DIR" > /dev/null

# Perform the build
# If you turn double precision on, turn it on in inc.CMakeYamlCPP.txt as well for the NTRT build
"$ENV_DIR/bin/cmake" . -G "Unix Makefiles" \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_EXTRAS=ON \
-DCMAKE_INSTALL_PREFIX="$YAMLCPP_INSTALL_PREFIX" \
-DCMAKE_C_COMPILER="gcc" \
-DCMAKE_CXX_COMPILER="g++" \
-DCMAKE_C_FLAGS="-fPIC" \
-DCMAKE_CXX_FLAGS="-fPIC" \
-DCMAKE_EXE_LINKER_FLAGS="-fPIC" \
-DCMAKE_MODULE_LINKER_FLAGS="-fPIC" \
-DCMAKE_SHARED_LINKER_FLAGS="-fPIC" \
-DUSE_DOUBLE_PRECISION=OFF \
-DCMAKE_INSTALL_NAME_DIR="$YAMLCPP_INSTALL_PREFIX" || { echo "- ERROR: CMake for YamlCPP failed."; exit 1; }
#If you turn this on, turn it on in inc.CMakeYamlCPP.txt as well for the NTRT build
# Additional yamlcpp options:
# -DFRAMEWORK=ON
# -DBUILD_DEMOS=ON

make || { echo "- ERROR: YamlCPP build failed"; exit 1; }

popd > /dev/null
}

# Install the package under the package install prefix from install.conf
function install_yamlcpp()
{

echo "- Installing YamlCPP under $YAMLCPP_INSTALL_PREFIX"

pushd "$YAMLCPP_BUILD_DIR" > /dev/null

make install || { echo "Install failed -- maybe you need to use sudo when running setup?"; exit 1; }

popd > /dev/null
}

# Create symlinks under env for building our applications and IDE integration
function env_link_yamlcpp()
{

# Build
pushd "$ENV_DIR/build" > /dev/null
rm yamlcpp 2>/dev/null # Note: this will fail if 'yamlcpp' is a directory, which is what we want.

# If we're building under env, use a relative path for the link; otherwise use an absolute one.
if str_contains "$YAMLCPP_BUILD_DIR" "$ENV_DIR"; then
current_pwd=`pwd`
rel_path=$(get_relative_path "$current_pwd" "$YAMLCPP_BUILD_DIR" )
create_exist_symlink "$rel_path" yamlcpp
else
create_exist_symlink "$YAMLCPP_BUILD_DIR" yamlcpp # this links directly to the most recent build...
fi

popd > /dev/null

}

function main()
{

ensure_install_prefix_writable $YAMLCPP_INSTALL_PREFIX

if check_package_installed "$YAMLCPP_INSTALL_PREFIX/lib/libyaml-cpp*"; then
echo "- YamlCPP is installed under prefix $YAMLCPP_INSTALL_PREFIX -- skipping."
env_link_yamlcpp
return
fi

if check_yamlcpp_built; then
echo "- YamlCPP is already built under $YAMLCPP_BUILD_DIR -- skipping."
install_yamlcpp
env_link_yamlcpp
return
fi

# @todo: add check yamlcpp patched

if check_file_exists "$YAMLCPP_PACKAGE_DIR/CMakeLists.txt"; then
echo "- YamlCPP is already unpacked to $YAMLCPP_BUILD_DIR -- skipping."
build_yamlcpp
install_yamlcpp
env_link_yamlcpp
return
fi

if check_file_exists "$DOWNLOADS_DIR/$yamlcpp_pkg"; then
echo "- YamlCPP package already exists under env/downloads -- skipping download."
unpack_yamlcpp
build_yamlcpp
install_yamlcpp
env_link_yamlcpp
return
fi

# If we haven't returned by now, we have to do everything
download_yamlcpp
unpack_yamlcpp
build_yamlcpp
install_yamlcpp
env_link_yamlcpp

}


main
42 changes: 42 additions & 0 deletions conf/default/yamlcpp.conf.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Copyright © 2012, United States Government, as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All rights reserved.
#
# The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
# under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

# Purpose: Define configuration directives for setup_yamlcpp.sh.
# Date: 2015-12-12
# Usage: Copy/rename this file to '../yamlcpp.conf' and run setup.sh

# YamlCPP installation prefix

# Global install: /usr/local, env install: "$ENV_DIR"
# By default, setup will download and install YamlCPP under your env directory.
# If you have an existing YamlCPP install, you should change
# YAMLCPP_INSTALL_PREFIX to what was used for installation (likely /usr/local).
YAMLCPP_INSTALL_PREFIX="$ENV_DIR"

# Location where YamlCPP is to be built if necessary, or where it was built if
# you're using an existing package. This doesn't need to be set unless yamlcpp is
# not already installed.
YAMLCPP_BUILD_DIR="$ENV_DIR/build/yamlcpp_0_5_2"

# This is the location where you unzipped the package (or, where it will
# be unzipped if necessary).
YAMLCPP_PACKAGE_DIR="$YAMLCPP_BUILD_DIR"

# YAMLCPP_URL can be either a web address or a local file address,
# e.g. http://url.com/for/yamlcpp.tgz or file:///path/to/yamlcpp.tgz
YAMLCPP_URL="https://github.com/jbeder/yaml-cpp/archive/release-0.5.2.zip"
47 changes: 47 additions & 0 deletions resources/YamlStructures/BaseStructures/3Prism.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
nodes:
bottom1: [-5, 0, 0]
bottom2: [5, 0, 0]
bottom3: [0, 0, 8.66]

top1: [-5, 5, 0]
top2: [5, 5, 0]
top3: [0, 5, 8.66]

pair_groups:
prism_rod:
- [bottom1, top2]
- [bottom2, top3]
- [bottom3, top1]

horizontal_string:
- [bottom1, bottom2]
- [bottom2, bottom3]
- [bottom1, bottom3]

- [top1, top2]
- [top2, top3]
- [top1, top3]

vertical_string:
- [bottom1, top1]
- [bottom2, top2]
- [bottom3, top3]

builders:
prism_rod:
class: tgRodInfo
parameters:
density: 0.688
radius: 0.31
horizontal_string:
class: tgBasicActuatorInfo
parameters:
stiffness: 1000
damping: 10
pretension: 3000
vertical_string:
class: tgBasicActuatorInfo
parameters:
stiffness: 1000
damping: 10
pretension: 1000
40 changes: 40 additions & 0 deletions resources/YamlStructures/BaseStructures/3PrismSymmetric.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
nodes:
bottom1: [-5, 0, 0]
bottom2: [5, 0, 0]
bottom3: [0, 0, 8.66]

top1: [-5, 5, 0]
top2: [5, 5, 0]
top3: [0, 5, 8.66]

pair_groups:
prism_rod:
- [bottom1, top2]
- [bottom2, top3]
- [bottom3, top1]

prism_string:
- [bottom1, bottom2]
- [bottom2, bottom3]
- [bottom1, bottom3]

- [top1, top2]
- [top2, top3]
- [top1, top3]

- [bottom1, top1]
- [bottom2, top2]
- [bottom3, top3]

builders:
prism_rod:
class: tgRodInfo
parameters:
density: 0.688
radius: 0.31
prism_string:
class: tgBasicActuatorInfo
parameters:
stiffness: 1000
damping: 10
pretension: 1000

0 comments on commit 21b076b

Please sign in to comment.