|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Should this code work as intended?
I'm the lead programmer for my team (this is our second year) and last year we used LabView, but I'm trying to get java ready for the build season. I wrote some code I thought should work, but it isn't. There are no compiling errors and when I tell it to deploy, the crio restarts like it should.
I want to know if something is wrong with my code, or if there must be something wrong with configuration somewhere (it will help to know which so I don't have to examine both possibilities). This code should make the Jaguar in pwm 1 start going during autonomous(at least that is my intention) Code:
//copyright shite
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Jaguar;
//the vm automatially runs this shizzy class
public class SimpleBob extends SimpleRobot {
Jaguar test = new Jaguar(1);
//called during autonomous
public void autonomous() {
test.set(0.75);
}
//called during operator control period of time
public void operatorControl() {
}
}
|
|
#2
|
||||
|
||||
|
Re: Should this code work as intended?
(As a warning, I use the IterativeRobot to code instead of the SimpleRobot, so there might be some error in my post)
The autonomous and operator control methods only run once when the robot is enabled, so when you start autonomous mode, it does do "test.set(0.75);" but right after that autonomous ends, putting it in disabled mode, which sets the motors to 0 . To fix this, you have to have a loop to repeat in the code, such as: Code:
while( isAutonomous() && isEnabled() ) {
test.set(0.75);
}
Code:
test.set(0.75);
while( isAutonomous() && isEnabled() ) {
}
Also, you should read this, it'll help: http://first.wpi.edu/Images/CMS/Firs...va_for_FRC.pdf |
|
#3
|
||||
|
||||
|
Re: Should this code work as intended?
Whenever i construct a Jaguar object and I'musing pwm, i like to pass the slot as a parameter, in case we end up using two digital sidecars. This code won't run on the robot, because you are missing your call to the watchdog. you need to either set the Watchdog to never be fed or you need to be feeding the watchdog in your main loop.
|
|
#4
|
|||
|
|||
|
Re: Should this code work as intended?
In SimpleRobot the autonomous (and teleop) methods are called only once. You should have a loop around your driving command and an explicit set(0.0) after it. e.g.
while(isAutonomous()){ test.set(0.75); } test.set(0.0); but yes, your code should start the Jag on PWM 1 at 75%. |
|
#5
|
||||
|
||||
|
Re: Should this code work as intended?
Hm, you shouldn't need to loop the .set methods. I would also set the module the Digital SideCar is plugged into.
Are you sure your jags are wired correctly, when running the code do you notice the LEDs on them change color? Also are you running auton mode in the Driver Station? For basic auton code you can do: Jag.set(.5); Timer.Delay(4); Jaq.set(0); That will run the motor at speed .5 for 4 secs then shut it off. |
|
#6
|
|||
|
|||
|
Re: Should this code work as intended?
Alright I tried the first two posts to no avail, but I will try what mk said on monday. I know everything is wired correctly because I have been imaging it back to LabView for demos (and I have been setting it to Autonomous in the DS)
tyvm |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|