Assistance with RobotBuilder and Drive

Greetings,

We’re trying to use robotbuilder this year. We have PID and solenoids working, for some reason I’m having a lot of trouble getting the mecanum drivetrain code working.

I followed this tutorial http://wpilib.screenstepslive.com/s/4485/m/26402/l/255451-driving-the-robot-with-tank-drive-and-joysticks

and got the drive subsystem all set. When I try to add the method to the execute() section of our DriveWithJoystick command, I get the error "No known conversion for argument 1 from ‘Joystick*’ to ‘Joystick’.

From the command DriveWithJoystick


void DriveWithJoystick::Execute()
{
     Robot::driveSubsystem->takeJoystickInputs(Robot::io->getJoystick1() );
}

In my header file for my driveSubsystem, I added this

void takeJoystickInputs(Joystick stick);
void stop();

and finally in my driveSystem.cpp these are the two functions I added after InitDefaultCommand:


void  takeJoystickInputs(Joystick stick)
{
     Robot::driveSubsystem->robotDrive4->MecanumDrive_Cartesian(stick.GetX(), stick.GetY(), stick,GetZ() );
}

void stop()
{
      Robot::driveSubsystem->robotDrive4->StopMotor();
}

Thank you for any help you can provide!

What type does getJoystick1() return? The error suggests that you’re trying to give takeJoystickInputs() a pointer to a Joystick object, but the function expects an actual Joystick rather than a pointer to one.

Did you mean to call getJoystick(1)?

getJoystick1() returns a Joystick*, but I don’t see a way to return the actual joystick instance instead of just a pointer

If you can’t pass a Joystick, change the function to expect a **Joystick *** and change the stick.GetX() etc. to stick->GetX() instead.

Thanks for your help!

I changed the function to expect *Joystick and swapped the call to ->GetX() instead of .GetX()

I’m down to one error -
“undefined reference to `DriveSystem::takeJoystickInputs(Joystick*)”

I included the drivesystem.h file in my driving command, so I’m unsure why its not defined.

Did that backtick ` character get accidentally added to the code itself, or when you copied the error message?

This is the exact error, including the tick: undefined reference to `DriveSystem::takeJoystickInputs(Joystick*, Joystick*)’

Notice how for the InitDefaultCommand, the function is defined DriveSubsystem::InitDefaultCommand() { //whatever code }. (assuming you built with robotbuilder)

You need to say what class those functions are a part of, they don’t know just because they have the same file name as the header file (they are becomming global functions and so are undefined when you call them as part of the DriveSubsystem class) . If the actuators you are calling functions on are part of that subsystem, you also don’t need the Robot::driveSubsystem before each of them, though I suppose having it might not break it.

So I think doing this in your DriveSystem.cpp might fix it:


void  DriveSubsystem::takeJoystickInputs(Joystick *stick)
{
    robotDrive4->MecanumDrive_Cartesian(stick.GetX(), stick.GetY(), stick,GetZ() );
}

void DriveSubsystem::stop()
{
    robotDrive4->StopMotor();
}

I’m not sure about using a pointer or not for using a joystick as a parameter. I usually have joystick values called in the command, than passed into a subsystem function that takes generic floats for x,y, and rotation in the case of Mecanum drive so I can reuse that function in autonomous. Hope this helps, good luck!

Also, is it DriveSubsystem or DriveSystem? You seem to go back and forth in your comments, just make sure it’s consistent in your code :slight_smile: