Go to Post edit: laptop. yeah as a programmer to not put this in I should be taken out the back and "decompiled". - Stuart [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 24-11-2016, 14:51
FRC Team CC FRC Team CC is offline
Registered User
FRC #6560 (Charging Champions)
 
Join Date: Sep 2014
Rookie Year: 2012
Location: Southern California
Posts: 102
FRC Team CC is an unknown quantity at this point
Basic motor programming help

Hello,

We are trying to get two motors to run with this program, but when we run it, the build is successful but nothing happens. We are using the Java Deploy feature to compile the program to the RoboRio. Both of our Talon SRX motors have successfully connected to our RoboRio using CAN cables and are showing orange alternating lights.

We are assuming that the motors should automatically run once we deploy the program, but we may be wrong about this. Is there something wrong in our code below or our method of compilation?

Code:
package org.usfirst.frc.team6560.robot;

//import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.SampleRobot;
//import edu.wpi.first.wpilibj.livewindow.LiveWindow;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Robot extends SampleRobot {
	RobotDrive myRobot;
	Joystick stick;
	int autoLoopCounter;
	CANTalon testMotor0 = new CANTalon(1);
	CANTalon testMotor1 = new CANTalon(15);
	
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
    	myRobot = new RobotDrive(testMotor0, testMotor1);
    	//stick = new Joystick(0);
    }
    
    /*
     * This function is run once each time the robot enters autonomous mode
     */
    public void autonomousInit() {
    	//autoLoopCounter = 0;
    }
  

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
    	//testMotor0.set(0.2);
    	while(isAutonomous() && isEnabled()) {
    		myRobot.setSafetyEnabled(false);
    		myRobot.drive(-0.5, 0.0);
    		Timer.delay(2.0);
    		myRobot.drive(0.0, 0.0);
    	}
    }
    
}
Thanks,
Charging Champions
__________________
The Charging Champions
FTC Team #8660
Facebook Page: https://www.facebook.com/chargingchampions
Follow us on Twitter: @FtcTeamCC
Google Plus: https://plus.google.com/112552147224383900922/posts
Youtube channel: https://www.youtube.com/channel/UCop...G3zsvQKCXF4ESQ
Blog: http://chargingchampionsblog.blogspot.com/

Last edited by FRC Team CC : 24-11-2016 at 15:11.
Reply With Quote
  #2   Spotlight this post!  
Unread 24-11-2016, 16:33
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 296
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Basic motor programming help

Quote:
Originally Posted by FTC Team CC View Post
Code:
    public void autonomousPeriodic() {
    	while(isAutonomous() && isEnabled()) {
    		// ...
    		// ...
    		Timer.delay(2.0);
    		// ...
    	}
    }
Don't do this! Periodic functions are supposed to run at 50 Hz, so you should not be doing a long while loop or a delay in them. Also, autonomousPeriodic() will only run if isAutonomous() && isEnabled() is true, so you don't need to do that check yourself.
Instead, you should implement a looping state machine so you can ensure that each loop iteration is as short as possible. I've also done some refactoring for you

Code:
public class Robot extends IterativeRobot {
    static final long AUTO_DRIVE_TIME = 2000; // ms
    static final int CAN_ID_DRIVE0 = 1;
    static final long CAN_ID_DRIVE1 = 15;

    static final double[] AUTO_DRIVE_SPEED = new double[]{-0.5, 0.0};

    enum AutoState {
        DRIVING,
        STOPPED
    }
    
    RobotDrive m_robotDrive;
    CANTalon m_testMotor0;
    CANTalon m_testMotor1;

    AutoState m_autoState;
    long m_autoStartTime;
	
    public void robotInit() {
        m_testMotor0 = new CANTalon(CAN_ID_DRIVE0);
        m_testMotor1 = new CANTalon(CAN_ID_DRIVE1);
    	m_robotDrive = new RobotDrive(m_testMotor0, m_testMotor1);
    }
    
    public void autonomousInit() {
        m_autoState = AutoState.DRIVING;
        m_autoStartTime = System.currentTimeMillis();
    }
    
    public void autonomousPeriodic() {
    	switch(m_autoState) {
        case AutoState.DRIVING:
            m_robotDrive.drive(AUTO_DRIVE_SPEED[0], AUTO_DRIVE_SPEED[1]);
            if(System.currentTimeMillis() - m_autoStartTime >= AUTO_DRIVE_TIME) {
                m_autoState = AutoState.STOPPED;
            }
            break;
        case AutoState.STOPPED:
            m_robotDrive.drive(0, 0);
            break;
        }
    }
}
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote
  #3   Spotlight this post!  
Unread 26-11-2016, 14:36
FRC Team CC FRC Team CC is offline
Registered User
FRC #6560 (Charging Champions)
 
Join Date: Sep 2014
Rookie Year: 2012
Location: Southern California
Posts: 102
FRC Team CC is an unknown quantity at this point
Re: Basic motor programming help

Thank you so much for your help. With a few adjustments, the code worked on our motors. We greatly appreciate it.

Thanks,
Charging Champions
__________________
The Charging Champions
FTC Team #8660
Facebook Page: https://www.facebook.com/chargingchampions
Follow us on Twitter: @FtcTeamCC
Google Plus: https://plus.google.com/112552147224383900922/posts
Youtube channel: https://www.youtube.com/channel/UCop...G3zsvQKCXF4ESQ
Blog: http://chargingchampionsblog.blogspot.com/
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:30.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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