View Full Version : Craziest Bug I'v Ever Seen--C++
btreyl11
22-01-2013, 17:08
My robot is completely ignoring the code we try to put on it and just doing arcade mode. We have tried the robot default code, customizing the simple robot code, rewiring to pwm's and the CAN system. We have renumbered the pwm's in various ways and tried writing the code with and without the DriverStation object. we have tried declaring this object as
myRobot = new RobotDrive(1,2);
and
myRobot = new RobotDrive(1,2,3,4);
I honestly don't know what to do and my team want to convert to lab view at this point. I really don't want to do that and would have to resign as head of programming if that happened so PLEASE HELP!!!
MetalJacket
22-01-2013, 17:13
Try declaring it as
RobotDrive *myRobot = new RobotDrive( 1, 2, 3, 4 );
// this creates a pointer to the object's memory location
or
RobotDrive myRobot( 1, 2, 3, 4 );
If you use the first one and it works, whenever you use any of the object's member functions, you will have to type
myRobot->TankDrive( /* arguments */ );
as opposed to
myRobot.TankDrive( /* arguments */ );
which will work for the second version
William Kunkel
22-01-2013, 17:13
Can you give us more details, preferably code samples?
Kevin Sevcik
22-01-2013, 22:58
It sounds to me like you're not actually downloading code to the robot. This could be because you have something configured wrong or simply because your code has errors and isn't successfully compiling.
First, make sure when you build your code that it's successfully compiled. There will be lots of red and error stuff in the windriver output window if it hasn't compiled.
Next, make sure you have the cRIO, your laptop, and windriver configured correctly.
Go to the Imaging your cRIO Guide (http://wpilib.screenstepslive.com/s/3120/m/8559/l/89727-imaging-your-crio) and follow it step-by-step. That will make sure that your cRIO and laptop are setup correctly for C++.
Then go to the Building and Downloading a project to the cRIO Guide (http://wpilib.screenstepslive.com/s/3120/m/7913/l/79735-building-and-downloading-a-robot-project-to-the-crio). I'd recommend doing "Building a robot program" and "Verify that no User Code is running". Then skip ahead to "Loading a program to run on robot startup" and follow along till the end. Running in debug mode is a little more complicated and error prone than just deploying and rebooting. Hopefully after you reboot your robot, whatever code changes you've made will now show up on your robot.
GrimmReaper
23-01-2013, 10:07
Additionally if you think the program is getting loaded onto the cRio properly, you could also run NetConsole. Do a reboot from the drivers station while netconsole is up and watch the boot up. You might spot an error if the code is erroring. then try to enable it and try to drive - see if you get any errors on netconsole at that point.
good luck!
Mark McLeod
23-01-2013, 10:31
The .out file path that Deploy is set to use is probably not the one you are compiling.
It's probably an old or default path, so check what it is in FIRST Downloader Preferences.
btreyl11
23-01-2013, 13:02
Well my team seems to believe it is not necessarily a problem with our code but, with deploying the c++ code itself onto the robot but yes hear is our prototype drive code:
#include <WPILib.h>
#include <Vision/RGBImage.h>
#include <Vision/BinaryImage.h>
#include <Math.h>
class RobotDemo : public IterativeRobot
{
Joystick* Stick_xy;
Joystick* Stick_z;
Jaguar* motor1;
Jaguar* motor2;
Jaguar* motor3;
Jaguar* motor4;
Jaguar* motor5;
PWM* connect1;
PWM* connect2;
PWM* connect3;
PWM* connect4;
PWM* connect5;
//RobotDrive* myRobot;
Servo* xCam;
Servo* yCam;
DriverStation* Station;
DriverStationLCD* Station_out;
public:
RobotDemo(void) // as they are declared above.
{
Stick_xy = new Joystick(1);
Stick_z = new Joystick(2);
motor1 = new Jaguar(1);
motor2 = new Jaguar(2);
motor3 = new Jaguar(3);
motor4 = new Jaguar(4);
motor5 = new Jaguar(5);
connect1 = new PWM(1,1);
connect2 = new PWM(2,2);
connect3 = new PWM(3,3);
connect4 = new PWM(4,4);
connect5 = new PWM(5,5);
//myRobot = new RobotDrive(1,2,3,4);
Station = DriverStation::GetInstance();
Station_out = DriverStationLCD::GetInstance();
}
~RobotDemo(void)
{
delete Stick_xy;
delete Stick_z;
delete motor1;
delete motor2;
delete motor3;
delete motor4;
delete motor5;
//delete myRobot;
delete Station;
delete Station_out;
delete xCam;
delete yCam;
}
void Autonomous(void)
{
}
void TeleopContinuous(void)
{
if (Stick_xy->GetRawAxis(2)!= 0)//if the stick is moved up or down
{
motor1->SetSpeed(Stick_xy->GetRawAxis(1));
motor3->SetSpeed(Stick_xy->GetRawAxis(1));
}
if(Stick_xy->GetRawAxis(1) != 0)//if the stick moves left or right
{
motor2->SetSpeed(Stick_xy->GetRawAxis(2));
motor4->SetSpeed(Stick_xy->GetRawAxis(2));
}
if(Stick_z->GetRawAxis(2)!= 0)//if the z stick moves left or right
{
motor1->SetSpeed(Stick_z->GetRawAxis(1));
motor3->SetSpeed(-(Stick_z->GetRawAxis(1)));
}
if(Stick_z->GetRawAxis(1) != 0)
{
motor5->SetSpeed(Stick_z->GetRawAxis(1));
}
else
{
Stop();
}
}
void Test() {
}
private:
void Stop()
{
motor1->SetSpeed(0);
motor2->SetSpeed(0);
motor3->SetSpeed(0);
motor4->SetSpeed(0);
}
/*void GetCamPosition()
{
float xPos = 170 * Stick_z->GetRawAxis(1)+85;
float yPos = 170 * Stick_xy->GetRawAxis(2)+85;
if(Stick_z->GetRawAxis(2)!= 0)
{
while(xCam->SetAngle(2) >insert ammount && xCam->SetAngle(2)<insert Right angle)
{
xCam->SetAngle(Stick_z->GetRawAxis(2));
}
}
}*/
void Target()
{
/*
* MIDDLE GOALS have openings that are 54 in. wide and 21 in. tall
* bottom edge of the MIDDLE GOAL is located 88 5/8 in. above the FIELD
*----------------------------------------------------------------------
* HIGH GOAL is 54 in. wide and 12 in. tall
* bottom edge of the opening located 104 1/8 in. above the FIELD
*/
}
};
START_ROBOT_CLASS(RobotDemo);
some of it has been customized since the last time I posted. And it probably wont be used on the robot this year but, I am just curious how to fix it.
Joe Ross
23-01-2013, 13:08
From http://wpilib.screenstepslive.com/s/3120/m/8559/l/92653-2013-software-notes
Iterative robot templates no longer have the continuous methods. That is AutonomousContinuous, TeleopContinuous and DisabledContinuous methods are no longer included in the library. If you are looking for similar functionality threads is a possible alternative.
Your code in TeleopContinuous is not being executed. It should be in TeleopPeriodic.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.