View Single Post
  #1   Spotlight this post!  
Unread 14-01-2017, 16:25
CSkillet CSkillet is offline
Registered User
FRC #0135
 
Join Date: Jan 2016
Location: Indiana
Posts: 11
CSkillet is an unknown quantity at this point
CTRE Toolsuite with Command-Based C++

Hello,
I have been having an issue with using CANTalon.h class from the CTRE Toolsuite. I have been trying to run Talon Motor Controllers with a C++ Command-Based program and am having no luck.

My current setup has a PDP powered by a 12V battery. The PDP is powering both the RoboRIO and the Talon Motor Controller. I then have the CANBus going from the Talon to (1) one set of wires to the RoboRIO and (2) one set of wires to the PDP. I have tried using both a wired ans wireless connection.

I am using the following code to run the Talons:

.h of the subsystem:
Code:
#ifndef Motor_H
#define Motor_H

#include <Commands/Subsystem.h>
#include "CANTalon.h"

class Motor : public Subsystem {
private:
	// It's desirable that everything possible under private except
	// for methods that implement subsystem capabilities

	CANTalon* motor;

public:
	Motor();
	void InitDefaultCommand();
	void DriveMotor(float);
	void StopMotor();
};

#endif  // Motor_H
.cpp of the Subsystem
Code:
#include "Motor.h"
#include "../RobotMap.h"
#include "Commands/TestingMotor.h"

Motor::Motor() : Subsystem("Motor") {

	motor = new CANTalon(3);
	motor->EnableControl();
	motor->SetControlMode(CANTalon::ControlMode::kPercentVbus);
	motor->SetSafetyEnabled(false);
	motor->Set(0);
}

void Motor::InitDefaultCommand() {
	// Set the default command for a subsystem here.
	// SetDefaultCommand(new MySpecialCommand());
	SetDefaultCommand(new TestingMotor());
}

void Motor::DriveMotor(float motorPower) {
	motor->Set(motorPower);
}

void Motor::StopMotor() {
	motor->Set(0);
}

// Put methods for controlling this subsystem
// here. Call these from Commands.
.h of the Command
Code:
#ifndef TestingMotor_H
#define TestingMotor_H

#include "../CommandBase.h"

class TestingMotor : public CommandBase {
public:
	TestingMotor();
	void Initialize();
	void Execute();
	bool IsFinished();
	void End();
	void Interrupted();
};

#endif  // TestingMotor_H
.cpp of the Command
Code:
#include "TestingMotor.h"

TestingMotor::TestingMotor() {
	// Use Requires() here to declare subsystem dependencies
	// eg. Requires(Robot::chassis.get());
	Requires(motor.get());
}

// Called just before this Command runs the first time
void TestingMotor::Initialize() {

}

// Called repeatedly when this Command is scheduled to run
void TestingMotor::Execute() {
	motor->DriveMotor(.75f);
}

// Make this return true when this Command no longer needs to run execute()
bool TestingMotor::IsFinished() {
	return false;
}

// Called once after isFinished returns true
void TestingMotor::End() {
	motor->StopMotor();
}

// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void TestingMotor::Interrupted() {
	End();
}
The following line in the .cpp of the command:
Code:
motor = new CANTalon(3);
gives the following error:
Undefined Reference to CANTalon::CANTalon(int)

I have v4.4.1.9 of the CTRE Toolsuite installed on my computer. There has been no error associated with #include "CANTalon.h". There also has been no problems with the other functions of the CANTalon class I've been using:
Code:
motor->EnableControl();
motor->SetControlMode(CANTalon::ControlMode::kPercentVbus);
motor->SetSafetyEnabled(false);
motor->Set(0);
The weird thing is, when I use an IterativeRobot Program instead of a CommandBased Robot Program, the Talon runs perfectly fine. That's why I'm assuming the problem is associated with CommandBased. It's the exact same code as the one in the CommandBased file, just in a different strcutire obviously.

The Talons are always flashing orange, which mean the robot detects the CANBus and is disabled. When we enable the robot from the Driver Station, the lights are still flashing orange. Furthermore, the NI-Web Based Software shows the mode of the Talon in Mode 0: Throttle (Duty Cycle) when it is enabled.

We are able to control the Talons from the RoboRIO because we were able to update the firmware of them. We have tested multiple Talons, and neither of them have worked. The PDP has firmware version 1.40 and its lights are flashing green, so there isn't a problem with that.

Sometimes, that error goes away when we build Eclipse, and when we upload the code to the RoboRIO, we received the following error from the Driver Station:
ERROR -52010 NIFPGA: Resource Not Initialized GetFPGATime [Utility.cpp:171]
We assumed this error was a result of the CANTalon pointer motor not being defined because of the error it has received before.

Another time, we built the code and we received the following build error from Eclipse:
c:/frc/bin/../lib/gcc/arm-frc-linux-gnueabi/4.9.3/../../../../arm-frc-linux-gnueabi/bin/ld.exe: cannot find -lTalonSRXLib

We were wondering if anyone is receiving the same problem and if anyone knows how to solve the issue we are having.
Reply With Quote