|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Very basic programming issue
First of all, I know almost nothing of programming. We spent a lot of time on debugging and troubleshooting, and I'm just now getting around to writing the code. I have a tiny issue that I don't know how to fix.
I'm building my code off the sample template, and having almost no C++ knowledge, I'm working completely off example. My currently modified( not by much, just added a third motor) code is as follows: Code:
#include "WPILib.h"
#include "vision/AxisCamera2010.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 RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Joystick stick;// only joystick
Jaguar kicker; // call kicking motor
public:
RobotDemo(void):
myRobot(1, 2), // these must be initialized in the same order
stick(1),
kicker(3)// the motor for kicking should be plugged into slot 3
// as they are declared above.
{
GetWatchdog().SetExpiration(0.1);
}
/**
* Drive left & right motors for 2 seconds then stop
*/
void Autonomous(void)
{
// I edited this code for testing
GetWatchdog().SetEnabled(false);
myRobot.Drive(0.5, 0.0); // drive backwards half speed
Wait(1.0);
myRobot.Drive(0.0,0.0);// stop for a bit
Wait(1.0);
myRobot.Drive(-5.0, 0.0);// go back to where you started
Wait(1.0);
myRobot.Drive(0.0,0.0);
}
/**
* Runs the motors with arcade steering.
*/
void OperatorControl(void)
{
GetWatchdog().SetEnabled(true);
while (IsOperatorControl())
{
GetWatchdog().Feed();
myRobot.ArcadeDrive(stick); // drive with arcade style (use right stick)
if (stick.GetTrigger()) // use trigger to activate kicking device (I added this bit)
kicker.Set(1.0); // If trigger is pressed, full speed!
else
kicker.Set(.2); // Otherwise, go at 1/5 speed
Wait(0.005); // wait for a motor update time
}
}
};
START_ROBOT_CLASS(RobotDemo);
Do I need to modify RobotDrive? And if so, where do I modify it? If I modify a file in WPIlib, will the new file get built into my project? |
|
#2
|
||||
|
||||
|
Re: Very basic programming issue
Here's my take:
Set your PWM cables such that you get the following behaviour: Forward and Backwards are reversed Left and Right are reversed Hopefully when you do this, you'll notice that PWM 1 -> Left and PWM 2 -> Right, just as it should be based on what your code says. Power down the robot, and on ALL your drivetrain speed controllers, switch the red and black wires that lead to the motors. That will reverse their direction. Other here might recommend extensive coding changes to make this change in programming, but seeing as how you'd said your programming expertise is low, I think this is your best fix! Just make sure you document that you flipped these wires so that the next person who hooks up your motors knows to reverse them. |
|
#3
|
|||
|
|||
|
Re: Very basic programming issue
Thanks, that is exactly what was needed!
|
|
#4
|
|||
|
|||
|
Re: Very basic programming issue
Actually, to fix it just add a - before the GetAxis on the joyticks and it will run the motors in the opposite directions. The joyticks are very un-intuitive and have forward as a negative value. In case you're wondering, the - simply does a mathematical negative on the value
|
|
#5
|
||||
|
||||
|
Re: Very basic programming issue
Quote:
myRobot.ArcadeDrive(stick); not myRobot.ArcadeDrive(stick.GetY(), stick.GetX()); so your suggestion won't work (at least at this point) |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Very Basic: Get a program running on the cRio that will show video on Classmat | isaacdl | Control System | 6 | 23-01-2010 17:33 |
| very basic code help | mikelowry | C/C++ | 20 | 18-09-2009 18:38 |
| Very odd issue with WindRiver | GGCO | C/C++ | 1 | 24-01-2009 01:21 |
| BASIC programming | John Gutmann | Programming | 3 | 17-05-2005 12:15 |
| Very Basic Programming Question | kewlkid382 | Chit-Chat | 5 | 18-01-2003 11:11 |