OCCRA
Go to Post The proper way to advance forward is by bringing the bottom up, not by limiting how high the top can fly. - artdutra04 [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 02-15-2018, 05:35 PM
BaconEater707 BaconEater707 is offline
Registered User
AKA: Sam Martin
FRC #2795 (Ohm's Claw)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2014
Location: Tulsa Tech
Posts: 2
BaconEater707 is an unknown quantity at this point
Problem With CANTalon ID's

I have 6 CANTalons on our robot. last year we had no issues. For some reason this year only two talons work while the other 4, if called in code, disable the robot. specifically the 'driveMotor's do this. the lift and winch motor work. Iv'e tried using different ID's on the talons to no avail. any advice would be much appreciated!
Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved.                        */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

#include <iostream>
#include <string>
#include <WPILib.h>
#include <IterativeRobot.h>
#include <LiveWindow/LiveWindow.h>
#include <SmartDashboard/SendableChooser.h>
#include <SmartDashboard/SmartDashboard.h>
#include "ctre/Phoenix.h"
#include "ctre/Phoenix.h"
#include <Drive/DifferentialDrive.h>

class Robot : public frc::IterativeRobot {



		Compressor *compressor = new Compressor (0);
		Solenoid *closeSOL = new Solenoid {0};
		Solenoid *raiseSOL = new Solenoid {1};
		WPI_TalonSRX *driveMotor1 = new WPI_TalonSRX(22);
		WPI_TalonSRX *driveMotor2 = new WPI_TalonSRX(23);
		WPI_TalonSRX *driveMotor3 = new WPI_TalonSRX(24);
		WPI_TalonSRX *driveMotor4 = new WPI_TalonSRX(25);
		WPI_TalonSRX *winchMotor = new WPI_TalonSRX(20);
		WPI_TalonSRX *liftMotor = new WPI_TalonSRX(21);
		Joystick *Xbox0 = new Joystick (0);
		Joystick *Xbox1 = new Joystick (1);
		DigitalInput *limit = new DigitalInput(10);
		int drivePower = .75;
		int liftPower = .25;



public:


	void RobotInit() {
		m_chooser.AddDefault(kAutoNameDefault, kAutoNameDefault);
		m_chooser.AddObject(kAutoNameCustom, kAutoNameCustom);
		m_chooser.AddObject(kAutoNameRight, kAutoNameRight);
		frc::SmartDashboard::PutData("Auto Modes", &m_chooser);

		raiseSOL->Set(true);
		closeSOL->Set(true);


		compressor->SetClosedLoopControl(true);
	}

	/*
	 * This autonomous (along with the chooser code above) shows how to
	 * select
	 * between different autonomous modes using the dashboard. The sendable
	 * chooser code works with the Java SmartDashboard. If you prefer the
	 * LabVIEW Dashboard, remove all of the chooser code and uncomment the
	 * GetString line to get the auto name from the text box below the Gyro.
	 *
	 * You can add additional auto modes by adding additional comparisons to
	 * the
	 * if-else structure below with additional strings. If using the
	 * SendableChooser make sure to add them to the chooser code above as
	 * well.
	 */
	void AutonomousInit() override {
		m_autoSelected = m_chooser.GetSelected();
		m_autoSelected = SmartDashboard::GetString(
		 		"Auto Selector", kAutoNameDefault);
		std::cout << "Auto selected: " << m_autoSelected << std::endl;

		if (m_autoSelected == kAutoNameCustom) {
			// Custom Auto goes here
		} else {
			// Default Auto goes here
		}
	}

	void AutonomousPeriodic() {
		if (m_autoSelected == kAutoNameCustom) {
			// Custom Auto goes here
		} else {
			// Default Auto goes here
		}
	}

	void TeleopInit()
	{
		driveMotor1 = 0;
		driveMotor2 = 0;
		driveMotor3 = 0;
		driveMotor4 = 0;
		compressor->SetClosedLoopControl(true);
	}

	void TeleopPeriodic()
	{


		float leftStickY = Xbox0->GetRawAxis(1);
		float rightStickY = Xbox0->GetRawAxis(5);
		float limitSwitch = limit->Get();



		if (Xbox0->GetRawButton(3))

		{

		//	winchMotor->Set(1);
			driveMotor1->Set(1);
		//	driveMotor2->Set(.5);
		//	driveMotor3->Set(.5);
		//	driveMotor4->Set(.5);
		}
		else
		{
			winchMotor->Set(0);
		}

		if (limitSwitch == 1)
		{

			liftMotor->Set(1);
		}
		else
		{
			liftMotor->Set(0);
		}


		if (Xbox0->GetRawButton(1))
					{
						closeSOL->Set(true);
					}
					else
					{
						closeSOL->Set(false);
					}
		if (Xbox0->GetRawButton(2))
					{
						raiseSOL->Set(false);
					}
					else
					{
						raiseSOL->Set(true);
					}


	}

	void TestPeriodic() {}

private:
	frc::LiveWindow& m_lw = *LiveWindow::GetInstance();
	frc::SendableChooser<std::string> m_chooser;
	const std::string kAutoNameDefault = "Middle";
	const std::string kAutoNameCustom = "Left";
	const std::string kAutoNameRight = "Right";
	std::string m_autoSelected;
};

START_ROBOT_CLASS(Robot)
Reply With Quote
  #2   Spotlight this post!  
Unread 02-15-2018, 06:57 PM
Thad House Thad House is online now
Volunteer, WPILib Contributor
no team (Waiting for 2021)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2010
Location: Thousand Oaks, California
Posts: 1,229
Thad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond repute
Re: Problem With CANTalon ID's

Quote:
Originally Posted by BaconEater707 View Post
I have 6 CANTalons on our robot. last year we had no issues. For some reason this year only two talons work while the other 4, if called in code, disable the robot. specifically the 'driveMotor's do this. the lift and winch motor work. Iv'e tried using different ID's on the talons to no avail. any advice would be much appreciated!
Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved.                        */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

#include <iostream>
#include <string>
#include <WPILib.h>
#include <IterativeRobot.h>
#include <LiveWindow/LiveWindow.h>
#include <SmartDashboard/SendableChooser.h>
#include <SmartDashboard/SmartDashboard.h>
#include "ctre/Phoenix.h"
#include "ctre/Phoenix.h"
#include <Drive/DifferentialDrive.h>

class Robot : public frc::IterativeRobot {



		Compressor *compressor = new Compressor (0);
		Solenoid *closeSOL = new Solenoid {0};
		Solenoid *raiseSOL = new Solenoid {1};
		WPI_TalonSRX *driveMotor1 = new WPI_TalonSRX(22);
		WPI_TalonSRX *driveMotor2 = new WPI_TalonSRX(23);
		WPI_TalonSRX *driveMotor3 = new WPI_TalonSRX(24);
		WPI_TalonSRX *driveMotor4 = new WPI_TalonSRX(25);
		WPI_TalonSRX *winchMotor = new WPI_TalonSRX(20);
		WPI_TalonSRX *liftMotor = new WPI_TalonSRX(21);
		Joystick *Xbox0 = new Joystick (0);
		Joystick *Xbox1 = new Joystick (1);
		DigitalInput *limit = new DigitalInput(10);
		int drivePower = .75;
		int liftPower = .25;



public:


	void RobotInit() {
		m_chooser.AddDefault(kAutoNameDefault, kAutoNameDefault);
		m_chooser.AddObject(kAutoNameCustom, kAutoNameCustom);
		m_chooser.AddObject(kAutoNameRight, kAutoNameRight);
		frc::SmartDashboard::PutData("Auto Modes", &m_chooser);

		raiseSOL->Set(true);
		closeSOL->Set(true);


		compressor->SetClosedLoopControl(true);
	}

	/*
	 * This autonomous (along with the chooser code above) shows how to
	 * select
	 * between different autonomous modes using the dashboard. The sendable
	 * chooser code works with the Java SmartDashboard. If you prefer the
	 * LabVIEW Dashboard, remove all of the chooser code and uncomment the
	 * GetString line to get the auto name from the text box below the Gyro.
	 *
	 * You can add additional auto modes by adding additional comparisons to
	 * the
	 * if-else structure below with additional strings. If using the
	 * SendableChooser make sure to add them to the chooser code above as
	 * well.
	 */
	void AutonomousInit() override {
		m_autoSelected = m_chooser.GetSelected();
		m_autoSelected = SmartDashboard::GetString(
		 		"Auto Selector", kAutoNameDefault);
		std::cout << "Auto selected: " << m_autoSelected << std::endl;

		if (m_autoSelected == kAutoNameCustom) {
			// Custom Auto goes here
		} else {
			// Default Auto goes here
		}
	}

	void AutonomousPeriodic() {
		if (m_autoSelected == kAutoNameCustom) {
			// Custom Auto goes here
		} else {
			// Default Auto goes here
		}
	}

	void TeleopInit()
	{
		driveMotor1 = 0;
		driveMotor2 = 0;
		driveMotor3 = 0;
		driveMotor4 = 0;
		compressor->SetClosedLoopControl(true);
	}

	void TeleopPeriodic()
	{


		float leftStickY = Xbox0->GetRawAxis(1);
		float rightStickY = Xbox0->GetRawAxis(5);
		float limitSwitch = limit->Get();



		if (Xbox0->GetRawButton(3))

		{

		//	winchMotor->Set(1);
			driveMotor1->Set(1);
		//	driveMotor2->Set(.5);
		//	driveMotor3->Set(.5);
		//	driveMotor4->Set(.5);
		}
		else
		{
			winchMotor->Set(0);
		}

		if (limitSwitch == 1)
		{

			liftMotor->Set(1);
		}
		else
		{
			liftMotor->Set(0);
		}


		if (Xbox0->GetRawButton(1))
					{
						closeSOL->Set(true);
					}
					else
					{
						closeSOL->Set(false);
					}
		if (Xbox0->GetRawButton(2))
					{
						raiseSOL->Set(false);
					}
					else
					{
						raiseSOL->Set(true);
					}


	}

	void TestPeriodic() {}

private:
	frc::LiveWindow& m_lw = *LiveWindow::GetInstance();
	frc::SendableChooser<std::string> m_chooser;
	const std::string kAutoNameDefault = "Middle";
	const std::string kAutoNameCustom = "Left";
	const std::string kAutoNameRight = "Right";
	std::string m_autoSelected;
};

START_ROBOT_CLASS(Robot)
In TeleopInit, the 4 driveMotor lines are actually setting the pointer to 0, causing the next time they are referenced to cause a segfault. Instead, most likely what you want is those 4 lines to be driveMotorX->Set(0); to actually set the value of the motor to 0.
__________________
All statements made are my own and not the feelings of any of my affiliated teams.
Teams 1510 and 2898 - Student 2010-2012
Team 4488 - Mentor 2013-2016
Co-developer of RobotDotNet, a .NET port of the WPILib.
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 03:09 PM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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