Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
frc::Jaguar exampleJaguar{0};
frc::Talon exampleTalon{1};
frc::TalonSRX exampleTalonSRX{2};
frc::Victor exampleVictor{11};
frc::VictorSP exampleVictorSP{12};Jaguar exampleJaguar = new Jaguar(0);
Talon exampleTalon = new Talon(1);
TalonSRX exampleTalonSRX = new TalonSRX(2);
Victor exampleVictor = new Victor(11);
VictorSP exampleVictorSP = new VictorSP(12);frc::Jaguar exampleJaguar{0};
exampleJaguar.EnableDeadbandElimination(true);Jaguar exampleJaguar = new Jaguar(0);
exampleJaguar.enableDeadbandElimination(true);frc::Jaguar exampleJaguar{0};
exampleJaguar.Set(0.7);Jaguar exampleJaguar = new Jaguar(0);
exampleJaguar.set(0.7);class Robot
{
public:
frc::Spark m_left{1};
frc::Spark m_right{2};
frc::DifferentialDrive m_drive{m_left, m_right};public class Robot
{
Spark m_left = new Spark(1);
Spark m_right = new Spark(2);
DifferentialDrive m_drive = new DifferentialDrive(m_left, m_right);class Robot
{
public:
frc::Spark m_frontLeft{1};
frc::Spark m_rearLeft{2};
frc::SpeedControllerGroup m_left{m_frontLeft, m_rearLeft};
frc::Spark m_frontRight{3};
frc::Spark m_rearRight{4};
frc::SpeedControllerGroup m_right{m_frontRight, m_rearRight};
frc::DifferentialDrive m_drive{m_left, m_right};public class Robot
{
Spark m_frontLeft = new Spark(1);
Spark m_rearLeft = new Spark(2);
SpeedControllerGroup m_left = new SpeedControllerGroup(m_frontLeft, m_rearLeft);
Spark m_frontRight = new Spark(3);
Spark m_rearRight = new Spark(4);
SpeedControllerGroup m_Right = new SpeedControllerGroup(m_frontRight, m_rearRight);
DifferentialDrive m_drive = new DifferentialDrive(m_left, m_right);class Robot: public frc::TimedRobot
{
//Object construction
void TeleopPeriodic() override {
myDrive.TankDrive(leftStick.GetY(), rightStick.GetY());
}
}public class RobotTemplate extends TimedRobot
{
//Object construction
public void teleopPeriodic() {
myDrive.tankDrive(leftStick.getY(), rightStick.getY());
}
}class Robot: public frc::TimedRobot
{
//Object construction
void TeleopPeriodic() override {
myDrive.ArcadeDrive(driveStick.GetY(), driveStick.GetX());
}
}public class RobotTemplate extends TimedRobot
{
//Object construction
public void teleopPeriodic() {
myDrive.arcadeDrive(driveStick.getY(), driveStick.getX());
}
}class Robot: public frc::TimedRobot
{
//Object construction
void TeleopPeriodic() override {
myDrive.CurvatureDrive(driveStick.GetY(), driveStick.GetX(), driveStick.GetButton(1));
}
}public class RobotTemplate extends TimedRobot
{
//Object construction
public void teleopPeriodic() {
myDrive.curvatureDrive(driveStick.getY(), driveStick.getX(), driveStick.GetButton(1));
}
}#include "WPILib.h"
/**
* Simplest program to drive a robot with mecanum drive using a single Logitech
* Extreme 3D Pro joystick and 4 drive motors connected as follows:
* - PWM 0 - Connected to front left drive motor
* - PWM 1 - Connected to rear left drive motor
* - PWM 2 - Connected to front right drive motor
* - PWM 3 - Connected to rear right drive motor
*/
class MecanumDefaultCode : public frc::TimedRobot
{
frc::Spark m_frontLeft{0};
frc::Spark m_rearLeft{1};
frc::Spark m_frontRight{2};
frc::Spark m_rearRight{3};
frc::MecanumDrive m_drive{m_frontLeft, m_rearLeft, m_frontRight, m_rearRight};
frc::Joystick m_driveStick{1};
/**
* Gets called once for each new packet from the DS.
*/
void TeleopPeriodic override (void)
{
m_robotDrive.MecanumDrive_Cartesian(m_driveStick.GetX(), m_driveStick.GetY(), m_driveStick.GetZ());
}
};
START_ROBOT_CLASS(MecanumDefaultCode);import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.TimedRobot;
/*
* Simplest program to drive a robot with mecanum drive using a single Logitech
* Extreme 3D Pro joystick and 4 drive motors connected as follows:
* - PWM 0 - Connected to front left drive motor
* - PWM 1 - Connected to rear left drive motor
* - PWM 2 - Connected to front right drive motor
* - PWM 3 - Connected to rear right drive motor
*/
public class MecanumDefaultCode extends TimedRobot {
//Create a robot drive object using PWMs 0, 1, 2 and 3
Spark m_frontLeft = new Spark(1);
Spark m_rearLeft = new Spark(2);
Spark m_frontRight = new Spark(3);
Spark m_rearRight = new Spark(4);
//Define joystick being used at USB port 1 on the Driver Station
Joystick m_driveStick = new Joystick(1);
public void teleopPeriodic()
{
m_robotDrive.mecanumDrive_Cartesian(m_driveStick.getX(), m_driveStick.getY(), m_driveStick.getZ());
}
}m_robotDrive.MecanumDrive_Cartesian(m_driveStick.GetX(), m_driveStick.GetY(), m_driveStick.GetZ(), m_gyro.GetAngle());m_robotDrive.mecanumDrive_Cartesian(m_driveStick.getX(), m_driveStick.getY(), m_driveStick.getZ(), m_gyro.getAngle());C++
Servo *exampleServo = new Servo(1);Java
Servo exampleServo = new Servo(1);
C++
exampleServo->Set(.5);
exampleServo->SetAngle(75);
Java
exampleServo.set(.5);
exampleServo.setAngle(75);C++
Relay *exampleRelay = new Relay(1);
Relay *exampleRelay = new Relay(1, Relay::Value::kForward)
exampleRelay->Set(Relay::Value::kOn);
exampleRelay->Set(Relay::Value::kForward);
Java
exampleRelay = new Relay(1);
exampleRelay = new Relay(1, Relay.Value.kForward);
exampleRelay.set(Relay.Value.kOn);
exampleRelay.set(Relay.Value.kForward);
Compressor *c = new Compressor(0);
c->SetClosedLoopControl(true);
c->SetClosedLoopControl(false);
Compressor c = new Compressor(0);
c.setClosedLoopControl(true);
c.setClosedLoopControl(false);bool enabled = c->Enabled();
bool pressureSwitch = c->GetPressureSwitchValue();
double current = c->GetCompressorCurrent();
boolean enabled = c.enabled();
boolean pressureSwitch = c.getPressureSwitchValue();
double current = c.getCompressorCurrent();frc::Solenoid exampleSolenoid {1};
exampleSolenoid.Set(true);
exampleSolenoid.Set(false);
Solenoid exampleSolenoid = new Solenoid(1);
exampleSolenoid.set(true);
exampleSolenoid.set(false);frc::DoubleSolenoid exampleDouble {1, 2};
exampleDouble.Set(frc::DoubleSolenoid::Value::kOff);
exampleDouble.Set(frc::DoubleSolenoid::Value::kForward);
exampleDouble.Set(frc::DoubleSolenoid::Value::kReverse);
DoubleSolenoid exampleDouble = new DoubleSolenoid(1, 2);
exampleDouble.set(DoubleSolenoid.Value.kOff);
exampleDouble.set(DoubleSolenoid.Value.kForward);
exampleDouble.set(DoubleSolenoid.Value.kReverse);



public void autonomousInit() { //Bu metod her zaman robot otonom moda girdiginde baslar
timer.reset(); // zamanlayiciyi resetle
timer.start(); // saymaya başla
}
public void autonomousPeriodic() { //Bu metod robot otonom modun enable olduguna dair bir paket aldiginda calismaya baslar
// 2 saniye boyunca robotu sur
if (timer.get() < 2.0) {
myRobot.drive(-0.5, 0.0); // robotu yarim hizda ileri sur
} else {
myRobot.drive(0.0, 0.0); // Robotu durdur
}
}//Programın ihtiyac duydugu diger dosyalari ice aktarir
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
public class Robot extends IterativeRobot {
//Robot classimiz icin degiskenler tanimlar
RobotDrive myRobot;
Joystick stick;
Timer timer;
//Robot init yönetimindeki degiskenleri cagirir robot basladiginda ilk bu komutlar calisir
public void robotInit() {
myRobot = new RobotDrive(0,1); //myRobot adinda robotumuzu haraket ettirecek kutuphaneyi cagirdik 0,1 robotumuzun tekerleklerinin bagli oldugu pwm numaralaridir 4 teker kullanıyorsanız 0,1,2,3 seklinde degistirebilirsiniz
stick = new Joystick(1); //stick adinda joystick veya xbox kullanmamiza olanak saglayacak kutuphaneyi cagiriyoruz 1 kullandiginiz kolun takili oldugu usb portudur driver station uzerinden gorebilir ve ayarlayabilirsiniz
timer = new Timer(); // timer adinda bir zamanlayici kullanmamiza olanak saglayacak kutuphaneyi cagiriyoruz
}
}public void teleopInit() {// teleopInit metodu her zaman teleop moduna girdiginizde cagrilir
}
public void teleopPeriodic() { // teleperiodic metodu robotun enable olduguna dair bir paket aldiginda calismaya baslar
myRobot.arcadeDrive(stick); //Bu kod robota tanimladiginiz joystick ile motorlari surmenizi saglar
}
public void testPeriodic() {
LiveWindow.run();
}
//Test Modu, robot işlevselliğini test etmek için kullanılır.Programımızın test modu LiveWindow'u çalıştırır. LiveWindow, Robot Test Modundayken, robot üzerindeki kontrol panelindeki girişleri ve kontrol çıkışlarını görmenizi sağlayan SmartDashboard'un bir parçasıdır.SmartDashboard bölümünde LiveWindow hakkında daha fazla bilgi edinebilirsiniz.Bu içeriğin gelişmesine katkı sağladığı için 6064 Istanbulls takımına teşekkür ederiz.
Bu içeriğin oluşumuna öncülük yaptığı için Sneaky Sneakes 7285 takımına teşekkür ederiz.
buradan takımların geçmiş yıllara ait iş planlarını bulabilirsiniz.

Bu içeriğe destek sağladığı için 6025 Adroit Androids takımına teşekkür ederiz.
buradan takımların geçmiş yıllara ait ödül yazılarını bulabilirsiniz.

Yaşadıkları problemleri ve çözümleri bizlere aktaran #6038 ITOBOT takımına ve #6025 Adroit Anroids takımına teşekkürler!



camera = cv2.VideoCapture(0) # webcamin bagli oldugu port varsayilan 0





id "edu.wpi.first.GradleRIO" version "2019.1.1"{
"enableCppIntellisense": false,
"currentLanguage": "java",
"projectYear": "2019", //yarışma senesi
"teamNumber": 6874 //takım numarası
}plugins {
//...
id 'idea' //Eğer IntelliJ IDEA kullanacaksanız
id 'eclipse' //Eğer Eclipse kullanacaksanız
}task wrapper(type: Wrapper) {
gradleVersion = '5.0'
}id "edu.wpi.first.GradleRIO" version "2019.1.1"




import numpy as np
from PIL import ImageGrab
from collections import deque
from networktables import NetworkTables
import cv2
import time
import imutils
import argparse
import cv2 as CV
x = 0 #programın ileride hata vermemesi için x 0 olarak tanımlıyorum
y = 0 # programın ileride hata vermemesi için y 0 olarak tanımlıyorum
NetworkTables.initialize(server='roborio-6025-frc.local') # Roborio ile iletişim kuruyoruz
table = NetworkTables.getTable("Vision") # table oluşturuyoruz
#sari rengin algilanmasi
colorLower = (24, 100, 100)
colorUpper = (44, 255, 255)
#converter.py ile convert ettiğiniz rengi buraya giriniz
def screen_record():
x = 0
y = 0
r = 0
last_time = time.time()
while(True):
# 800x600 windowed mode
printscreen = np.array(ImageGrab.grab(bbox=(0,40,1024,768)))
print('Tekrarlanma süresi : {} saniye'.format(time.time()-last_time))
last_time = time.time()
frame = printscreen
frame = imutils.resize(frame, width=600)
frame = imutils.rotate(frame, angle=0)
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, colorLower, colorUpper)
mask = cv2.erode(mask, None, iterations=2)
mask = cv2.dilate(mask, None, iterations=2)
cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)[-2]
center = None
if len(cnts) > 0:
c = max(cnts, key=cv2.contourArea)
((x, y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
if radius > 10:
cv2.circle(frame, (int(x), int(y)), int(radius),
(0, 255, 255), 2)
cv2.circle(frame, center, 5, (0, 0, 255), -1)
else:
x = 0
y = 0
print("x : ")
print(x)
print("y : ")
print(y)
table.putNumber("X", x) # roborioya değeri göndermek
table.putNumber("Y", y) # roborioya değeri göndermek
cv2.imshow('frame', frame)
cv2.waitKey(1)
screen_record()



m_jaguar = new CANJaguar(CANJaguarIDValue);m_jaguar->SetPercentMode(CANJaguar::QuadEncoder, 360);
m_jaguar->EnableControl();
m_jaguar->Set(0.0f); double initialPosition = m_jaguar->GetPosition(); m_jaguar->SetVoltageMode();m_jaguar->SetPercentMode(); m_jaguar->SetPercentMode(CANJaguar::QuadEncoder, 360);m_jaguar->SetPositionMode(CANJaguar::QuadEncoder, 360, 10.0f, 0.4f, 0.2f);
m_jaguar->EnableControl();
double setpoint = m_jaguar->GetPosition() + 10.0f;
m_jaguar->Set(setpoint);setSpeedMode(EncoderTag tag, int codesPerRev, double p, double i, double d)m_jaguar->GetBusVoltage();
m_jaguar->GetOutputVoltage();
m_jaguar->GetOutputCurrent();
m_jaguar->GetTemperature();
m_jaguar->GetFaults();import edu.wpi.first.wpilibj.networktables.NetworkTable; // Networktables kütüphanesi
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; // smartdashboardan verileri görmek için
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; public static NetworkTable table1 = NetworkTable.getTable("Vision"); // vision adında table çekiliyorpublic static double konumX()
{
return table1.getNumber("X", 0.0); //raspberry pi den gelen x kordinatları
}
public static double konumY()
{
return table1.getNumber("Y", 0.0); //raspberry pi den gelen y kordinatları
} public void teleopPeriodic() {
SmartDashboard.putNumber("Nesnenin X konumu: ", konumX()); // smartdashboarda x konumu yazdır
SmartDashboard.putNumber("Nesnenin Y konumu: ", konumY()); // smartdashboarda y konumunu yazdır
}public void autonomousPeriodic() {
if(konumX() == 0)
{
sagmotor1.set(0);
sagmotor2.set(0);
solmotor1.set(0);
solmotor2.set(0);
}
else if(konumX() < 285) // degerler 285'ten kucukse saga don
{
sagmotor1.set(0.5); // sag motorları calistir
sagmotor2.set(0.5);
}
else if (konumX() > 295) // degerler 295'ten buyukse sola don
{
solmotor1.set(0.5); //sol motorlari calistir
solmotor2.set(0.5);
}
}












Gyro headingGyro = new AnalogGyro(1);
double heading = headingGyro.getAngle();public class Robot extends IterativeRobot {
public void robotInit() {
Thread t = new Thread(() -> {
while (true) {
// Burada takıldık!
}
});
t.start();
}
}public class Robot extends IterativeRobot {
public void robotInit() {
Thread t = new Thread(() -> {
while (!Thread.interrupted()) {
// Bu sefer takılmadık!
}
});
t.start();
}
}RobotTemplate::RobotTemplate()
{
}
void RobotTemplate::RobotInit()
{
}
void RobotTemplate::AutonomousInit()
{
}
void RobotTemplate::AutonomousPeriodic()
{
}
public class RobotTemplate extends IterativeRobot {
public void robotInit() {
}
public void autonomousInit() {
}
public void autonomousPeriodic() {
}
}RobotTemplate::RobotTemplate()
{
}
//This function is called once each time the robot enters autonomous mode.
void RobotTemplate::Autonomous()
{
while (IsAutonomous() && IsEnable())
{
// Put code here
Wait(0.05);
}
}
// This function is called once each time the robot enters teleop mode.
void RobotTemplate::OperatorControl() {
while (isOperatorControl() && isEnabled())
{
// Put code here
Wait(0.05);
}
}
public class RobotTemplate extends SampleRobot {
//This function is called once each time the robot enters autonomous mode.
public void autonomous() {
// Put code here
Timer.delay(0.05);
}
// This function is called once each time the robot enters teleop mode.
public void operatorControl() {
while(isOperatorControl() && isEnabled()) {
//Put code here
//Timer.delay(0.05);
}
}
}
C++
Joystick *exampleStick
public:
Robot(){
}
void RobotInit() {
exampleStick = new Joystick(1);
}
Java
exampleStick = new Joystick(1);C++
double value;
value = exampleStick->GetX();
value = exampleStick->GetY();
value = exampleStick->GetZ();
value = exampleStick->GetThrottle();
value = exampleStick->GetTwist();
boolean buttonValue;
buttonValue = exampleStick->GetTop();
buttonValue = exampleStick->GetTrigger();
Java
double value;
value = exampleStick.getX();
value = exampleStick.getY();
value = exampleStick.getZ();
value = exampleStick.getThrottle();
value = exampleStick.getTwist();
boolean buttonValue;
buttonValue = exampleStick.getTop();
buttonValue = exampleStick.getTrigger();C++
double value;
value = exampleStick->GetRawAxis(2);
boolean buttonValue;
buttonValue = exampleStick->GetRawButton(1);
Java
double value;
value = exampleStick.getRawAxis(1);
boolean buttonValue;
buttonValue = exampleStick.getRawButton(2);C++
double value;
value = exampleStick->GetDirectionDegrees();
value = exampleStick->GetDirectionRadians();
value = exampleStick->GetMagnitude();
Java
double value;
value = exampleStick.getDirectionDegrees();
value = exampleStick.getDirectionRadians();
value = exampleStick.getMagnitude();wget https://raw.githubusercontent.com/enisgetmez/FRC-Vision-Processing/master/Pixy/pixy.pyimport edu.wpi.first.wpilibj.networktables.NetworkTable; // Networktables kütüphanesi
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; // smartdashboardan verileri görmek için
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; public static NetworkTable table1 = NetworkTable.getTable("Vision"); // vision adında table çekiliyorpublic static double konumX()
{
return table1.getNumber("X", 0.0); //raspberry pi den gelen x kordinatları
}
public static double konumY()
{
return table1.getNumber("Y", 0.0); //raspberry pi den gelen y kordinatları
} public void teleopPeriodic() {
SmartDashboard.putNumber("Nesnenin X konumu: ", konumX()); // smartdashboarda x konumu yazdır
SmartDashboard.putNumber("Nesnenin Y konumu: ", konumY()); // smartdashboarda y konumunu yazdır
}public void autonomousPeriodic() {
if(konumX() == 0)
{
sagmotor1.set(0);
sagmotor2.set(0);
solmotor1.set(0);
solmotor2.set(0);
}
else if(konumX() < 285) // degerler 285'ten kucukse saga don
{
sagmotor1.set(0.5); // sag motorları calistir
sagmotor2.set(0.5);
}
else if (konumX() > 295) // degerler 295'ten buyukse sola don
{
solmotor1.set(0.5); //sol motorlari calistir
solmotor2.set(0.5);
}
}





NetworkTable table = NetworkTableInstance.getDefault().getTable("limelight");
NetworkTableEntry tx = table.getEntry("tx");
NetworkTableEntry ty = table.getEntry("ty");
NetworkTableEntry ta = table.getEntry("ta");
double x = tx.getDouble(0);
double y = ty.getDouble(0);
double area = ta.getDouble(0);import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;std::shared_ptr<NetworkTable> table = NetworkTable::GetTable("limelight");
float targetOffsetAngle_Horizontal = table->GetNumber("tx");
float targetOffsetAngle_Vertical = table->GetNumber("ty");
float targetArea = table->GetNumber("ta");
float targetSkew = table->GetNumber("ts");from networktables import NetworkTables
table = NetworkTables.getTable("limelight")
tx = table.getNumber('tx',None)
ty = table.getNumber('ty',None)
ta = table.getNumber('ta',None)
ts = table.getNumber('ts',Noneif (limelight.angleOffset > 10) { // eğer hedef solda kalıyorsa
RightMotorMaster.setPower(0.30); // 30% throttle
LeftMotorMaster.setPower(-0.30); // -30% throttle
} else if (limelight.angleOffset < -10) { // Eğer Hedef Sağda Kaalıyorsa
RightMotorMaster.setPower(-0.30); // -30% throttle
LeftMotorMaster.setPower(0.30); // 30% throttle
} else {
// Robot hizalanmış yavaşça ileri gidin
RightMotorMaster.setPower(0.30); // 30% throttle
LeftMotorMaster.setPower(0.30); // 30% throttle
}









import sys
import numpy as np
import cv2
blue = sys.argv[1]
green = sys.argv[2]
red = sys.argv[3]
color = np.uint8([[[blue, green, red]]])
hsv_color = cv2.cvtColor(color, cv2.COLOR_BGR2HSV)
hue = hsv_color[0][0][0]
print("Lower bound is :"),
print("[" + str(hue-10) + ", 100, 100]\n")
print("Upper bound is :"),
print("[" + str(hue + 10) + ", 255, 255]")#!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import deque
from networktables import NetworkTables
import numpy as np
import argparse
import cv2
import time
import imutils
x = 0 #programın ileride hata vermemesi için x 0 olarak tanımlıyorum
y = 0 # programın ileride hata vermemesi için y 0 olarak tanımlıyorum
NetworkTables.initialize(server='roborio-6025-frc.local') # Roborio ile iletişim kuruyoruz
table = NetworkTables.getTable("Vision") # table oluşturuyoruz
#sari rengin algilanmasi
colorLower = (24, 100, 100)
colorUpper = (44, 255, 255)
#converter.py ile convert ettiğiniz rengi buraya giriniz
camera = cv2.VideoCapture(0) # webcamin bagli oldugu port varsayilan 0
while True: #yazılımımız çalıştığı sürece aşağıdaki işlemleri tekrarla
(grabbed, frame) = camera.read() # grabbed ve frame değişkenini camera.read olarak tanımlıyoruz.
frame = imutils.resize(frame, width=600) # görüntü genişliğini 600p yapıyoruz
frame = imutils.rotate(frame, angle=0) # görüntüyü sabitliyoruz
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # görüntüyü hsv formatına çeviriyoruz
mask = cv2.inRange(hsv, colorLower, colorUpper) # hsv formatına dönen görüntünün bizim belirttiğimiz renk sınırları içerisinde olanları belirliyor
mask = cv2.erode(mask, None, iterations=2) # bizim renklerimizi işaretliyor
mask = cv2.dilate(mask, None, iterations=2) # bizim renklerimizin genişliğini alıyor
cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)[-2]
center = None
if len(cnts) > 0:
c = max(cnts, key=cv2.contourArea)
((x, y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
if radius > 10: #algılanacak hedefin minumum boyutu
cv2.circle(frame, (int(x), int(y)), int(radius),
(0, 255, 255), 2)
cv2.circle(frame, center, 5, (0, 0, 255), -1)
else:
x = 0 ##değerlerin sıfırlanması
y = 0
print("x : ")
print(x) # kameradan gelen görüntüde bizim rengimiz varsa x kordinatı
print("y : ")
print(y) # kameradan gelen görüntüde bizim rengimiz varsa y kordinatı
table.putNumber("X", x) # roborioya değeri göndermek
table.putNumber("Y", y)wget https://raw.githubusercontent.com/enisgetmez/FRC-Vision-Processing/master/Color%20Detect/vision.py#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import argparse
import cv2
import cv2 as CV
from networktables import NetworkTables
NetworkTables.initialize(server='roborio-6025-frc.local') # Roborio ile iletişim kuruyoruz
table = NetworkTables.getTable("Vision") # table oluşturuyoruz
cap = cv2.VideoCapture(0) # webcamin bagli oldugu port
while(True):
# goruntu yakalama
ret, frame = cap.read()
# goruntuyu grilestir
output = frame.copy()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# goruntuyu blurlastir
gray = cv2.GaussianBlur(gray,(5,5),0);
gray = cv2.medianBlur(gray,5)
gray = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
cv2.THRESH_BINARY,11,3.5)
kernel = np.ones((5,5),np.uint8)
gray = cv2.erode(gray,kernel,iterations = 1)
gray = cv2.dilate(gray,kernel,iterations = 1)
circles = cv2.HoughCircles(gray, cv2.cv.CV_HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0) #python2 icin
# circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 20, param1=40, param2=45, minRadius=0, maxRadius=0) # python3 icin
# (x−xcenter)2+(y−ycenter)2=r2 (xcenter,ycenter)
# kalibre
# daireyi isle
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for (x, y, r) in circles:
cv2.circle(output, (x, y), r, (0, 255, 0), 4)
cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
print ("X kordinat: ")
print (x) # x kordinatı
print ("Y Kordinat: ")
print (y) # y kordinatı
print ("Radius: ")
print (r) # cisimin büyüklüğü
table.putNumber("X", x) # roborioya değeri göndermek
table.putNumber("Y", y)
#cv2.imshow('frame',output) # ekranda göster
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()wget https://raw.githubusercontent.com/enisgetmez/FRC-Vision-Processing/master/Figure%20Detect/circle.pyimport edu.wpi.first.wpilibj.networktables.NetworkTable; // Networktables kütüphanesi
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; // smartdashboardan verileri görmek için
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; public static NetworkTable table1 = NetworkTable.getTable("Vision"); // vision adında table çekiliyorpublic static double konumX()
{
return table1.getNumber("X", 0.0); //raspberry pi den gelen x kordinatları
}
public static double konumY()
{
return table1.getNumber("Y", 0.0); //raspberry pi den gelen y kordinatları
} public void teleopPeriodic() {
SmartDashboard.putNumber("Nesnenin X konumu: ", konumX()); // smartdashboarda x konumu yazdır
SmartDashboard.putNumber("Nesnenin Y konumu: ", konumY()); // smartdashboarda y konumunu yazdır
} public void autonomousPeriodic() {
if(konumX() == 0)
{
sagmotor1.set(0);
sagmotor2.set(0);
solmotor1.set(0);
solmotor2.set(0);
}
else if(konumX() < 285) // degerler 285'ten kucukse saga don
{
sagmotor1.set(0.5); // sag motorları calistir
sagmotor2.set(0.5);
}
else if (konumX() > 295) // degerler 295'ten buyukse sola don
{
solmotor1.set(0.5); //sol motorlari calistir
solmotor2.set(0.5);
}
}


















































C++
#include "WPILib.h"
class Robot: public SampleRobot
{
DigitalInput limitSwitch;
public:
Robot() {
}
void RobotInit()
{
limitSwitch = new DigitalInput(1);
}
void OperatorControl() {
// more code here
while (limitSwitch.Get()) {
Wait(10);
}
// more code here
}
Java
package org.usfirst.frc.team1.robot;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Timer;
public class RobotTemplate extends SampleRobot {
DigitalInput limitSwitch;
\ public void robotInit() {
limitSwitch = new DigitalInput(1);
}
\ public void operatorControl() {
// more code here
while (limitSwitch.get()) {
Timer.delay(10);
}
// more code here
}
package edu.wpi.first.wpilibj.templates.commands;
public class ArmUp extends CommandBase {
public ArmUp() {
}
protected void initialize() {
arm.armUp();
}
protected void execute() {
}
protected boolean isFinished() {
return arm.isSwitchSet();
}
protected void end() {
arm.armStop();
}
protected void interrupted() {
end();
}
}package edu.wpi.first.wpilibj.templates.subsystems;
import edu.wpi.first.wpilibj.Counter;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.command.Subsystem;
public class Arm extends Subsystem {
DigitalInput limitSwitch = new DigitalInput(1);
SpeedController armMotor = new Victor(1);
Counter counter = new Counter(limitSwitch);
public boolean isSwitchSet() {
return counter.get() > 0;
}
public void initializeCounter() {
counter.reset();
}
public void armUp() {
armMotor.set(0.5);
}
public void armDown() {
armMotor.set(-0.5);
}
public void armStop() {
armMotor.set(0.0);
}
protected void initDefaultCommand() {
}
}package edu.wpi.first.wpilibj.templates.commands;
public class ArmUp extends CommandBase {
public ArmUp() {
}
protected void initialize() {
arm.initializeCounter();
arm.armUp();
}
protected void execute() {
}
protected boolean isFinished() {
return arm.isSwitchSet();
}
protected void end() {
arm.armStop();
}
protected void interrupted() {
end();
}
}class AccelerometerSample: public SampleRobot {
AnalogAccelerometer *accel;
double acceleration;
AccelerometerSample()
{
accel = new AnalogAccelerometer(0); //create accelerometer on analog input 0
accel->SetSensitivity(.018); // Set sensitivity to 18mV/g (ADXL193)
accel->SetZero(2.5); //Set zero to 2.5V (actual value should be determined experimentally)
}
public void OperatorControl() {
while(IsOperatorControl() && IsEnabled())
{
acceleration = accel->GetAcceleration();
}
}
}AccelerometerSample()
{
accel = new AnalogAccelerometer(0); //create accelerometer on analog input 0
accel.setSensitivity(.018); // Set sensitivity to 18mV/g (ADXL193)
accel.setZero(2.5); //Set zero to 2.5V (actual value should be determined experimentally)
}
public void operatorControl() {
while(isOperatorControl() && isEnabled())
{
acceleration = accel.getAcceleration();
}
}
}C++
Accelerometer *accel;
accel = new BuiltInAccelerometer(Accelerometer:kRange_4G);
double xVal = accel->GetX();
double yVal = accel->GetY();
double zVal = accel->GetZ();Java
Accelerometer accel;
accel = new BuiltInAccelerometer();
accel = new BuiltInAccelerometer(Accelerometer.Range.k4G);
double xVal = accel.getX();
double yVal = accel.getY();
double zVal = accel.getZ();C++
class AccelerometerSample: public SampleRobot {
Accelerometer *accel;
double accelerationX;
double accelerationY;
double accelerationZ;
AccelerometerSample()
{
accel = new ADXL345_I2C(I2C::Port::kOnboard, Accelerometer::Range::kRange_4G);
}
public void OperatorControl() {
while(IsOperatorControl() && IsEnabled())
{
accelerationX = accel->GetX();
accelerationY = accel->GetY();
accelerationZ = accel->GetZ();
}
}
}
Java
public class AccelerometerSample extends SampleRobot {
Accelerometer accel;
double accelerationX;
double accelerationY;
double accelerationZ;
AccelerometerSample()
{
accel = new ADXL345_I2C(I2C.Port.kOnboard, Accelerometer.Range.k4G);
}
public void operatorControl() {
while(isOperatorControl() && isEnabled())
{
accelerationX = accel.getX();
accelerationY = accel.getY();
accelerationZ = accel.getZ();
}
}
}C++
class GyroSample : public SampleRobot
{
RobotDrive myRobot; // robot drive system
AnalogGyro gyro;
static const float kP = 0.03;
public:
GyroSample():
myRobot(1, 2), // initialize the sensors in initilization list
gyro(1)
{
myRobot.SetExpiration(0.1);
}
void Autonomous()
{
gyro.Reset();
while (IsAutonomous())
{
float angle = gyro.GetAngle(); // get heading
myRobot.Drive(-1.0, -angle * kP); // turn to correct heading
Wait(0.004);
}
myRobot.Drive(0.0, 0.0); // stop robot
}
};
Java
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.AnalogGyro;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Timer;
public class GyroSample extends SampleRobot {
\ private RobotDrive myRobot; // robot drive system
private Gyro gyro;
\ double Kp = 0.03;
public GyroSample() {
gyro = new AnalogGyro(1); \ // Gyro on Analog Channel 1
myRobot = new RobotDrive(1,2); \ // Drive train jaguars on PWM 1 and 2
myRobot.setExpiration(0.1);
\ }
public void autonomous() {
gyro.reset();
while (isAutonomous()) {
double angle = gyro.getAngle(); // get current heading
myRobot.drive(-1.0, -angle*Kp); // drive towards heading 0
Timer.delay(0.004);
}
myRobot.drive(0.0, 0.0);
\ }
}
C++
class ultrasonicSample : public SampleRobot
{
Ultrasonic *ultra; // creates the ultra object
public:
ultrasonicSample()
{
ultra = new Ultrasonic(1, 1); // assigns ultra to be an ultrasonic sensor which uses DigitalOutput 1 for the echo pulse and DigitalInput 1 for the trigger pulse
ultra->SetAutomaticMode(true); // turns on automatic mode
}
void Teleop()
{
int range = ultra->GetRangeInches(); // reads the range on the ultrasonic sensor
}
};
Java
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Ultrasonic;
public class RobotTemplate extends SampleRobot {
Ultrasonic ultra = new Ultrasonic(1,1); // creates the ultra object andassigns ultra to be an ultrasonic sensor which uses DigitalOutput 1 for
// the echo pulse and DigitalInput 1 for the trigger pulse
public void robotInit() {
ultra.setAutomaticMode(true); // turns on automatic mode
}
public void ultrasonicSample() {
double range = ultra.getRangeInches(); // reads the range on the ultrasonic sensor
}









Java
import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.command.Subsystem;
import org.usfirst.frc.team1.robot.RobotMap;
public class Claw extends Subsystem {
Victor motor = RobotMap.clawMotor;
public void initDefaultCommand() {
}
public void open() {
motor.set(1);
}
public void close() {
motor.set(-1);
}
public void stop() {
motor.set(0);
}
}
Java
package org.usfirst.frc.team1.robot.commands;
import edu.wpi.first.wpilibj.command.Command;
import org.usfirst.frc.team1.robot.Robot;
/**
*
*/
public class OpenClaw extends Command {
public OpenClaw() {
requires(Robot.claw);
setTimeout(.9);
}
protected void initialize() {
Robot.claw.open()
}
protected void execute() {
}
protected boolean isFinished() {
return isTimedOut();
}
protected void end() {
Robot.claw.stop();
}
protected void interrupted() {
end();
}
}
Java
package org.usfirst.frc.team1.robot.subsystems;
import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.command.PIDSubsystem;
import org.usfirst.frc.team1.robot.RobotMap;
public class Wrist extends PIDSubsystem { // This system extends PIDSubsystem
Victor motor = RobotMap.wristMotor;
AnalogInput pot = RobotMap.wristPot();
public Wrist() {
super("Wrist", 2.0, 0.0, 0.0);// The constructor passes a name for the subsystem and the P, I and D constants that are used when computing the motor output
setAbsoluteTolerance(0.05);
getPIDController().setContinuous(false);
}
public void initDefaultCommand() {
}
protected double returnPIDInput() {
return pot.getAverageVoltage(); // returns the sensor value that is providing the feedback for the system
}
protected void usePIDOutput(double output) {
motor.pidWrite(output); // this is where the computed output value fromthe PIDController is applied to the motor
}
}
C++
#include "MyCommandName.h"
/*
* 1. Constructor - Might have parameters for this command such as target positions of devices. Should also set the name of the command for debugging purposes.
* This will be used if the status is viewed in the dashboard. And the command should require (reserve) any devices is might use.
*/
MyCommandName::MyCommandName() : CommandBase("MyCommandName")
{
Requires(Elevator);
}
// initialize() - This method sets up the command and is called immediately before the command is executed for the first time and
// every subsequent time it is started . Any initialization code should be here.
void MyCommandName::Initialize()
{
}
/*
* execute() - This method is called periodically (about every 20ms) and does the work of the command. Sometimes, if there is a position a
* subsystem is moving to, the command might set the target position for the subsystem in initialize() and have an empty execute() method.
*/
void MyCommandName::Execute()
{
}
bool MyCommandName::IsFinished()
{
return false;
}
void MyCommandName::End()
{
}
// Make this return true when this Command no longer needs to run execute()
void MyCommandName::Interrupted()
{
}
Java
public class MyCommandName extends Command {
/*
* 1. Constructor - Might have parameters for this command such as target positions of devices. Should also set the name of the command for debugging purposes.
* This will be used if the status is viewed in the dashboard. And the command should require (reserve) any devices is might use.
*/
public MyCommandName() {
super("MyCommandName");
requires(elevator);
}
// initialize() - This method sets up the command and is called immediately before the command is executed for the first time and every subsequent time it is started .
// Any initialization code should be here.
protected void initialize() {
}
/*
* execute() - This method is called periodically (about every 20ms) and does the work of the command. Sometimes, if there is a position a
* subsystem is moving to, the command might set the target position for the subsystem in initialize() and have an empty execute() method.
*/
protected void execute() {
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return false;
}
}
C++
#include "DriveWithJoysticks.h"
#include "RobotMap.h"
DriveWithJoysticks::DriveWithJoysticks() : CommandBase("DriveWithJoysticks")
{
Requires(Robot::drivetrain); // Drivetrain is our instance of the drive system
}
// Called just before this Command runs the first time
void DriveWithJoysticks::Initialize()
{
}
/*
* execute() - In our execute method we call a tankDrive method we have created in our subsystem. This method takes two speeds as a parameter which we get from methods in the OI class.
* These methods abstract the joystick objects so that if we want to change how we get the speed later we can do so without modifying our commands
* (for example, if we want the joysticks to be less sensitive, we can multiply them by .5 in the getLeftSpeed method and leave our command the same).
*/
void DriveWithJoysticks::Execute()
{
Robot::drivetrain->Drive(Robot::oi->GetJoystick());
}
/*
* isFinished - Our isFinished method always returns false meaning this command never completes on it's own. The reason we do this is that this command will be set as the default command for the subsystem. This means that whenever the subsystem is not running another command, it will run this command. If any other command is scheduled it will interrupt this command, then return to this command when the other command completes.
*/
bool DriveWithJoysticks::IsFinished()
{
return false;
}
void DriveWithJoysticks::End()
{
Robot::drivetrain->Drive(0, 0);
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void DriveWithJoysticks::Interrupted()
{
End();
}
Java
public class DriveWithJoysticks extends Command {
public DriveWithJoysticks() {
requires(drivetrain);// drivetrain is an instance of our Drivetrain subsystem
}
protected void initialize() {
}
/*
* execute() - In our execute method we call a tankDrive method we have created in our subsystem. This method takes two speeds as a parameter which we get from methods in the OI class.
* These methods abstract the joystick objects so that if we want to change how we get the speed later we can do so without modifying our commands
* (for example, if we want the joysticks to be less sensitive, we can multiply them by .5 in the getLeftSpeed method and leave our command the same).
*/
protected void execute() {
drivetrain.tankDrive(oi.getLeftSpeed(), oi.getRightSpeed());
}
/*
* isFinished - Our isFinished method always returns false meaning this command never completes on it's own. The reason we do this is that this command will be set as the default command for the subsystem. This means that whenever the subsystem is not running another command, it will run this command. If any other command is scheduled it will interrupt this command, then return to this command when the other command completes.
*/
protected boolean isFinished() {
return false;
}
protected void end() {
}
protected void interrupted() {
}
}
C++
#include "PlaceSoda.h"
PlaceSoda::PlaceSoda()
{
AddSequential(new SetElevatorSetpoint(TABLE_HEIGHT));
AddSequential(new SetWristSetpoint(PICKUP));
AddSequential(new OpenClaw());
}
Java
public class PlaceSoda extends CommandGroup {
public PlaceSoda() {
addSequential(new SetElevatorSetpoint(Elevator.TABLE_HEIGHT));
addSequential(new SetWristSetpoint(Wrist.PICKUP));
addSequential(new OpenClaw());
}
}
C++
#include "PrepareToGrab.h"
PrepareToGrab::PrepareToGrab()
{
AddParallel(new SetWristSetpoint(PICKUP));
AddParallel(new SetElevatorSetpoint(BOTTOM));
AddParallel(new OpenClaw());
}
Java
public class PrepareToGrab extends CommandGroup {
public PrepareToGrab() {
addParallel(new SetWristSetpoint(Wrist.PICKUP));
addParallel(new SetElevatorSetpoint(Elevator.BOTTOM));
addParallel(new OpenClaw());
}
}C++
#include "Grab.h"
Grab::Grab()
{
AddSequential(new CloseClaw());
AddParallel(new SetElevatorSetpoint(STOW));
AddSequential(new SetWristSetpoint(STOW));
}
Java
public class Grab extends CommandGroup {
public Grab() {
addSequential(new CloseClaw());
addParallel(new SetElevatorSetpoint(Elevator.STOW));
addSequential(new SetWristSetpoint(Wrist.STOW));
}
}C++
OI::OI()
{
joy = new Joystick(1);
JoystickButton* button1 = new JoystickButton(joy, 1),
button2 = new JoystickButton(joy, 2),
button3 = new JoystickButton(joy, 3),
button4 = new JoystickButton(joy, 4),
button5 = new JoystickButton(joy, 5),
button6 = new JoystickButton(joy, 6),
button7 = new JoystickButton(joy, 7),
button8 = new JoystickButton(joy, 8);
}
Java
public class OI {
// Create the joystick and the 8 buttons on it
Joystick leftJoy = new Joystick(1);
Button button1 = new JoystickButton(leftJoy, 1),
button2 = new JoystickButton(leftJoy, 2),
button3 = new JoystickButton(leftJoy, 3),
button4 = new JoystickButton(leftJoy, 4),
button5 = new JoystickButton(leftJoy, 5),
button6 = new JoystickButton(leftJoy, 6),
button7 = new JoystickButton(leftJoy, 7),
button8 = new JoystickButton(leftJoy, 8);
}C++
button1->WhenPressed(new PrepareToGrab());
button2->WhenPressed(new Grab());
button3->WhenPressed(new DriveToDistance(0.11));
button4->WhenPressed(new PlaceSoda());
button6->WhenPressed(new DriveToDistance(0.2));
button8->WhenPressed(new Stow());
button7->WhenPressed(new SodaDelivery());
Java
public OI() {
button1.whenPressed(new PrepareToGrab());
button2.whenPressed(new Grab());
button3.whenPressed(new DriveToDistance(0.11));
button4.whenPressed(new PlaceSoda());
button6.whenPressed(new DriveToDistance(0.2));
button8.whenPressed(new Stow());
button7.whenPressed(new SodaDelivery());
}
C++
button1->WhenPressed(new PrepareToGrab());
button2->WhenPressed(new Grab());
button3->WhenPressed(new DriveToDistance(0.11));
button4->WhenPressed(new PlaceSoda());
button6->WhenPressed(new DriveToDistance(0.2));
button8->WhenPressed(new Stow());
button7->WhenPressed(new SodaDelivery());
Java
public OI() {
button1.whenPressed(new PrepareToGrab());
button2.whenPressed(new Grab());
button3.whenPressed(new DriveToDistance(0.11));
button4.whenPressed(new PlaceSoda());
button6.whenPressed(new DriveToDistance(0.2));
button8.whenPressed(new Stow());
button7.whenPressed(new SodaDelivery());
}
C++
Command* autonomousCommand;
class Robot: public IterativeRobot {
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
void RobotInit()
{
// instantiate the command used for the autonomous period
autonomousCommand = new SodaDelivery();
oi = new OI();
}
void AutonomousInit()
{
// schedule the autonomous command (example)
if(autonomousCommand != NULL) autonomousCommand->Start();
}
/*
* This function is called periodically during autonomous
*/
void AutonomousPeriodic()
{
Scheduler::GetInstance()->Run();
}
Java
public class Robot extends IterativeRobot {
Command autonomousCommand;
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
oi = new OI();
// instantiate the command used for the autonomous period
autonomousCommand = new SodaDelivery();
}
public void autonomousInit() {
// schedule the autonomous command (example)
if (autonomousCommand != null) autonomousCommand.start();
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
Scheduler.getInstance().run();
}C++
// Aim shooter
SetTargetAngle(); // Initialization: prepares for the action to be performed
while (!AtRightAngle()) { // Condition: keeps the loop going while it is satisfied
CorrectAngle(); // Execution: repeatedly updates the code to try to make the condition false
delay(); // Delay to prevent maxing CPU
}
HoldAngle(); // End: performs any cleanup and final task before moving on to the next action
// Spin up to Speed
SetTargetSpeed(); // Initialization: prepares for the action to be performed
while (!FastEnough()) { // Condition: keeps the loop going while it is satisfied
SpeedUp(); // Execution: repeatedly updates the code to try to make the condition false
delay(); // Delay to prevent maxing CPU
}
HoldSpeed();
// Shoot Frisbee
Shoot(); // End: performs any cleanup and final task before moving on to the next action
}
Java
// Aim shooter
SetTargetAngle(); // Initialization: prepares for the action to be performed
while (!AtRightAngle()) { // Condition: keeps the loop going while it is satisfied
CorrectAngle(); // Execution: repeatedly updates the code to try to make the condition false
delay(); // Delay to prevent maxing CPU
}
HoldAngle(); // End: performs any cleanup and final task before moving on to the next action
// Spin up to Speed
SetTargetSpeed(); // Initialization: prepares for the action to be performed
while (!FastEnough()) { // Condition: keeps the loop going while it is satisfied
SpeedUp(); // Execution: repeatedly updates the code to try to make the condition false
delay(); // Delay to prevent maxing CPU
}
HoldSpeed();
// Shoot Frisbee
Shoot(); // End: performs any cleanup and final task before moving on to the next action
}C++
#include "AutonomousCommand.h"
AutonomousCommand::AutonomousCommand()
{
AddSequential(new Aim());
AddSequential(new SpinUpShooter());
AddSequential(new Shoot());
}
Java
public class AutonomousCommand extends CommandGroup {
public AutonomousCommand() {
addSequential(new Aim());
addSequential(new SpinUpShooter());
addSequential(new Shoot());
}
}
C++
#include "Aim.h"
Aim::Aim()
{
Requires(Robot::turret);
}
// Called just before this Command runs the first time
void Aim::Initialize()
{
SetTargetAngle();
}
// Called repeatedly when this Command is scheduled to run
void Aim:Execute()
{
\ CorrectAngle();
}
// Make this return true when this Command no longer needs to run execute()
bool Aim:IsFinished()
{
return AtRightAngle();
}
// Called once after isFinished returns true
void Aim::End()
{
HoldAngle();
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void Aim:Interrupted()
{
End();
}
Java
public class Aim extends Command {
public Aim() {
requires(Robot.turret);
}
// Called just before this Command runs the first time
protected void initialize() {
SetTargetAngle();
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
CorrectAngle();
\ }
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return AtRightAngle();
\ }
// Called once after isFinished returns true
protected void end() {
HoldAngle();
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
end();
}
}
C++
#include "SpinUpShooter.h"
SpinUpShooter::SpinUpShooter()
{
Requires(Robot::shooter)
}
// Called just before this Command runs the first time
void SpinUpShooter::Initialize()
{
\ SetTargetSpeed();
}
// Called repeatedly when this Command is scheduled to run
void SpinUpShooter::Execute()
{
SpeedUp();
}
// Make this return true when this Command no longer needs to run execute()
bool SpinUpShooter::IsFinished()
{
\ return FastEnough();
}
// Called once after isFinished returns true
void SpinUpShooter::End()
{
HoldSpeed();
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void SpinUpShooter::Interrupted()
{
End();
}
Java
public class SpinUpShooter extends Command {
public SpinUpShooter() {
requires(Robot.shooter);
\ }
// Called just before this Command runs the first time
protected void initialize() {
SetTargetSpeed();
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
SpeedUp();
\ }
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return FastEnough();
\ }
// Called once after isFinished returns true
protected void end() {
HoldSpeed();
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
end();
}
}
C++
#include "Shoot.h"
Shoot::Shoot()
{
Requires(Robot.shooter);
}
// Called just before this Command runs the first time
void Shoot::Initialize()
{
\ Shoot();
}
// Called repeatedly when this Command is scheduled to run
void Shoot::Execute()
{
}
// Make this return true when this Command no longer needs to run execute()
bool Shoot::IsFinished()
{
return true;
}
// Called once after isFinished returns true
void Shoot::End()
{
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void Shoot::Interrupted()
{
End();
}
Java
public class Shoot extends Command {
public Shoot() {
requires(shooter);
}
// Called just before this Command runs the first time
protected void initialize() {
Shoot();
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return true;
}
// Called once after isFinished returns true
protected void end() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
\ protected void interrupted() {
end();
}
}C++
#include "ExampleSubsystem.h"
ExampleSubsystem::ExampleSubsystem()
{
// Put methods for controlling this subsystem
// here. Call these from Commands.
}
ExampleSubsystem::InitDefaultCommand()
{
// Set the default command for a subsystem here.
SetDefaultCommand(new MyDefaultCommand());
}
Java
public class ExampleSubsystem extends Subsystem {
// Put methods for controlling this subsystem
// here. Call these from Commands.
public void initDefaultCommand() {
// Set the default command for a subsystem here.
setDefaultCommand(new MyDefaultCommand());
}
}C++
#include "CoopBridgeAutonomous.h"
CoopBridgeAutonomous::CoopBridgeAutonomous()
{
// SmartDashboard->PutDouble("Camera Time", 5.0);
AddSequential(new SetTipperState(READY_STATE);
AddParallel(new SetVirtualSetpoint(HYBRID_LOCATION);
AddSequential(new DriveToBridge());
AddParallel(new ContinuousCollect());
AddSequential(new SetTipperState(DOWN_STATE));
// addParallel(new WaitThenShoot());
AddSequential(new TurnToTargetLowPassFilterHybrid(4.0));
AddSequential(new FireSequence());
AddSequential(new MoveBallToShooter(true));
}
Java
public class CoopBridgeAutonomous extends CommandGroup {
public CoopBridgeAutonomous() {
//SmartDashboard.putDouble("Camera Time", 5.0);
addSequential(new SetTipperState(BridgeTipper.READY_STATE)); // 1
addParallel(new SetVirtualSetpoint(SetVirtualSetpoint.HYBRID_LOCATION)); // 2
addSequential(new DriveToBridge()); // 3
addParallel(new ContinuousCollect());
addSequential(new SetTipperState(BridgeTipper.DOWN_STATE));
// addParallel(new WaitThenShoot());
addSequential(new TurnToTargetLowPassFilterHybrid(4.0));
addSequential(new FireSequence());
addSequential(new MoveBallToShooter(true));
}
}





















