Go to Post I think it will be very hard to find one aspect of FIRST which doesn't inspire us. - Arefin Bari [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 15-01-2015, 15:42
DrOmni9885's Avatar
DrOmni9885 DrOmni9885 is offline
Registered User
FRC #1595 (Dragons)
Team Role: Programmer
 
Join Date: Feb 2013
Rookie Year: 2012
Location: Spokane, WA
Posts: 8
DrOmni9885 is an unknown quantity at this point
Arcade drive/Talon controller problems

Currently I'm still testing my program on a test bed which we have assembled that has 4 motors. Right now I have my program set up so that it initializes the robot with only two motors in its drive base and the other two for testing purposes. In our teleop stage I want to programmatically set it up so that when the A button on the controller is pressed one motor moves for a certain amount of time then stops so that the whole movement is automated. However, right now though the mechanism is supposedly programmatically working, the motors that are moving are the ones that I initialized as drive train motors (and the arcade drive doesn't work). Below is my code:

Code:
#include "WPILib.h"
#include "Timer.h"

class Robot: public IterativeRobot
{

	RobotDrive dragonBot; // robot drive system
	Joystick stick; // only joystick
	LiveWindow *lw;
	Talon l_motor;
	PowerDistributionPanel m_pdp;
	int autoLoopCounter;
	Timer autoTimer, raisingTimer;
	bool isButtonForRaisingPressed;

public:
	Robot() :
		dragonBot(0, 1),	// these must be initialized in the same order
		stick(0),		// as they are declared above.
		lw(NULL),
		l_motor(3),
		autoLoopCounter(0),
		autoTimer(),
		raisingTimer(),
		isButtonForRaisingPressed()
	{
		dragonBot.SetExpiration(0.1);
	}

private:
	void RobotInit()
	{
		lw = LiveWindow::GetInstance();
		autoTimer.Reset();
		raisingTimer.Reset();
	}

	void AutonomousInit()
	{
		autoLoopCounter = 0;
	}

	void AutonomousPeriodic()
	{
		if(autoLoopCounter <= 1) {
			autoTimer.Start();
			autoLoopCounter++;
		} else {
			double autoTime = autoTimer.Get();
			if(autoTime < 2) //Check if we've completed 100 loops (approximately 2 seconds)
			{
				dragonBot.Drive(-1.0, 0.0);
			}
			else if(autoTime >= 2 && autoTime <= 5) {
				dragonBot.Drive(0.25, 0.0);
			}
			else {
				dragonBot.Drive(0.0, 0.0);
				autoTimer.Stop();
			}
			SmartDashboard::PutNumber("elapsed time", autoTime);
			SmartDashboard::PutNumber("Current Left front", m_pdp.GetCurrent(0));
			SmartDashboard::PutNumber("Current Right Front", m_pdp.GetCurrent(1));
		}
	}

	void TeleopInit()
	{
		autoTimer.Reset();
		raisingTimer.Reset();
	}

	void TeleopPeriodic()
	{
		dragonBot.ArcadeDrive(stick);
		SmartDashboard::PutBoolean("is button for raising pressed?", isButtonForRaisingPressed);
		if(stick.GetRawButton(1)) {
			isButtonForRaisingPressed = true;
			raisingTimer.Start();
		}
		else {
			double raisingTime = raisingTimer.Get();
			if(isButtonForRaisingPressed == true && raisingTime <= 4) {
				l_motor(1.0);
			}
			else {
				l_motor(0.0);
				raisingTimer.Stop();
				raisingTimer.Reset();
				isButtonForRaisingPressed = false;
			}
			SmartDashboard::PutNumber("Voltage", m_pdp.GetVoltage());
		}
	}

	void TestPeriodic()
	{
		lw->Run();
	}
};

START_ROBOT_CLASS(Robot);
Additionally, on the l_motor(1.0) and l_motor(0.0) lines eclipse gives me and error that says "no match to call to '(Talon)(double'". I'd appreciate any help and in the meantime I will try to figure out why the motors are not working correctly. Thanks!
Reply With Quote
  #2   Spotlight this post!  
Unread 15-01-2015, 16:20
alopex_rex's Avatar
alopex_rex alopex_rex is offline
Rainbow Professionalism Dash
AKA: Scott Morton
FRC #0830 (The RatPack)
Team Role: Alumni
 
Join Date: Dec 2014
Rookie Year: 2012
Location: Ann Arbor, MI
Posts: 92
alopex_rex has a reputation beyond reputealopex_rex has a reputation beyond reputealopex_rex has a reputation beyond reputealopex_rex has a reputation beyond reputealopex_rex has a reputation beyond reputealopex_rex has a reputation beyond reputealopex_rex has a reputation beyond reputealopex_rex has a reputation beyond reputealopex_rex has a reputation beyond reputealopex_rex has a reputation beyond reputealopex_rex has a reputation beyond repute
Re: Arcade drive/Talon controller problems

First of all, the l_motor(1.0) call doesn't work because to drive the motor, you need to use the set function: l_motor.Set(1.0). What you have is meaningless, as l_motor is an object, not a function.

As for the arcade drive, I would try first using the ArcadeDrive function with constant inputs (ie ArcadeDrive(1.0, 0.0) ) and see what happens. That way you know the issue isn't with your joystick. It looks like you're using Talons for everything, but if the drive motors aren't talons then the way you initialized dragonBot won't work.

For testing purposes, don't bother with all the loops and timing; just try to run the motor if the button is pressed. The more complicated the code, the harder it is to find what's wrong.
__________________
Ratpack programming lead 2013 - 2015

ἔκλαγξαν δ᾽ ἄρ᾽ ὀϊστοὶ ἐπ᾽ ὤμων χωομένοιο / αὐτοῦ κινηθέντος: ὃ δ᾽ ἤϊε νυκτὶ ἐοικώς. (Ancient Greek nerds unite!)
Reply With Quote
  #3   Spotlight this post!  
Unread 15-01-2015, 21:53
DrOmni9885's Avatar
DrOmni9885 DrOmni9885 is offline
Registered User
FRC #1595 (Dragons)
Team Role: Programmer
 
Join Date: Feb 2013
Rookie Year: 2012
Location: Spokane, WA
Posts: 8
DrOmni9885 is an unknown quantity at this point
Re: Arcade drive/Talon controller problems

Quote:
Originally Posted by alopex_rex View Post
First of all, the l_motor(1.0) call doesn't work because to drive the motor, you need to use the set function: l_motor.Set(1.0). What you have is meaningless, as l_motor is an object, not a function.

As for the arcade drive, I would try first using the ArcadeDrive function with constant inputs (ie ArcadeDrive(1.0, 0.0) ) and see what happens. That way you know the issue isn't with your joystick. It looks like you're using Talons for everything, but if the drive motors aren't talons then the way you initialized dragonBot won't work.

For testing purposes, don't bother with all the loops and timing; just try to run the motor if the button is pressed. The more complicated the code, the harder it is to find what's wrong.
Thanks, figured out the l_motor.Set part today and will create a simple testing program tomorrow.
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 09:55.

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