Go to Post that is one of the funniest non-photoshoped pictures of my father i have seen... - Lil' Lavery [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
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 22-01-2017, 19:45
Robochris Robochris is offline
Registered User
FRC #6722
 
Join Date: Jan 2017
Location: Florida
Posts: 3
Robochris is an unknown quantity at this point
CIM coders help!

Im having trouble programming the CIMcoders. Please correct me if you see something wrong im new at this.
So I have the Encoder plugged into the DIO on the roboRIO. From left to right on the encoder when placed on a motor, I have the 1st pin in DIO 0: 5V, 2nd pin in DIO 1: signal, 3rd pin in DIO 0: GRN, 4th pin in DIO 0: signal.

On the code side I am using C++. The Encoder stuff is inside a command and none of it is in the Robot.cpp or the main one. The "DriveCommand" is an Autonmous btw, not sure if that helps. When ever i run it in the FRC Drive Station, I get these errors. Need anymore information fill free to let me know. Thanks

Quote:
ERROR -1029 HAL: Resource already allocated, Minimum Value: 0, Maximum Value: 20, Requested Value: 0 PWM [PWM.cpp:43]
ERROR -1029 HAL: Resource already allocated, Minimum Value: 0, Maximum Value: 20, Requested Value: 1 PWM [PWM.cpp:43]
ERROR -1029 HAL: Resource already allocated, Minimum Value: 0, Maximum Value: 31, Requested Value: 0 DigitalInput [DigitalInput.cpp:43]
ERROR -1029 HAL: Resource already allocated, Minimum Value: 0, Maximum Value: 31, Requested Value: 1 DigitalInput [DigitalInput.cpp:43]
ERROR -1098 HAL: A handle parameter was passed incorrectly InitEncoder [Encoder.cpp:43]
Them sick codez
Code:
#include "DriveCommand.h"
#include "WPILib.h"
#include "CANTalon.h"

using namespace frc;

bool done = false;
Victor *victor;
CANTalon *talon;
Victor *victor2;
CANTalon *talon2;
Encoder *CIM;

DriveCommand::DriveCommand() {
	victor = new Victor(0);
	victor2 = new Victor(1);
	talon = new CANTalon(1);
	talon2 = new CANTalon(2);
	CIM = new Encoder(0, 1, false, Encoder::EncodingType::k4X);
}

void DriveCommand::Initialize() {
}

void DriveCommand::Execute() {
	if (!done) {
		victor->Set(CIM->Get() > 5 ? 0 : 1);
		done=true;
	}
}

execute()
bool DriveCommand::IsFinished() {
	return done;
}

void DriveCommand::End() {
	victor->Set(0);
	talon->Set(0);
}

void DriveCommand::Interrupted() {

}
Thanks for your help!
Reply With Quote
  #2   Spotlight this post!  
Unread 22-01-2017, 20:21
Adnewhouse's Avatar
Adnewhouse Adnewhouse is offline
Registered User
FRC #0639
Team Role: College Student
 
Join Date: Jun 2013
Rookie Year: 2012
Location: Ithaca, NY
Posts: 21
Adnewhouse is an unknown quantity at this point
Re: CIM coders help!

I think you might want to add parentheses to make it look like this:
Code:
victor->Set((CIM->Get() > 5) ? 0 : 1);
Also, if you want to use encoders and victors on the same ports during teleop, you should create those objects in a single file called RobotMap.cpp and then pass them along to each subsystem, not inside a command. Things can get really messy when you start creating objects inside commands. Have a look at our 2016 kitbot code for how we usually do it (sorry it's really messy, things haven't been cleaned up). Also check out wpilib for more details and best practices for command based code: http://wpilib.screenstepslive.com/s/...ed-programming

Last edited by Adnewhouse : 22-01-2017 at 20:24.
Reply With Quote
  #3   Spotlight this post!  
Unread 22-01-2017, 20:35
Robochris Robochris is offline
Registered User
FRC #6722
 
Join Date: Jan 2017
Location: Florida
Posts: 3
Robochris is an unknown quantity at this point
Re: CIM coders help!

Thank you sir i will definitely try that. Thanks for showing an example.
Reply With Quote
  #4   Spotlight this post!  
Unread 22-01-2017, 21:00
AustinShalit's Avatar
AustinShalit AustinShalit is offline
Registered User
AKA: אוסטין
no team (WPILib Suite Developer)
 
Join Date: Dec 2013
Rookie Year: 2008
Location: Los Angeles/Worcester/Israel
Posts: 154
AustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of light
Re: CIM coders help!

It looks like you are creating multiple instances of the command which is trying to allocate the same port multiple times. I think you want this to be a Subsystem instead of a command. Have you looked into using RobotBuilder to setup the framework of your code?

https://wpilib.screenstepslive.com/s/4485/m/26402
__________________
Reply With Quote
  #5   Spotlight this post!  
Unread 22-01-2017, 21:04
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: CIM coders help!

In your example you are creating CANTalon objects, so the number in the constructor is actually the CAN ID and not a roboRIO port number. So that in itself should not be a conflict.

Code:
DriveCommand::DriveCommand() {
	victor = new Victor(0);
	victor2 = new Victor(1);
	talon = new CANTalon(1);
	talon2 = new CANTalon(2);
	CIM = new Encoder(0, 1, false, Encoder::EncodingType::k4X);
}
I'm wondering if the command is being created more than once, which would cause duplicate allocations which are indicated by your output:

Code:
ERROR -1029 HAL: Resource already allocated, Minimum Value: 0, Maximum Value: 20, Requested Value: 0 PWM [PWM.cpp:43] 
ERROR -1029 HAL: Resource already allocated, Minimum Value: 0, Maximum Value: 20, Requested Value: 1 PWM [PWM.cpp:43] 
ERROR -1029 HAL: Resource already allocated, Minimum Value: 0, Maximum Value: 31, Requested Value: 0 DigitalInput [DigitalInput.cpp:43] 
ERROR -1029 HAL: Resource already allocated, Minimum Value: 0, Maximum Value: 31, Requested Value: 1 DigitalInput [DigitalInput.cpp:43] 
ERROR -1098 HAL: A handle parameter was passed incorrectly InitEncoder [Encoder.cpp:43]
Ideally you would want to create the sensors and speed controllers in a subsystem rather than a command and refer to methods on the subsystem to actually operate the drive base. That way, creating multiple instance of commands won't double-allocate the sensors.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
  #6   Spotlight this post!  
Unread 28-01-2017, 10:25
brainbounce brainbounce is offline
Registered User
AKA: Bob
FRC #3225 (Wolverine Robotics)
Team Role: Mentor
 
Join Date: Jan 2017
Rookie Year: 2016
Location: Salt Lake City
Posts: 2
brainbounce is an unknown quantity at this point
Re: CIM coders help!

I don't think you should try to debug your program until you have the wiring correct. The CIMCoder uses 2 DIO slots on the RoboRio, and needs external pull-up resistors.
Download the spec sheet from AndyMark to verify, but:
Orange Pin1 goes to +5V
Blue Pin2 goes to Signal0
Black Pin3 goes to GND
Yellow Pin4 goes to Signal1
(2) 10K pull-up resistors between +5V and each of the signal wires.
Reply With Quote
  #7   Spotlight this post!  
Unread 28-01-2017, 19:14
garyk garyk is offline
Programming Mentor: 668, 972, 2643
FRC #0668 (Apes of Wrath)
Team Role: Mentor
 
Join Date: Dec 2006
Rookie Year: 2005
Location: Santa Clara (Silicon Valley) Calif.
Posts: 94
garyk is a jewel in the roughgaryk is a jewel in the roughgaryk is a jewel in the roughgaryk is a jewel in the rough
Re: CIM coders help!

Quote:
Originally Posted by brainbounce View Post
I don't think you should try to debug your program until you have the wiring correct. The CIMCoder uses 2 DIO slots on the RoboRio, and needs external pull-up resistors.
Download the spec sheet from AndyMark to verify, but:
Orange Pin1 goes to +5V
Blue Pin2 goes to Signal0
Black Pin3 goes to GND
Yellow Pin4 goes to Signal1
(2) 10K pull-up resistors between +5V and each of the signal wires.
The RoboRIO DIO pins (when configured as Digital Inputs) are already pulled up, as were the same pins on the cRIO's Digital Sidecar and the ancient IFI Robot Controller. (Translation: the resistors aren't needed. Or are the CIMCoder's electrical signals in need of a stronger pullup?) Ref: NI roboRIO Users manual, Figure 16:
Attached Thumbnails
Click image for larger version

Name:	RoboRIOPullups.GIF
Views:	9
Size:	22.4 KB
ID:	21641  
__________________

Silicon Valley Regional 2005, 2006 972
Silicon Valley Regional 2007 668 Xerox Creativity Award
Championship Event 2007 668
Portland Regional 2008 668
Silicon Valley Regional 2008 668, 972
Beta Test Team 2008 668 (with 100 & 254)
Silicon Valley Regional 2009 668 Regional Chairman's Award; 2643
Sacramento Regional 2009 668 Winning Alliance (thanks, 1717 & 2473!), 2010 Winning Alliance 3256
CalGames 2006, 2007, 2008, 2009, 2010, 2011 Field Tech
NorCal FTC Regional 2008, 2009 Inspector
Championship Event 2009
San Diego, Silicon Valley Regionals; Champ. Event 2010 668, 2643, 3256
Silicon Valley, Madera Regional 2012 2643
WRRF Programming Instructor 2006-2016
Regional Woodie Flowers Award 2014 2643 Utah Regional


Last edited by garyk : 28-01-2017 at 19:38.
Reply With Quote
  #8   Spotlight this post!  
Unread 30-01-2017, 23:24
dravis dravis is offline
Registered User
AKA: Ben Randolph
FRC #0663
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2003
Location: Whitinsville
Posts: 6
dravis is an unknown quantity at this point
Re: CIM coders help!

I am also wondering if you need to use pull up resistor for the CIMCoder. I have used them without and didn't seem to have any issue. But based on the specs for CIMCoder it indicates we would need ~3-4k resistor for 5V supply.
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 04:16.

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