mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[copybara] Import robotpy examples (#8608)
GitOrigin-RevId: 9ba4bc3040fa7e772f5a594039e78fc6c43d114e
This commit is contained in:
51
robotpyExamples/MecanumDrive/robot.py
Executable file
51
robotpyExamples/MecanumDrive/robot.py
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
import wpilib
|
||||
|
||||
|
||||
class MyRobot(wpilib.TimedRobot):
|
||||
"""
|
||||
This is a demo program showing how to use Mecanum control with the
|
||||
MecanumDrive class.
|
||||
"""
|
||||
|
||||
# Channels on the roboRIO that the motor controllers are plugged in to
|
||||
kFrontLeftChannel = 2
|
||||
kRearLeftChannel = 3
|
||||
kFrontRightChannel = 1
|
||||
kRearRightChannel = 0
|
||||
|
||||
# The channel on the driver station that the joystick is connected to
|
||||
kJoystickChannel = 0
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.frontLeft = wpilib.PWMSparkMax(self.kFrontLeftChannel)
|
||||
self.rearLeft = wpilib.PWMSparkMax(self.kRearLeftChannel)
|
||||
self.frontRight = wpilib.PWMSparkMax(self.kFrontRightChannel)
|
||||
self.rearRight = wpilib.PWMSparkMax(self.kRearRightChannel)
|
||||
|
||||
# invert the right side motors
|
||||
# you may need to change or remove this to match your robot
|
||||
self.frontRight.setInverted(True)
|
||||
self.rearRight.setInverted(True)
|
||||
|
||||
self.robotDrive = wpilib.MecanumDrive(
|
||||
self.frontLeft, self.rearLeft, self.frontRight, self.rearRight
|
||||
)
|
||||
|
||||
self.stick = wpilib.Joystick(self.kJoystickChannel)
|
||||
|
||||
def teleopPeriodic(self):
|
||||
# Use the joystick X axis for lateral movement, Y axis for forward
|
||||
# movement, and Z axis for rotation.
|
||||
self.robotDrive.driveCartesian(
|
||||
-self.stick.getY(),
|
||||
-self.stick.getX(),
|
||||
-self.stick.getZ(),
|
||||
)
|
||||
Reference in New Issue
Block a user