Go to Post Success is realizing that anything is possible, persistence is the key. - SlamminSammy [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 22-10-2009, 11:51
Rob Stehlik's Avatar
Rob Stehlik Rob Stehlik is offline
Registered User
FRC #0610 (Coyotes)
Team Role: Engineer
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Toronto
Posts: 101
Rob Stehlik is a glorious beacon of lightRob Stehlik is a glorious beacon of lightRob Stehlik is a glorious beacon of lightRob Stehlik is a glorious beacon of lightRob Stehlik is a glorious beacon of light
Help with simple program

Hello, I'm definitely not a programmer, but as a mentor to the team, I'm trying to get some simple C++ code working. I started with the sample code, and added a few things to get our robot running. The tank drive code works well, but I wanted to use the joystick triggers to operate the intake rollers on the robot. The idea is to run the bottom two rollers to pick balls up, then run all of the rollers to spew the balls out. Pressing the trigger on the right joystick runns all of the rollers as expected. But for some reason the left joystick trigger won't run the bottom two rollers. I know the joystick is okay, because I tested the code to run all of the rollers with the left trigger, and it worked fine. For some reason it won't run just the bottom two rollers. I have stared at my code for a while, and I don't see what is wrong. Any comments or tips would be much appreciated. See the code below:

#include "WPILib.h"

/**
* This is a demo program showing the use of the RobotBase class.
* The SimpleRobot class is the base of a robot application that will automatically call your
* Autonomous and OperatorControl methods at the right time as controlled by the switches on
* the driver station or the field controls.
*/
class MainRobot : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick leftstick; // left joystick
Joystick rightstick; // right joystick
Relay intakeroller;
Relay feedroller1; // relay for first feed roller
Relay feedroller2; // relay for second feed roller
Relay feedroller3; // relay for top feed roller
Victor topshooter;
Victor bottomshooter;
Gyro gyro;

public:
MainRobot(void): // these must be initialized in the same order as above
myRobot(1, 2), //left motor on PWM port 1, right motor on port 2
leftstick(2), //USB port 2
rightstick(1), //USB port 1
intakeroller(4, 6, intakeroller.kBothDirections), //relay port 6
feedroller1(4, 8, feedroller1.kBothDirections), //relay port 8
feedroller2(4, 3, feedroller2.kBothDirections), //relay port 3
feedroller3(4, 1, feedroller3.kBothDirections), //relay port 1
topshooter(4), //PWM port 4
bottomshooter(3), //PWM port 3
gyro(1,1) //analog port 1
{
myRobot.SetInvertedMotor(myRobot.kRearRightMotor, true);
GetWatchdog().SetExpiration(0.1);
}
/**
* Drive left & right motors for 1 second then stop
*/
void Autonomous(void)
{
GetWatchdog().SetEnabled(false);
myRobot.Drive(-0.5, 0.0); // drive forwards half speed
Wait(1.0); // for 1 second
myRobot.Drive(0.0, 0.0); // stop robot
}

/**
* Runs the motors with tank steering.
*/
void OperatorControl(void)
{
GetWatchdog().SetEnabled(true);
while (IsOperatorControl())
{
GetWatchdog().Feed();
myRobot.TankDrive(leftstick,rightstick); // drive with tank style


if (leftstick.GetTrigger()) {
intakeroller.Set(intakeroller.kForward); // pressing button 1L runs pickup rollers
feedroller1.Set(feedroller1.kForward);
}
else {
intakeroller.Set(intakeroller.kOff); // releasing button stops rollers
feedroller1.Set(feedroller1.kOff);
}
if (rightstick.GetTrigger()) {
intakeroller.Set(intakeroller.kForward); // pressing button 1R runs all rollers
feedroller1.Set(feedroller1.kForward);
feedroller2.Set(feedroller2.kForward);
feedroller3.Set(feedroller3.kForward);
bottomshooter.Set(0.75);
topshooter.Set(0.75);
}
else {
intakeroller.Set(intakeroller.kOff); // releasing button stops rollers
feedroller1.Set(feedroller1.kOff);
feedroller2.Set(feedroller2.kOff);
feedroller3.Set(feedroller3.kOff);
bottomshooter.Set(0.0);
topshooter.Set(0.0);
}

Wait(0.005); // wait for a motor update time
}
}
};

START_ROBOT_CLASS(MainRobot);
Reply With Quote
  #2   Spotlight this post!  
Unread 22-10-2009, 11:56
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,754
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Help with simple program

Your logic has a problem

The right joystick, because it comes second, overrides all your left joystick logic.

You need to turn off the bottom rollers only if both left AND right joysticks are off.

Along the line of:

Code:
if (rightjoystick) {
 //turn everything on
}
else if (leftjoystick) {
 //turn botton rollers on
 //turn top rollers off
} else
  //turn everything off
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 22-10-2009 at 12:42.
Reply With Quote
  #3   Spotlight this post!  
Unread 23-10-2009, 15:00
Rob Stehlik's Avatar
Rob Stehlik Rob Stehlik is offline
Registered User
FRC #0610 (Coyotes)
Team Role: Engineer
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Toronto
Posts: 101
Rob Stehlik is a glorious beacon of lightRob Stehlik is a glorious beacon of lightRob Stehlik is a glorious beacon of lightRob Stehlik is a glorious beacon of lightRob Stehlik is a glorious beacon of light
Re: Help with simple program

Brilliant, Mark. Thanks so much for your help. It works as expected now!
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with 2009 wiring/program downloading programmr FRC Control System 5 17-12-2008 21:57
EasyC Question regarding simple program aeasson Programming 6 14-01-2008 23:16
help with program loading psych0gambit Programming 2 17-02-2005 19:03
help with simple project erikh98 Technical Discussion 8 27-08-2004 11:24
HELP writing simple delphi program! dave_macca Programming 1 25-03-2004 00:35


All times are GMT -5. The time now is 11:59.

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