|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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:
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() {
}
|
|
#2
|
||||
|
||||
|
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); Last edited by Adnewhouse : 22-01-2017 at 20:24. |
|
#3
|
|||
|
|||
|
Re: CIM coders help!
Thank you sir i will definitely try that. Thanks for showing an example.
|
|
#4
|
||||
|
||||
|
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 |
|
#5
|
|||
|
|||
|
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);
}
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] |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
||||
|
||||
|
Re: CIM coders help!
Quote:
Last edited by garyk : 28-01-2017 at 19:38. |
|
#8
|
|||
|
|||
|
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.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|