mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
Added BuiltInAccelerometer in Java and updated C++
Change-Id: I5a3360c51334e85da6a15fd640f9420bc3b64dca
This commit is contained in:
@@ -6,13 +6,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SensorBase.h"
|
#include "SensorBase.h"
|
||||||
|
#include "LiveWindow/LiveWindowSendable.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Built-in accelerometer.
|
* Built-in accelerometer.
|
||||||
*
|
*
|
||||||
* This class allows access to the RoboRIO's internal accelerometer.
|
* This class allows access to the RoboRIO's internal accelerometer.
|
||||||
*/
|
*/
|
||||||
class BuiltInAccelerometer : public SensorBase
|
class BuiltInAccelerometer : public SensorBase, public LiveWindowSendable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Range
|
enum Range
|
||||||
@@ -22,9 +23,18 @@ public:
|
|||||||
kRange_8G = 0x02,
|
kRange_8G = 0x02,
|
||||||
};
|
};
|
||||||
|
|
||||||
BuiltInAccelerometer(Range range = kRange_2G);
|
BuiltInAccelerometer(Range range = kRange_8G);
|
||||||
virtual ~BuiltInAccelerometer();
|
|
||||||
virtual double GetX() const;
|
virtual double GetX() const;
|
||||||
virtual double GetY() const;
|
virtual double GetY() const;
|
||||||
virtual double GetZ() const;
|
virtual double GetZ() const;
|
||||||
|
|
||||||
|
virtual std::string GetSmartDashboardType();
|
||||||
|
virtual void InitTable(ITable *subtable);
|
||||||
|
virtual void UpdateTable();
|
||||||
|
virtual ITable* GetTable();
|
||||||
|
virtual void StartLiveWindowMode() {}
|
||||||
|
virtual void StopLiveWindowMode() {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
ITable *m_table;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "AnalogModule.h"
|
#include "AnalogModule.h"
|
||||||
#include "AnalogTrigger.h"
|
#include "AnalogTrigger.h"
|
||||||
#include "AnalogTriggerOutput.h"
|
#include "AnalogTriggerOutput.h"
|
||||||
|
#include "BuiltInAccelerometer.h"
|
||||||
#include "Buttons/AnalogIOButton.h"
|
#include "Buttons/AnalogIOButton.h"
|
||||||
#include "Buttons/DigitalIOButton.h"
|
#include "Buttons/DigitalIOButton.h"
|
||||||
#include "Buttons/InternalButton.h"
|
#include "Buttons/InternalButton.h"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
* @param range The range the accelerometer will measure
|
* @param range The range the accelerometer will measure
|
||||||
*/
|
*/
|
||||||
BuiltInAccelerometer::BuiltInAccelerometer(Range range)
|
BuiltInAccelerometer::BuiltInAccelerometer(Range range)
|
||||||
|
: m_table(0)
|
||||||
{
|
{
|
||||||
setAccelerometerActive(false);
|
setAccelerometerActive(false);
|
||||||
setAccelerometerRange((AccelerometerRange)range);
|
setAccelerometerRange((AccelerometerRange)range);
|
||||||
@@ -20,14 +21,6 @@ BuiltInAccelerometer::BuiltInAccelerometer(Range range)
|
|||||||
HALReport(HALUsageReporting::kResourceType_Accelerometer, 0, 0, "Built-in accelerometer");
|
HALReport(HALUsageReporting::kResourceType_Accelerometer, 0, 0, "Built-in accelerometer");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor.
|
|
||||||
*/
|
|
||||||
BuiltInAccelerometer::~BuiltInAccelerometer()
|
|
||||||
{
|
|
||||||
setAccelerometerActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The acceleration of the RoboRIO along the X axis in g-forces
|
* @return The acceleration of the RoboRIO along the X axis in g-forces
|
||||||
*/
|
*/
|
||||||
@@ -51,3 +44,24 @@ double BuiltInAccelerometer::GetZ() const
|
|||||||
{
|
{
|
||||||
return getAccelerometerZ();
|
return getAccelerometerZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string BuiltInAccelerometer::GetSmartDashboardType() {
|
||||||
|
return "Accelerometer";
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuiltInAccelerometer::InitTable(ITable *subtable) {
|
||||||
|
m_table = subtable;
|
||||||
|
UpdateTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuiltInAccelerometer::UpdateTable() {
|
||||||
|
if (m_table != NULL) {
|
||||||
|
m_table->PutNumber("X", GetX());
|
||||||
|
m_table->PutNumber("Y", GetY());
|
||||||
|
m_table->PutNumber("Z", GetZ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ITable* BuiltInAccelerometer::GetTable() {
|
||||||
|
return m_table;
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Copyright (c) FIRST 2014. All Rights Reserved. */
|
||||||
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||||
|
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
package edu.wpi.first.wpilibj;
|
||||||
|
import edu.wpi.first.wpilibj.hal.AccelerometerJNI;
|
||||||
|
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType;
|
||||||
|
import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||||
|
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||||
|
import edu.wpi.first.wpilibj.livewindow.LiveWindowSendable;
|
||||||
|
import edu.wpi.first.wpilibj.parsing.ISensor;
|
||||||
|
import edu.wpi.first.wpilibj.tables.ITable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Built-in accelerometer.
|
||||||
|
*
|
||||||
|
* This class allows access to the RoboRIO's internal accelerometer.
|
||||||
|
*/
|
||||||
|
public class BuiltInAccelerometer implements ISensor, LiveWindowSendable
|
||||||
|
{
|
||||||
|
public enum Range { k2G, k4G, k8G }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* @param range The range the accelerometer will measure
|
||||||
|
*/
|
||||||
|
public BuiltInAccelerometer(Range range) {
|
||||||
|
AccelerometerJNI.setAccelerometerActive(false);
|
||||||
|
|
||||||
|
switch(range) {
|
||||||
|
case k2G:
|
||||||
|
AccelerometerJNI.setAccelerometerRange(0);
|
||||||
|
break;
|
||||||
|
case k4G:
|
||||||
|
AccelerometerJNI.setAccelerometerRange(1);
|
||||||
|
break;
|
||||||
|
case k8G:
|
||||||
|
AccelerometerJNI.setAccelerometerRange(2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
AccelerometerJNI.setAccelerometerActive(true);
|
||||||
|
|
||||||
|
UsageReporting.report(tResourceType.kResourceType_Accelerometer, 0, 0, "Built-in accelerometer");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
* The accelerometer will measure +/-8 g-forces
|
||||||
|
*/
|
||||||
|
public BuiltInAccelerometer() {
|
||||||
|
this(Range.k8G);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The acceleration of the RoboRIO along the X axis in g-forces
|
||||||
|
*/
|
||||||
|
public double getX() {
|
||||||
|
return AccelerometerJNI.getAccelerometerX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The acceleration of the RoboRIO along the Y axis in g-forces
|
||||||
|
*/
|
||||||
|
public double getY() {
|
||||||
|
return AccelerometerJNI.getAccelerometerY();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The acceleration of the RoboRIO along the Z axis in g-forces
|
||||||
|
*/
|
||||||
|
public double getZ() {
|
||||||
|
return AccelerometerJNI.getAccelerometerZ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSmartDashboardType(){
|
||||||
|
return "Accelerometer";
|
||||||
|
}
|
||||||
|
|
||||||
|
private ITable m_table;
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
public void initTable(ITable subtable) {
|
||||||
|
m_table = subtable;
|
||||||
|
updateTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
public void updateTable() {
|
||||||
|
if (m_table != null) {
|
||||||
|
m_table.putNumber("X", getX());
|
||||||
|
m_table.putNumber("Y", getY());
|
||||||
|
m_table.putNumber("Z", getZ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
public ITable getTable(){
|
||||||
|
return m_table;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startLiveWindowMode() {}
|
||||||
|
public void stopLiveWindowMode() {}
|
||||||
|
};
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package edu.wpi.first.wpilibj.hal;
|
||||||
|
|
||||||
|
public class AccelerometerJNI extends JNIWrapper {
|
||||||
|
public static native void setAccelerometerActive(boolean active);
|
||||||
|
public static native void setAccelerometerRange(int range);
|
||||||
|
public static native double getAccelerometerX();
|
||||||
|
public static native double getAccelerometerY();
|
||||||
|
public static native double getAccelerometerZ();
|
||||||
|
}
|
||||||
58
wpilibj/wpilibJavaJNI/lib/AccelerometerJNI.cpp
Normal file
58
wpilibj/wpilibJavaJNI/lib/AccelerometerJNI.cpp
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#include <jni.h>
|
||||||
|
#include "edu_wpi_first_wpilibj_hal_AccelerometerJNI.h"
|
||||||
|
#include "HAL/Accelerometer.hpp"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI
|
||||||
|
* Method: setAccelerometerActive
|
||||||
|
* Signature: (Z)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_setAccelerometerActive
|
||||||
|
(JNIEnv *, jclass, jboolean active)
|
||||||
|
{
|
||||||
|
setAccelerometerActive(active);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI
|
||||||
|
* Method: setAccelerometerRange
|
||||||
|
* Signature: (I)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_setAccelerometerRange
|
||||||
|
(JNIEnv *, jclass, jint range)
|
||||||
|
{
|
||||||
|
setAccelerometerRange((AccelerometerRange)range);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI
|
||||||
|
* Method: getAccelerometerX
|
||||||
|
* Signature: ()D
|
||||||
|
*/
|
||||||
|
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_getAccelerometerX
|
||||||
|
(JNIEnv *, jclass)
|
||||||
|
{
|
||||||
|
return getAccelerometerX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI
|
||||||
|
* Method: getAccelerometerY
|
||||||
|
* Signature: ()D
|
||||||
|
*/
|
||||||
|
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_getAccelerometerY
|
||||||
|
(JNIEnv *, jclass)
|
||||||
|
{
|
||||||
|
return getAccelerometerY();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: edu_wpi_first_wpilibj_hal_AccelerometerJNI
|
||||||
|
* Method: getAccelerometerZ
|
||||||
|
* Signature: ()D
|
||||||
|
*/
|
||||||
|
JNIEXPORT jdouble JNICALL Java_edu_wpi_first_wpilibj_hal_AccelerometerJNI_getAccelerometerZ
|
||||||
|
(JNIEnv *, jclass)
|
||||||
|
{
|
||||||
|
return getAccelerometerZ();
|
||||||
|
}
|
||||||
@@ -20,10 +20,10 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
||||||
</repositories>
|
</repositories>
|
||||||
<pluginRepositories>
|
<pluginRepositories>
|
||||||
|
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
<properties>
|
<properties>
|
||||||
<embeddedJDKHome>${user.home}${file.separator}jdk-linux-arm-vfp-sflt${file.separator}jdk1.7.0_45</embeddedJDKHome>
|
<embeddedJDKHome>${user.home}${file.separator}jdk-linux-arm-vfp-sflt${file.separator}jdk1.7.0_45</embeddedJDKHome>
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
<file>${embeddedJDKIncludePath}</file>
|
<file>${embeddedJDKIncludePath}</file>
|
||||||
</files>
|
</files>
|
||||||
<message>A copy of the 'Linux ARM v6/v7 Soft Float ABI' JDK must be extracted to '${embeddedJDKHome}' and
|
<message>A copy of the 'Linux ARM v6/v7 Soft Float ABI' JDK must be extracted to '${embeddedJDKHome}' and
|
||||||
the folder '${embeddedJDKIncludePath}' must exist to build this module. You must use Java 7 u45. This JDK may be downloaded from
|
the folder '${embeddedJDKIncludePath}' must exist to build this module. You must use Java 7 u45. This JDK may be downloaded from
|
||||||
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html#jdk-7u45-oth-JPR. To override
|
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html#jdk-7u45-oth-JPR. To override
|
||||||
this default location, specify a value for the 'embeddedJDKHome' property at the command line, like 'mvn -DembeddedJDKHome=path/to/jdk'</message>
|
this default location, specify a value for the 'embeddedJDKHome' property at the command line, like 'mvn -DembeddedJDKHome=path/to/jdk'</message>
|
||||||
</requireFilesExist>
|
</requireFilesExist>
|
||||||
@@ -113,6 +113,7 @@ this default location, specify a value for the 'embeddedJDKHome' property at the
|
|||||||
<javahClassName>edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary</javahClassName>
|
<javahClassName>edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary</javahClassName>
|
||||||
<javahClassName>edu.wpi.first.wpilibj.hal.HALUtil</javahClassName>
|
<javahClassName>edu.wpi.first.wpilibj.hal.HALUtil</javahClassName>
|
||||||
<javahClassName>edu.wpi.first.wpilibj.hal.JNIWrapper</javahClassName>
|
<javahClassName>edu.wpi.first.wpilibj.hal.JNIWrapper</javahClassName>
|
||||||
|
<javahClassName>edu.wpi.first.wpilibj.hal.AccelerometerJNI</javahClassName>
|
||||||
<javahClassName>edu.wpi.first.wpilibj.hal.AnalogJNI</javahClassName>
|
<javahClassName>edu.wpi.first.wpilibj.hal.AnalogJNI</javahClassName>
|
||||||
<javahClassName>edu.wpi.first.wpilibj.hal.CounterJNI</javahClassName>
|
<javahClassName>edu.wpi.first.wpilibj.hal.CounterJNI</javahClassName>
|
||||||
<javahClassName>edu.wpi.first.wpilibj.hal.DIOJNI</javahClassName>
|
<javahClassName>edu.wpi.first.wpilibj.hal.DIOJNI</javahClassName>
|
||||||
@@ -128,7 +129,7 @@ this default location, specify a value for the 'embeddedJDKHome' property at the
|
|||||||
</javahClassNames>
|
</javahClassNames>
|
||||||
<!-- enable additional javah interface in dependencies list -->
|
<!-- enable additional javah interface in dependencies list -->
|
||||||
<!-- javahSearchJNIFromDependencies>true</javahSearchJNIFromDependencies -->
|
<!-- javahSearchJNIFromDependencies>true</javahSearchJNIFromDependencies -->
|
||||||
<!--
|
<!--
|
||||||
| Add jdk include directories to system include path
|
| Add jdk include directories to system include path
|
||||||
| Override ${jkdIncludePath} If your jdk does not conform to Sun JDK layout
|
| Override ${jkdIncludePath} If your jdk does not conform to Sun JDK layout
|
||||||
-->
|
-->
|
||||||
@@ -242,7 +243,7 @@ this default location, specify a value for the 'embeddedJDKHome' property at the
|
|||||||
</then>
|
</then>
|
||||||
<else>
|
<else>
|
||||||
<copy todir="${project.build.directory}" >
|
<copy todir="${project.build.directory}" >
|
||||||
<fileset dir="${mvn.cpp-root.zip.path}" />
|
<fileset dir="${mvn.cpp-root.zip.path}" />
|
||||||
</copy>
|
</copy>
|
||||||
</else>
|
</else>
|
||||||
</if>
|
</if>
|
||||||
|
|||||||
Reference in New Issue
Block a user