Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   CIM coders help! (http://www.chiefdelphi.com/forums/showthread.php?t=154107)

Robochris 22-01-2017 19:45

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!

Adnewhouse 22-01-2017 20:21

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

Robochris 22-01-2017 20:35

Re: CIM coders help!
 
Thank you sir i will definitely try that. Thanks for showing an example.

AustinShalit 22-01-2017 21:00

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

BradAMiller 22-01-2017 21:04

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.

brainbounce 28-01-2017 10:25

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.

garyk 28-01-2017 19:14

Re: CIM coders help!
 
1 Attachment(s)
Quote:

Originally Posted by brainbounce (Post 1637405)
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:

dravis 30-01-2017 23:24

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.


All times are GMT -5. The time now is 21:57.

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