|
Re: Multiple .cpp files in Windriver
What we typically do is instantiate all our component pointers in the Robot constructor, then pass them into the sub-controller classes.
Example: Let's say my robot class is Robot2702
class ArmController2702
{
public:
ArmController2702(Victor* pClaw, Victor* pArm, Encoder* pArmEncoder) : m_pClaw(pClaw), m_pArm(pArm), m_pEncoder(pEncoder) {}
};
class Robot2702
{
public:
Robot2702()
{
clawMotor = new Victor(1,2);
armMotor = new Victor(3,4);
armEncoder = new Encoder(5,6,7,8);
armController = new ArmController2702(clawMotor, armMotor,armEncoder);
}
void OperatorControl() {}
void Autonomous() {}
};
Checks:
-It's a good idea to pass objects in or instantiate them in the constructor. That way, you know they're there before you start using the class.
-To figure out what's going on, I believe there is a function you can use called wpi_fatal which will halt execution. You could use it like this
if(armEncoder == NULL) wpi_fatal("oh no, our arm is missing!");
then watch the output in the console to see what's going on
-Make sure your battery is full. A low battery can cause the robot to reset once a motor draws current and drops the voltage too low.
|