diff --git a/CMakeLists.txt b/CMakeLists.txt index 484f86430c..a2d47b2158 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,6 @@ else () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++1y -DFRC_SIMULATOR -Wno-unused-parameter -pthread -fPIC -fpermissive") endif() - include_directories("build") add_subdirectory(simulation/gz_msgs) add_subdirectory(wpilibc/simulation) diff --git a/build.gradle b/build.gradle index d399ffd902..acf7a3a5db 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,8 @@ if (!hasProperty('repo')) { def repoBaseUrl = "http://first.wpi.edu/FRC/roborio/maven/${repo}" def publishUrl = "${System.getProperty('user.home')}/releases/maven/${repo}" +ext.simulationInstallDir = "$rootDir/build/install/simulation" + allprojects { ext.enableSimulation = enableSimulation ext.repo = repo @@ -43,4 +45,4 @@ subprojects { } } -apply from: 'cppSettings.gradle' \ No newline at end of file +apply from: 'cppSettings.gradle' diff --git a/settings.gradle b/settings.gradle index 9a43e3c29b..9c570c463a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,6 +2,10 @@ include 'hal', 'wpilibc', 'wpilibcIntegrationTests', 'wpilibj', - 'wpilibjIntegrationTests', + 'wpilibjIntegrationTests' + +if (hasProperty("makeSim")){ +include 'simulation', 'simulation:JavaGazebo', 'simulation:SimDS' +} diff --git a/simulation/SimDS/build.gradle b/simulation/SimDS/build.gradle index 7d44b8e1b6..58270b7f21 100644 --- a/simulation/SimDS/build.gradle +++ b/simulation/SimDS/build.gradle @@ -53,4 +53,12 @@ task simDsJavadoc(type: Jar, dependsOn: javadoc) { from javadoc.destinationDir } +//we need to move the simulation jars to the install directory +task copyJars(type: Copy) { + description = 'copy SimDS-all.jar to make simulation zip' + group = 'WPILib Simulation' + from shadowJar.archivePath + into "$simulationInstallDir/jar" +} + build.dependsOn shadowJar diff --git a/simulation/build.gradle b/simulation/build.gradle new file mode 100644 index 0000000000..1698f19911 --- /dev/null +++ b/simulation/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'java' +apply plugin: 'maven-publish' + +publishing { + publications { + simulation(MavenPublication) { + artifact zip + groupId 'simulation' + artifactId 'simulation' + version '1.0.0' + } + } + + setupWpilibRepo(it) +} + +task copy_resources(type: Copy) { + description = 'copy gz_msgs and install_resources to make simulation zip' + group = 'WPILib Simulation' + into ('gz_msgs') { + from 'gz_msgs' + } + into "$simulationInstallDir" + from 'install_resources' +} + +task zip(type: Zip, dependsOn: [copy_resources, + ':wpilibc:wpilibcSimCopy', + ':simulation:SimDS:copyJars', + ':wpilibj:copyJars']) { + description = 'zip of all the resources for simulation' + group = 'WPILib Simulation' + baseName = 'simulation-trusty' + from "$simulationInstallDir" +} diff --git a/simulation/frc_gazebo_plugins/CMakeLists.txt b/simulation/frc_gazebo_plugins/CMakeLists.txt index 6c662c3bff..e3574dddca 100644 --- a/simulation/frc_gazebo_plugins/CMakeLists.txt +++ b/simulation/frc_gazebo_plugins/CMakeLists.txt @@ -12,8 +12,6 @@ set (PLUGINS rangefinder servo) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/plugins) - link_directories(${GAZEBO_LIBRARY_DIRS}) foreach(PLUGIN ${PLUGINS}) @@ -29,8 +27,9 @@ foreach(PLUGIN ${PLUGINS}) endif() target_link_libraries(${PLUGIN} gz_msgs ${GAZEBO_LIBRARIES} ${Boost_LIBRARIES}) - - install(TARGETS ${PLUGIN} DESTINATION $ENV{HOME}/wpilib/simulation/plugins) + set_target_properties(${PLUGIN} + PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${SIMULATION_INSTALL_DIR}/plugins) endforeach() diff --git a/simulation/frcsim_installer.sh b/simulation/frcsim_installer.sh new file mode 100755 index 0000000000..be3d4a5712 --- /dev/null +++ b/simulation/frcsim_installer.sh @@ -0,0 +1,224 @@ +#!/bin/bash + +function check-environment { + # Ensure root access + if [ "$(id -u)" != "0" ]; then + echo "*** This script must be run as root!" 1>&2 + echo "*** Make sure that you followed the instructions properly." 1>&2 + install-fail + fi + + # Make sure that we're on Ubuntu. + if [ "$(lsb_release -is)" != "Ubuntu" ]; then + if [ "$(lsb_release -is)" = "" ]; then + echo "*** Distributions other than Ubuntu (such as yours, probably) are not supported." 1>&2 + else + echo "*** Distributions other than Ubuntu (such as $(lsb_release -is)) are not supported." 1>&2 + fi + echo "*** This means that the install will likely fail." 1>&2 + echo "*** Continue anyway? (y/n)" 1>&2 + read CONT + if [ "$CONT" != "y" -a "$CONT" != "Y" ]; then + install-fail + fi + fi + + # Make sure that we have /etc/apt/sources.list.d available. + if [ ! -e /etc/apt/sources.list.d ]; then + echo "*** Cannot find /etc/apt/sources.list.d - is apt installed?" + install-fail + fi + + # Make sure that apt-key is installed. + if ! which apt-key >/dev/null; then + echo "*** You don't appear to have apt-key installed." 1>&2 + echo "*** Please install apt and run the script again." 1>&2 + install-fail + fi + + # Make sure that apt-get is installed. + if ! which apt-get >/dev/null; then + echo "*** You don't appear to have apt-get installed." 1>&2 + echo "*** Please install apt and run the script again." 1>&2 + install-fail + fi + + # Make sure that we have internet access. + if ! ping 8.8.8.8 -c 1 >/dev/null; then + echo "*** You don't appear to be able to access the internet! (Can't ping 8.8.8.8)" 1>&2 + install-fail + fi + + # Make sure that wget is installed. + if ! which wget >/dev/null; then + echo "*** You don't appear to have wget installed." 1>&2 + echo "*** Install? (y/n)" 1>&2 + read CONT + if [ "$CONT" != "y" -a "$CONT" != "Y" ]; then + install-fail + fi + apt-get install wget -y + fi + + # Make sure that python is installed + if ! which python >/dev/null; then + echo "*** You don't appear to have python installed." 1>&2 + echo "*** Install? (y/n)" 1>&2 + read CONT + if [ "$CONT" != "y" -a "$CONT" != "Y" ]; then + install-fail + fi + apt-get install python -y + fi + + # Make sure that unzip is installed + if ! which unzip >/dev/null; then + echo "*** You don't appear to have unzip installed." 1>&2 + echo "*** Install? (y/n)" 1>&2 + read CONT + if [ "$CONT" != "y" -a "$CONT" != "Y" ]; then + install-fail + fi + apt-get install unzip -y + fi +} + +function remove-frcsim { + check-environment + + echo "*** Remove Gazebo package entry too? (y/n)" 1>&2 + read CONT + if [ "$CONT" == "y" -o "$CONT" == "Y" ]; then + rm -f /etc/apt/sources.list.d/gazebo-latest.list + fi + + apt-get update + apt-get remove --auto-remove gazebo6 g++-4.9 openjdk-8-jdk + rm -rf /opt/eclipse + rm -f /usr/share/applications/frcsim.desktop /usr/share/applications/eclipse.desktop /usr/share/applications/sim_ds.desktop + rm -f /usr/bin/frcism /usr/bin/sim_ds /usr/bin/eclipse + rm -rf ~/wpilib/simulation +} + +function install-eclipse-plugins { + if ! (wget -O /tmp/simulation.zip http://first.wpi.edu/FRC/roborio/maven/development/simulation/simulation/1.0.0/simulation-1.0.0.zip) + then + echo "***could not download wpilib simulation plugins, wrong URL probably***" + install-fail + fi + + mkdir -p ~/wpilib/simulation + unzip /tmp/simulation.zip -d ~/wpilib/simulation + ln -fs ~/wpilib/simulation/frcsim /usr/bin/frcsim + ln -fs ~/wpilib/simulation/sim_ds /usr/bin/sim_ds +} + +function install-eclipse { + if ! (wget -O /tmp/eclipse.tar.gz http://eclipse.mirror.rafal.ca/technology/epp/downloads/release/mars/1/eclipse-cpp-mars-1-linux-gtk-x86_64.tar.gz) + then + echo "***could not download eclipse, wrong URL probably***" + install-fail + fi + + tar -xf /tmp/eclipse.tar.gz -C /opt + ln -s /opt/eclipse/eclipse /usr/bin/eclipse +} + +function install-desktops { + mv ~/wpilib/simulation/eclipse.desktop /usr/share/applications/eclipse.desktop + mv ~/wpilib/simulation/frcsim.desktop /usr/share/applications/frcsim.desktop + mv ~/wpilib/simulation/sim_ds.desktop /usr/share/applications/sim_ds.desktop +} + +function install-gz_msgs { + cd ~/wpilib/simulation/gz_msgs + mkdir build + cd build + cmake .. + make + make install +} + +function install-toolchain { + add-apt-repository ppa:openjdk-r/ppa -y + add-apt-repository ppa:ubuntu-toolchain-r/test -y + apt-get update + apt-get install libprotoc-dev libprotobuf-dev protobuf-compiler g++-4.9 openjdk-8-jdk -y + ln -fs /usr/bin/g++-4.9 /usr/bin/g++ +} + +function install-models { + if ! (wget -O /tmp/models.zip https://usfirst.collab.net/sf/frs/do/downloadFile/projects.wpilib/frs.simulation.frcsim_gazebo_models/frs1160?) + then + echo "*** failed to download models. Check your internet connection! ***" + install-fail + fi + + unzip /tmp/models.zip -d ~/wpilib/simulation +} + +function install-frcsim { + check-environment + + # Add Gazebo Repository and Key + if ! echo "deb http://packages.osrfoundation.org/gazebo/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-latest.list + then + echo "*** Cannot add Gazebo repository!" 1>&2 + install-fail + fi + if ! (wget http://packages.osrfoundation.org/gazebo.key -O - | apt-key add -) + then + echo "*** Cannot add Gazebo repository key!" 1>&2 + if ! ping packages.osrfoundation.org -c 1 >/dev/null; then + echo "*** The package host for Gazebo appears to be down. Try again later." 1>&2 + fi + install-fail + fi + + # Update and install dependencies + if ! apt-get update + then + echo "*** Could not resynchronize package index files." 1>&2 + echo "*** Are you running another update or install?" 1>&2 + install-fail + fi + if ! apt-get install -y gazebo6 + then + echo "*** Could not install frcsim packages. See above output for details." 1>&2 + echo "*** Are you running another update or install?" 1>&2 + install-fail + fi + + install-eclipse-plugins + install-toolchain + install-gz_msgs + install-eclipse + install-desktops + install-models + + # Done + echo "Installation Finished!!" +} + +if [ "$1" == "ROOT" ] +then + install-frcsim +elif [ "$1" == "INSTALLER" ] +then + SUDO_ASKPASS=/usr/bin/ssh-askpass sudo bash -c "$0 ROOT" +elif [ "$1" == "REMOVE-ROOT" ] +then + remove-frcsim +elif [ "$1" == "REMOVE" ] +then + SUDO_ASKPASS=/usr/bin/ssh-askpass sudo bash -c "$0 REMOVE-ROOT" +else + if [ -z "$1" ] + then + echo "***This script requires an argument!***" + echo "***Run ./frcsim_installer.sh INSTALLER to install***" + echo "***Other options are REMOVE, or any of the functions in the script" + else + $@ + fi +fi diff --git a/simulation/gz_msgs/CMakeLists.txt b/simulation/gz_msgs/CMakeLists.txt index 31c7dbaa5c..5ca638686e 100644 --- a/simulation/gz_msgs/CMakeLists.txt +++ b/simulation/gz_msgs/CMakeLists.txt @@ -62,4 +62,10 @@ else() endif() target_link_libraries(${PROJECT_NAME} ${PROTOBUF_LIBRARIES}) -set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH "${ENV_HOME}/wpilib/simulation/lib") +set_target_properties(${PROJECT_NAME} + PROPERTIES + INSTALL_RPATH "${ENV_HOME}/wpilib/simulation/lib" + LIBRARY_OUTPUT_DIRECTORY ${SIMULATION_INSTALL_DIR}/lib) + +file(COPY "${GZ_MSGS_INCLUDE_DIR}/simulation" + DESTINATION "${CMAKE_BINARY_DIR}/install/simulation/include") diff --git a/simulation/install_resources/eclipse.desktop b/simulation/install_resources/eclipse.desktop new file mode 100644 index 0000000000..c6d8a8633a --- /dev/null +++ b/simulation/install_resources/eclipse.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Name=Eclipse +Exec=/usr/bin/eclipse +Icon=/opt/eclipse/icon.xpm +Type=Application +Categories=Development;Education;Science; +StartupNotify=true diff --git a/simulation/frcsim b/simulation/install_resources/frcsim similarity index 100% rename from simulation/frcsim rename to simulation/install_resources/frcsim diff --git a/simulation/install_resources/frcsim.desktop b/simulation/install_resources/frcsim.desktop new file mode 100644 index 0000000000..6434d9ce81 --- /dev/null +++ b/simulation/install_resources/frcsim.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=FRCSim +Keywords=frcsim,gazebo +Exec=/usr/bin/frcsim +Icon=gazebo +Type=Application +StartupNotify=true +Terminal=false +Categories=Development;IDE;Java;Education;Science diff --git a/simulation/install_resources/lib/libjinput-linux.so b/simulation/install_resources/lib/libjinput-linux.so new file mode 100755 index 0000000000..dba9e59fad Binary files /dev/null and b/simulation/install_resources/lib/libjinput-linux.so differ diff --git a/simulation/install_resources/lib/libjinput-linux64.so b/simulation/install_resources/lib/libjinput-linux64.so new file mode 100755 index 0000000000..8b5f9d84f4 Binary files /dev/null and b/simulation/install_resources/lib/libjinput-linux64.so differ diff --git a/simulation/sim_ds b/simulation/install_resources/sim_ds similarity index 100% rename from simulation/sim_ds rename to simulation/install_resources/sim_ds diff --git a/simulation/install_resources/sim_ds.desktop b/simulation/install_resources/sim_ds.desktop new file mode 100644 index 0000000000..34b6a177ac --- /dev/null +++ b/simulation/install_resources/sim_ds.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=Sim DS +Keywords=frcsim,driverstation +Exec=/usr/bin/sim_ds +Icon=~/wpilib/simulation/sim_ds_logo.png +Type=Application +StartupNotify=true +Terminal=false +Categories=Development;IDE;Java;Education;Science diff --git a/simulation/install_resources/sim_ds_logo.png b/simulation/install_resources/sim_ds_logo.png new file mode 100644 index 0000000000..39df91cee3 Binary files /dev/null and b/simulation/install_resources/sim_ds_logo.png differ diff --git a/wpilibc/build.gradle b/wpilibc/build.gradle index 959aaefe68..663e0ade22 100644 --- a/wpilibc/build.gradle +++ b/wpilibc/build.gradle @@ -22,4 +22,8 @@ ext.checkDoxygen = { } apply from: 'athena.gradle' -apply from: 'simulation.gradle' + +if (hasProperty('makeSim')){ + apply from: 'simulation.gradle' +} + diff --git a/wpilibc/simulation.gradle b/wpilibc/simulation.gradle index d8bd9b341c..ec70276883 100644 --- a/wpilibc/simulation.gradle +++ b/wpilibc/simulation.gradle @@ -1,33 +1,46 @@ import org.apache.tools.ant.taskdefs.condition.Os -if (project.hasProperty('makeSim')){ //cmake wrapper tasks - task setupCmake(type: Exec) { +task setupCmake(type: Exec) { + description = 'create build directory for cmake to use' + group = 'WPILib Simulation' workingDir '..' commandLine 'mkdir', '-p', 'build' - } +} - task cmake(type: Exec, dependsOn: setupCmake) { +task cmake(type: Exec, dependsOn: setupCmake) { + description = 'run cmake in the build directory to generate makefiles' + group = 'WPILib Simulation' workingDir '../build' if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine '../configure.bat', "-DNTCORE_INCLUDE_DIR=$netTablesInclude","-DNTCORE_LIBDIR=$netLibDesktopLocation" + commandLine '../configure.bat', + "-DNTCORE_INCLUDE_DIR=$netTablesInclude", + "-DNTCORE_LIBDIR=$netLibDesktopLocation", + "-DSIMULATION_INSTALL_DIR=$simulationInstallDir" } else { - commandLine 'cmake', '..', "-DNTCORE_INCLUDE_DIR=$netTablesInclude","-DNTCORE_LIBDIR=$netLibDesktopLocation" + commandLine 'cmake', '..', + "-DNTCORE_INCLUDE_DIR=$netTablesInclude", + "-DNTCORE_LIBDIR=$netLibDesktopLocation", + "-DSIMULATION_INSTALL_DIR=$simulationInstallDir" } - } +} - task frc_gazebo_plugins(type: Exec, dependsOn: cmake) { +task frc_gazebo_plugins(type: Exec, dependsOn: cmake) { + description = 'build Gazebo plugins with cmake' + group = 'WPILib Simulation' workingDir '../build' if (Os.isFamily(Os.FAMILY_WINDOWS)) { - comanndLine 'nmake', 'frc_gazebo_plugins' + commandLine 'nmake', 'frc_gazebo_plugins' } else { - commandLine 'make', 'frc_gazebo_plugins' + commandLine 'make', 'frc_gazebo_plugins' } - } +} - task gz_msgs(type: Exec, dependsOn: cmake) { +task gz_msgs(type: Exec, dependsOn: cmake) { + description = 'build gz_msgs library with cmake' + group = 'WPILib Simulation' workingDir '../build' if (Os.isFamily(Os.FAMILY_WINDOWS)) { commandLine 'nmake', 'gz_msgs' @@ -35,20 +48,49 @@ if (project.hasProperty('makeSim')){ else { commandLine 'make', 'gz_msgs' } - } +} - task wpilibcSim(type: Exec, dependsOn: ['cmake', ':unzipNetworkTables']) { +task wpilibcSim(type: Exec, dependsOn: ['cmake', ':unzipNetworkTables']) { + description = 'build WPILib C++ for simulation with cmake' + group = 'WPILib Simulation' workingDir '../build' if (Os.isFamily(Os.FAMILY_WINDOWS)) { - commandLine 'nmake', 'wpilibcSim' + commandLine 'nmake', 'wpilibcSim' } else { - commandLine 'make', 'wpilibcSim' + commandLine 'make', 'wpilibcSim' } - } - - task allcsim(dependsOn: [wpilibcSim, gz_msgs, frc_gazebo_plugins]){ - } - - build.dependsOn allcsim } + +task allcsim(dependsOn: [wpilibcSim, gz_msgs, frc_gazebo_plugins]){ + description = 'wrapper task to build all c++ simulation tasks' + group = 'WPILib Simulation' +} + +task wpilibcSimCopy(type: Copy) { + description = 'copy headers and ntcore library to make simulation zip' + group = 'WPILib Simulation' + into "$simulationInstallDir" + + from ("$netTablesInclude"){ + into "include" + } + + from ("../hal/include"){ + into "include" + } + + from ("simulation/include"){ + into "include" + } + + from ("shared/include"){ + into "include" + } + + from ("$netLibDesktopLocation/libntcore.so") { + into "lib" + } +} + +build.dependsOn allcsim diff --git a/wpilibc/simulation/CMakeLists.txt b/wpilibc/simulation/CMakeLists.txt index 09c92330fc..769d7e284a 100644 --- a/wpilibc/simulation/CMakeLists.txt +++ b/wpilibc/simulation/CMakeLists.txt @@ -15,7 +15,6 @@ set (INCLUDE_FOLDERS include ${Boost_INCLUDE_DIR} ${GAZEBO_INCLUDE_DIRS}) - include_directories(${INCLUDE_FOLDERS}) link_directories(${NTCORE_LIBDIR}) @@ -23,3 +22,7 @@ link_directories(${NTCORE_LIBDIR}) add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${COM_SRC_FILES}) target_link_libraries(${PROJECT_NAME} gz_msgs ntcore) + +set_target_properties(${PROJECT_NAME} + PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${SIMULATION_INSTALL_DIR}/lib) diff --git a/wpilibj/simulation.gradle b/wpilibj/simulation.gradle index 543e866510..1bec695812 100644 --- a/wpilibj/simulation.gradle +++ b/wpilibj/simulation.gradle @@ -10,7 +10,8 @@ dependencies { } task wpilibjSimJar(type: Jar, dependsOn: simClasses) { - + description = 'Creates the WPILibJSimulation Jar' + group = 'WPILib Simulation' def addClasspath = { classpath -> classpath.files.findAll { it.exists() }.each { if (file(it).directory) { @@ -24,8 +25,6 @@ task wpilibjSimJar(type: Jar, dependsOn: simClasses) { addClasspath sourceSets.shared.runtimeClasspath addClasspath sourceSets.sim.runtimeClasspath - description = 'Creates the WPILibJSimulation Jar' - group = 'WPILib' from sourceSets.sim.output.classesDir from sourceSets.shared.output.classesDir baseName 'wpilibjSimulation' @@ -72,4 +71,12 @@ publishing { } } +//we need to move the simulation jars to the install directory +task copyJars(type: Copy) { + description = 'copy wpilibj simulation jar to make simulation zip' + group = 'WPILib Simulation' + from wpilibjSimJar.archivePath + into "$simulationInstallDir/jar" +} + build.dependsOn wpilibjSimJar