![]() |
Help with Code
Thanks to all on this sight for the guidance offered to all teams. We are working hard trying to figure out how to write code and we need some help. below is the code we have written so far. What we want to have happen is for our drive system to be arcade and we are using the left joystick on our xbox controller and we have two shooter motors. Ideally I would like to have the shooter motors turn on and off with one button but I am not sure how to write that so I attempted to start the motors with the press of one button and turn them off with another button. So far nothing works. The drive motors turn in opposite directions, so I attempted to invert the motors. This allowed us to drive forward and reverse but we could not turn. I am not concerned with autonomous at this time just teleop. I would appreciate any insight into problems with this code and suggestions on how to make it work. Thank you in advance. (sorry i'm not sure the best way to attache my code.)
Code:
package org.usfirst.frc.team5676.robot; |
Re: Help with Code
I'm not a coder, but I stayed at a Holiday Inn Express last night ....
In Public Class, you create the objects for each motor controller (speedcontroller). In Robotinit, you tell robotdrive which are your 4 drive motors. Where do you associate the motorcontroller (victorsp1 for example) with a particular channel address (either PWM port, or CAN port)? Something like what you are doing for xboxcontroller where you associate it with Joystick(0), and then with xbutton and y button. |
Re: Help with Code
So you're using teleop-periodic. This means that the teleop loop gets called over and over. You can get what you want out of the joystick buttons with this concept.
Code:
if (getButton) |
Re: Help with Code
I take that to mean that the button will have to be held down in order to turn the motors on. Is there a way that I can turn the motors on when I first press the button then turn them off when I press the button again?
|
Re: Help with Code
Quote:
*Taken from Ether* Code:
teleop_init |
Re: Help with Code
Quote:
In other words, if you actually counted the number of transitions with a single button press, you can get 5 or more transitions. In essence, the 1/2 way point of a button is "undefined", and can be either pressed or not pressed, and it can change between reads. If it is simply starting a motor when pressed, and stopping a motor when released, you probably won't notice it (the motor controller cycles between off/on really fast). If it is something else (like a toggle), you could end up in an unexpected state. In order to avoid the problem, you have to set a timer. You reset the timer when a valid transition is detected. If the next detected transition is within 250 milliseconds (1/4 second), you ignore it. Remember to debounce the release too so you don't get an accidental "press" when the button is "released". |
Re: Help with Code
If you are trying to use two motors at the same time. The best way to synchronize them is use a PWM Y splitter. This will eliminate the possibilities of them not being synced.
|
Hey Can anyone help me this is my first year coding.
Down below is my code and we want the robot to drive with arcade with a xbox controller also plz help me to get it to turn. And we are using the standard wheels on the robot
package org.usfirst.frc.team5713.robot; 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; import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.Talon; public class Robot extends IterativeRobot { RobotDrive drive = new RobotDrive(1,2,3,4); Joystick driveStick = new Joystick(0); Joystick controlStick = new Joystick(1); Talon frontLeft = new Talon(1); Talon rearLeft = new Talon(2); Talon frontRight = new Talon(3); Talon rearRight = new Talon(4); public void robotInit() { drive = new RobotDrive(1,2,3,4); driveStick = new Joystick(0); controlStick = new Joystick(1); frontLeft = new Talon(1); frontLeft.enableDeadbandElimination(true); frontLeft.set(+1.0); rearLeft = new Talon(2); rearLeft.enableDeadbandElimination(true); rearLeft.set(-1.0); frontRight = new Talon(3); frontRight.enableDeadbandElimination(true); frontRight.set(+1.0); rearRight = new Talon(4); rearRight.enableDeadbandElimination(true); rearRight.set(-1.0); public void teleopInit(){ drive = new RobotDrive(1,2,3,4); driveStick = new Joystick(0); controlStick = new Joystick(1); frontLeft = new Talon(1); frontLeft.enableDeadbandElimination(true); frontLeft.set(-1.0); rearLeft = new Talon(2); rearLeft.enableDeadbandElimination(true); rearLeft.set(+1.0); frontRight = new Talon(3); frontRight.enableDeadbandElimination(true); frontRight.set(-1.0); rearRight = new Talon(4); rearRight.enableDeadbandElimination(true); rearRight.set(+1.0); } public void teleopPeriodic() { while (isOperatorControl() && isEnabled()) { drive.setSafetyEnabled(true); double joystickLeftY = driveStick.getRawAxis(2); double joystickLeftX = driveStick.getRawAxis(1); drive.arcadeDrive(joystickLeftY, joystickLeftX, true); Timer.delay(0.01); } } |
Re: Hey Can anyone help me this is my first year coding.
also our middle wheel and back are the only ones connecting to the drive train.
we have two motors on our middle wheel and two on the other middle wheel. so we can go forward and backward |
Re: Help with Code
Did you confirm that your numbers for controlling the Talons are correct? Go to 10.TE.AM.2 and log into the RoboRio. Enable the lights on Talon(1), and hit save. Verify that your motor, Talon, RobioRio and code all are (1). Then do the same for Talon(2), etc .
|
| All times are GMT -5. The time now is 08:03 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi