Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Should this code work as intended? (http://www.chiefdelphi.com/forums/showthread.php?t=98082)

Thundrio 01-11-2011 21:46

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() {

    }
}

thanks for all help

Kovs 02-11-2011 16:53

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);
}

or, since you don't have to keep setting the speed controller value, you can do:

Code:

test.set(0.75);
while( isAutonomous() && isEnabled() ) {
}

which should set the motor to 75% when autonomous is enabled and will run til autonomous is disabled (or when the robot breaks).

Also, you should read this, it'll help: http://first.wpi.edu/Images/CMS/Firs...va_for_FRC.pdf

Anupam Goli 03-11-2011 11:22

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.

omalleyj 03-11-2011 13:03

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%.

Mk.32 05-11-2011 12:23

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.

Thundrio 05-11-2011 13:19

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


All times are GMT -5. The time now is 22:18.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi