Skip to content

Set get yaw example #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
293 changes: 293 additions & 0 deletions C++/PigeonSetGetYawC++/.cproject

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions C++/PigeonSetGetYawC++/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PigeonSetGetYawC++</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>edu.wpi.first.wpilib.plugins.core.nature.FRCProjectNature</nature>
</natures>
</projectDescription>
36 changes: 36 additions & 0 deletions C++/PigeonSetGetYawC++/.settings/language.settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="cdt.managedbuild.config.gnu.cross.exe.debug.1104744751" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1345929325569682115" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="cdt.managedbuild.config.gnu.cross.exe.debug.1104744751.2017904325" name="linux_simulate">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="36374163183" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
<configuration id="cdt.managedbuild.config.gnu.mingw.exe.debug.912379410.387599128" name="Windows Simulate">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1687629054637893" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
eclipse.preferences.version=1
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/CPATH/delimiter=;
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/CPATH/operation=remove
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/CPLUS_INCLUDE_PATH/delimiter=;
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/CPLUS_INCLUDE_PATH/operation=remove
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/C_INCLUDE_PATH/delimiter=;
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/C_INCLUDE_PATH/operation=remove
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/append=true
environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/appendContributed=true
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/LIBRARY_PATH/delimiter=;
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/LIBRARY_PATH/operation=remove
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/append=true
environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.cross.exe.debug.1104744751/appendContributed=true
11 changes: 11 additions & 0 deletions C++/PigeonSetGetYawC++/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Build information
out=FRCUserProgram
src.dir=src
build.dir=build
out.exe=Debug/${out}

# Simulation
simulation.world.file=/usr/share/frcsim/worlds/GearsBotDemo.world

# Use the current C++ library by default
cpp-version=current
28 changes: 28 additions & 0 deletions C++/PigeonSetGetYawC++/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<project name="FRC Deployment" default="deploy">

<!--
The following properties can be defined to override system level
settings. These should not be touched unless you know what you're
doing. The primary use is to override the wpilib version when
working with older robots that can't compile with the latest
libraries.
-->

<!-- By default the system version of WPI is used -->
<!-- <property name="version" value=""/> -->

<!-- By default the system team number is used -->
<!-- <property name="team-number" value=""/> -->

<!-- By default the target is set to 10.TE.AM.2 -->
<!-- <property name="target" value=""/> -->

<property file="${user.home}/wpilib/wpilib.properties"/>
<property file="build.properties"/>
<property file="${user.home}/wpilib/cpp/${version}/ant/build.properties"/>

<import file="${wpilib.ant.dir}/build.xml"/>

</project>
59 changes: 59 additions & 0 deletions C++/PigeonSetGetYawC++/src/Robot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <stdio.h>
#include "ctre/Phoenix.h"
#include "Joystick.h"
#include <IterativeRobot.h>

class Robot: public frc::IterativeRobot {
public:
//This can be changed to an pigeon plugged into a talon with a ribbon cable by instantating a talon
//and passing that talon object into the pigeon constructor.

PigeonIMU * _imu = new PigeonIMU(3);

Joystick * _joystick = new Joystick(0);

bool _lastButton1 = false;
bool _lastButton2 = false;
bool _lastButton3 = false;

double _lastSetYaw = 0;

void TeleopInit() {
_imu->SetYaw(0);
}

void TeleopPeriodic() {

//Set or Add yaw in degrees based on joystick
double yaw = 180 * _joystick->GetRawAxis(1);

if(_joystick->GetRawButton(1) && !_lastButton1) {
double ypr_deg[] = {0, 0, 0};

_imu->GetYawPitchRoll(ypr_deg);
printf("yaw: %f last set yaw: %f\n", ypr_deg[0], _lastSetYaw);
}

if(_joystick->GetRawButton(2) && !_lastButton2) {
_imu->SetYaw(yaw, 30);
_lastSetYaw = yaw;
printf("Set yaw to: %f\n", yaw);
}

if(_joystick->GetRawButton(3) && !_lastButton3) {
double ypr_deg[] = {0, 0, 0};

_imu->GetYawPitchRoll(ypr_deg);

_imu->AddYaw(yaw, 30);

_lastSetYaw = ypr_deg[0] + yaw;
printf("Added %f to yaw\n", yaw);
}
_lastButton1 = _joystick->GetRawButton(1);
_lastButton2 = _joystick->GetRawButton(2);
_lastButton3 = _joystick->GetRawButton(3);
}
};

START_ROBOT_CLASS(Robot)
22 changes: 22 additions & 0 deletions HERO C#/PigeonGetSetYaw/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Phoenix Software License Agreement
*
* Copyright (C) Cross The Road Electronics. All rights
* reserved.
*
* Cross The Road Electronics (CTRE) licenses to you the right to
* use, publish, and distribute copies of CRF (Cross The Road) firmware files (*.crf) and
* Phoenix Software API Libraries ONLY when in use with CTR Electronics hardware products.
*
* THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
* WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
* LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* CROSS THE ROAD ELECTRONICS BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
* PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
* BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
* THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
* SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
* (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE
*/
50 changes: 50 additions & 0 deletions HERO C#/PigeonGetSetYaw/PigeonGetSetYaw.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AssemblyName>PigeonGetSetYaw</AssemblyName>
<OutputType>Exe</OutputType>
<RootNamespace>Top</RootNamespace>
<ProjectTypeGuids>{b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{FD578599-D937-45DE-8426-8A0496775D6B}</ProjectGuid>
<TargetFrameworkVersion>v4.4</TargetFrameworkVersion>
<NetMfTargetsBaseDir Condition="'$(NetMfTargetsBaseDir)'==''">$(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\</NetMfTargetsBaseDir>
<DeployDevice>Cross Link HERO .NETMF_Mini-USB</DeployDevice>
<DeployTransport>USB</DeployTransport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<Import Project="$(NetMfTargetsBaseDir)$(TargetFrameworkVersion)\CSharp.Targets" />
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="CTRE, Version=5.1.5.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="ctre_netmf_native">
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.SPOT.Graphics" />
<Reference Include="Microsoft.SPOT.Hardware" />
<Reference Include="Microsoft.SPOT.Native" />
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions HERO C#/PigeonGetSetYaw/PigeonGetSetYaw.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PigeonGetSetYaw", "PigeonGetSetYaw.csproj", "{FD578599-D937-45DE-8426-8A0496775D6B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FD578599-D937-45DE-8426-8A0496775D6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD578599-D937-45DE-8426-8A0496775D6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD578599-D937-45DE-8426-8A0496775D6B}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{FD578599-D937-45DE-8426-8A0496775D6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD578599-D937-45DE-8426-8A0496775D6B}.Release|Any CPU.Build.0 = Release|Any CPU
{FD578599-D937-45DE-8426-8A0496775D6B}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C42EC366-E98E-4DCC-B494-0500E6601A0B}
EndGlobalSection
EndGlobal
89 changes: 89 additions & 0 deletions HERO C#/PigeonGetSetYaw/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* A quick example on getting and setting the yaw of a pigeon
*
* This assumes the pigeon is directly connected over CAN. This example prints to console and requires the use of a
* gamepad.
*/

using CTRE.Phoenix;
using Microsoft.SPOT;
using CTRE.Phoenix.Controller;
using CTRE.Phoenix.Sensors;
using System.Threading;

namespace PigeonGetSetYaw
{
public class Program
{
static RobotApplication _robotApp = new RobotApplication();

public static void Main()
{
_robotApp.init();

while (true)
{
_robotApp.run();

Thread.Sleep(10);
}
}
}

public class RobotApplication
{
/* any system wide initializations here */
PigeonIMU _imu = new PigeonIMU(3);
GameController _joystick = new GameController(UsbHostDevice.GetInstance());

bool _lastButton1 = false;
bool _lastButton2 = false;
bool _lastButton3 = false;

float _lastSetYaw = 0;

public void init()
{
_imu.SetYaw(0, 30);
}


/* loop forever */
public void run()
{
//Set or Add yaw in degrees based on joystick
float yaw = 180 * _joystick.GetAxis(0);
if (_joystick.GetButton(1) && !_lastButton1)
{
float[] ypr_deg = { 0, 0, 0 };
_imu.GetYawPitchRoll(ypr_deg);
Debug.Print("yaw: " + ypr_deg[0].ToString() + " last set yaw: " + _lastSetYaw.ToString());
}

if (_joystick.GetButton(2) && !_lastButton2)
{
_imu.SetYaw(yaw, 30);
_lastSetYaw = yaw;
Debug.Print("Set yaw to: " + yaw.ToString());
}

if (_joystick.GetButton(3) && !_lastButton3)
{
float[] ypr_deg = { 0, 0, 0 };

_imu.GetYawPitchRoll(ypr_deg);

_imu.AddYaw(yaw, 30);

_lastSetYaw = ypr_deg[0] + yaw;
Debug.Print("Added " + yaw.ToString() + " to yaw");
}
_lastButton1 = _joystick.GetButton(1);
_lastButton2 = _joystick.GetButton(2);
_lastButton3 = _joystick.GetButton(3);

}
}


}
Loading