mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[examples] Add AnalogAccelerometer snippets
Delete AnalogAccelerometer comments about sensitivity and zero constants that don't exist
This commit is contained in:
committed by
Peter Johnson
parent
cc8eaf3ed7
commit
b7cd03adc4
@@ -74,7 +74,7 @@ def tagList = [
|
||||
/* --- Hardware --- */
|
||||
"Analog", "Ultrasonic", "Gyro", "Pneumatics", "I2C", "Duty Cycle", "PDP", "DMA", "Relay",
|
||||
"AddressableLEDs", "HAL", "Encoder", "Smart Motor Controller", "Digital Input",
|
||||
"Digital Output",
|
||||
"Digital Output", "Accelerometer",
|
||||
|
||||
/* --- HID --- */
|
||||
"XboxController", "PS4Controller", "PS5Controller", "Joystick",
|
||||
|
||||
@@ -75,8 +75,7 @@ class AnalogAccelerometer : public wpi::Sendable,
|
||||
* Set the accelerometer sensitivity.
|
||||
*
|
||||
* This sets the sensitivity of the accelerometer used for calculating the
|
||||
* acceleration. The sensitivity varies by accelerometer model. There are
|
||||
* constants defined for various models.
|
||||
* acceleration. The sensitivity varies by accelerometer model.
|
||||
*
|
||||
* @param sensitivity The sensitivity of accelerometer in Volts per G.
|
||||
*/
|
||||
@@ -85,8 +84,7 @@ class AnalogAccelerometer : public wpi::Sendable,
|
||||
/**
|
||||
* Set the voltage that corresponds to 0 G.
|
||||
*
|
||||
* The zero G voltage varies by accelerometer model. There are constants
|
||||
* defined for various models.
|
||||
* The zero G voltage varies by accelerometer model.
|
||||
*
|
||||
* @param zero The zero G voltage.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <frc/AnalogAccelerometer.h>
|
||||
#include <frc/AnalogInput.h>
|
||||
#include <frc/TimedRobot.h>
|
||||
|
||||
/**
|
||||
* AnalogAccelerometer snippets for frc-docs.
|
||||
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/accelerometers-software.html
|
||||
*/
|
||||
class Robot : public frc::TimedRobot {
|
||||
public:
|
||||
Robot() {
|
||||
// Sets the sensitivity of the accelerometer to 1 volt per G
|
||||
m_accelerometer.SetSensitivity(1);
|
||||
// Sets the zero voltage of the accelerometer to 3 volts
|
||||
m_accelerometer.SetZero(3);
|
||||
}
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
// Gets the current acceleration
|
||||
m_accelerometer.GetAcceleration();
|
||||
}
|
||||
|
||||
private:
|
||||
// Creates an analog accelerometer on analog input 0
|
||||
frc::AnalogAccelerometer m_accelerometer{0};
|
||||
};
|
||||
|
||||
#ifndef RUNNING_FRC_TESTS
|
||||
int main() {
|
||||
return frc::StartRobot<Robot>();
|
||||
}
|
||||
#endif
|
||||
@@ -103,5 +103,16 @@
|
||||
],
|
||||
"foldername": "AnalogPotentiometer",
|
||||
"gradlebase": "cpp"
|
||||
},
|
||||
{
|
||||
"name": "AnalogAccelerometer",
|
||||
"description": "Snippets of Analog Accelerometer for frc-docs.",
|
||||
"tags": [
|
||||
"Hardware",
|
||||
"Analog",
|
||||
"Accelerometer"
|
||||
],
|
||||
"foldername": "AnalogAccelerometer",
|
||||
"gradlebase": "cpp"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -91,7 +91,7 @@ public class AnalogAccelerometer implements Sendable, AutoCloseable {
|
||||
* Set the accelerometer sensitivity.
|
||||
*
|
||||
* <p>This sets the sensitivity of the accelerometer used for calculating the acceleration. The
|
||||
* sensitivity varies by accelerometer model. There are constants defined for various models.
|
||||
* sensitivity varies by accelerometer model.
|
||||
*
|
||||
* @param sensitivity The sensitivity of accelerometer in Volts per G.
|
||||
*/
|
||||
@@ -102,8 +102,7 @@ public class AnalogAccelerometer implements Sendable, AutoCloseable {
|
||||
/**
|
||||
* Set the voltage that corresponds to 0 G.
|
||||
*
|
||||
* <p>The zero G voltage varies by accelerometer model. There are constants defined for various
|
||||
* models.
|
||||
* <p>The zero G voltage varies by accelerometer model.
|
||||
*
|
||||
* @param zero The zero G voltage.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.snippets.analogaccelerometer;
|
||||
|
||||
import edu.wpi.first.wpilibj.RobotBase;
|
||||
|
||||
/**
|
||||
* Do NOT add any static variables to this class, or any initialization at all. Unless you know what
|
||||
* you are doing, do not modify this file except to change the parameter class to the startRobot
|
||||
* call.
|
||||
*/
|
||||
public final class Main {
|
||||
private Main() {}
|
||||
|
||||
/**
|
||||
* Main initialization function. Do not perform any initialization here.
|
||||
*
|
||||
* <p>If you change your main robot class, change the parameter type.
|
||||
*/
|
||||
public static void main(String... args) {
|
||||
RobotBase.startRobot(Robot::new);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.snippets.analogaccelerometer;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogAccelerometer;
|
||||
import edu.wpi.first.wpilibj.TimedRobot;
|
||||
|
||||
/**
|
||||
* AnalogAccelerometer snippets for frc-docs.
|
||||
* https://docs.wpilib.org/en/stable/docs/software/hardware-apis/sensors/accelerometers-software.html
|
||||
*/
|
||||
public class Robot extends TimedRobot {
|
||||
// Creates an analog accelerometer on analog input 0
|
||||
AnalogAccelerometer m_accelerometer = new AnalogAccelerometer(0);
|
||||
|
||||
/** Called once at the beginning of the robot program. */
|
||||
public Robot() {
|
||||
// Sets the sensitivity of the accelerometer to 1 volt per G
|
||||
m_accelerometer.setSensitivity(1);
|
||||
// Sets the zero voltage of the accelerometer to 3 volts
|
||||
m_accelerometer.setZero(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleopPeriodic() {
|
||||
// Gets the current acceleration
|
||||
m_accelerometer.getAcceleration();
|
||||
}
|
||||
}
|
||||
@@ -113,5 +113,17 @@
|
||||
"foldername": "analogpotentiometer",
|
||||
"gradlebase": "java",
|
||||
"mainclass": "Main"
|
||||
},
|
||||
{
|
||||
"name": "AnalogAccelerometer",
|
||||
"description": "Snippets of Analog Accelerometer for frc-docs.",
|
||||
"tags": [
|
||||
"Hardware",
|
||||
"Analog",
|
||||
"Accelerometer"
|
||||
],
|
||||
"foldername": "analogaccelerometer",
|
||||
"gradlebase": "java",
|
||||
"mainclass": "Main"
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user