Go to Post By inviting engineers and mentors to be a part of your team and partnering with them...brings added value, depth, strength, expertise, and wisdom to the team and to the overall experience. - JaneYoung [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 01-15-2016, 03:52 PM
JoelRummel JoelRummel is offline
Registered User
FRC #4855
 
Join Date: Jan 2016
Location: South Haven, MI
Posts: 7
JoelRummel is an unknown quantity at this point
Defining/Setting a motor in Java

I am trying to run a VERY SIMPLE piece of Java.
Its only goal is to set a motor's speed to 0.5.
Yet I have difficulties with even this simple task:
Code:
package org.usfirst.frc.team4855.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Talon;

public class Robot extends IterativeRobot {

	Talon talonMotor;

    public void robotInit() {

    	talonMotor = new Talon(0);
    	
    }

    public void teleopInit(){

    	talonMotor.set(0.5);

    }
Not only does this not work but I get a whole bunch of crap in the driver station:

ERROR Unhandled exception: java.lang.RuntimeException: Code: -1029. HAL: Resource already allocated at [edu.wpi.first.wpilibj.hal.PWMJNI.allocatePWMChanne l(Native Method), edu.wpi.first.wpilibj.PWM.initPWM(PWM.java:117), edu.wpi.first.wpilibj.PWM.<init>(PWM.java:134), edu.wpi.first.wpilibj.SafePWM.<init>(SafePWM.java: 35), edu.wpi.first.wpilibj.Talon.<init>(Talon.java:51), org.usfirst.frc.team4855.robot.Robot.robotInit(Rob ot.java:31), edu.wpi.first.wpilibj.IterativeRobot.startCompetit ion(IterativeRobot.java:72), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.jav a:241)]
WARNING: Robots don't quit!

Give it enough time and the robot will just reach an emergency stopped state without any apparent reason.

What in the world am I doing wrong
Reply With Quote
  #2   Spotlight this post!  
Unread 01-15-2016, 04:11 PM
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Defining/Setting a motor in Java

First, the 50% code should be in teleopPeriodic, not init (so it keeps getting called over and over again).

Second, you're creating the talon at least twice. Your code isn't complete so I can't see where else it's being constructed.
__________________
All opinions are my own.
Reply With Quote
  #3   Spotlight this post!  
Unread 01-15-2016, 04:18 PM
JoelRummel JoelRummel is offline
Registered User
FRC #4855
 
Join Date: Jan 2016
Location: South Haven, MI
Posts: 7
JoelRummel is an unknown quantity at this point
Re: Defining/Setting a motor in Java

Thanks, put the code in teleopPeriodic.

I'm confused with your second point. The code I posted is all the code there is.
Reply With Quote
  #4   Spotlight this post!  
Unread 01-15-2016, 05:37 PM
iSpotix iSpotix is offline
Registered User
FRC #4049
 
Join Date: Jan 2016
Location: Pittsburgh
Posts: 27
iSpotix is an unknown quantity at this point
Re: Defining/Setting a motor in Java

I have always written it in one line directly under the class statement not in robotinit.

Talon motor = new Talon(0);

Your problem may be from splitting it up.
Reply With Quote
  #5   Spotlight this post!  
Unread 01-15-2016, 05:41 PM
rzoeller rzoeller is offline
MN GOFIRST Recruitment Officer
AKA: Ryan Zoeller
FRC #2169 (RI3D 'Snow Problem; KING TeC)
Team Role: Alumni
 
Join Date: Nov 2009
Rookie Year: 2007
Location: Savage, MN
Posts: 111
rzoeller is a jewel in the roughrzoeller is a jewel in the roughrzoeller is a jewel in the rough
Re: Defining/Setting a motor in Java

Quote:
Originally Posted by iSpotix View Post
I have always written it in one line directly under the class statement not in robotinit.

Talon motor = new Talon(0);

Your problem may be from splitting it up.
That shouldn't cause it, his motor reference would just be null prior to calling robotInit().
__________________
Ri3D - 'Snow Problem Programmer
MN GOFIRST Recruitment Officer
FRC 2169 Alumni
Reply With Quote
  #6   Spotlight this post!  
Unread 01-16-2016, 12:24 AM
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Defining/Setting a motor in Java

The error stack shows Robot.java:31, meaning line 31. You don't have 31 lines posted in your thread.

And you're missing a curly brace to close the class. The above by itself wouldn't compile.
__________________
All opinions are my own.
Reply With Quote
  #7   Spotlight this post!  
Unread 01-16-2016, 10:40 AM
JoelRummel JoelRummel is offline
Registered User
FRC #4855
 
Join Date: Jan 2016
Location: South Haven, MI
Posts: 7
JoelRummel is an unknown quantity at this point
Re: Defining/Setting a motor in Java

That's because I had a bunch of blank space and comments that I got rid of when I copied and pasted the code here

I'm no longer getting errors in the console after moving to teleopPeriodic. But the motors still won't move.

I checked the motors earlier by hooking them up to our battery. They work fine...
Reply With Quote
  #8   Spotlight this post!  
Unread 01-16-2016, 11:16 AM
pastelpony's Avatar
pastelpony pastelpony is offline
Programmer/Electrical
AKA: Zach M
FRC #3525 (Nuts and Bolts of Fury)
Team Role: Programmer
 
Join Date: Feb 2014
Rookie Year: 2013
Location: Waterbury, Connecticut
Posts: 152
pastelpony will become famous soon enough
Re: Defining/Setting a motor in Java

I am having the same issue. I am trying to execute EXTREMELY basic code (operating a Victor). Yet, whenever I try to execute the code, nothing happens and my console gives no hints. Even the sample code does nothing to the robot right now. It successfully deploys yet does nothing.
__________________
Team 3525 Head Programmer (2014- ) - Java (Formerly LabVIEW)
Reply With Quote
  #9   Spotlight this post!  
Unread 01-16-2016, 11:45 AM
JoelRummel JoelRummel is offline
Registered User
FRC #4855
 
Join Date: Jan 2016
Location: South Haven, MI
Posts: 7
JoelRummel is an unknown quantity at this point
Re: Defining/Setting a motor in Java

Nevermind. It was a stupid electrical error. I thought I had checked the system thoroughly but apparently I hadn't.

Thanks for letting me know it wasn't the code's fault.
Reply With Quote
  #10   Spotlight this post!  
Unread 01-16-2016, 12:17 PM
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Defining/Setting a motor in Java

Quote:
Originally Posted by JoelRummel View Post
Nevermind. It was a stupid electrical error. I thought I had checked the system thoroughly but apparently I hadn't.

Thanks for letting me know it wasn't the code's fault.
Always is
__________________
All opinions are my own.
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 08:00 AM.

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