Log in

View Full Version : Assistance with RobotBuilder and Drive


droswell
05-02-2015, 11:02
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!

Alan Anderson
05-02-2015, 11:21
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() );
}


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)?

droswell
05-02-2015, 13:25
getJoystick1() returns a Joystick*, but I don't see a way to return the actual joystick instance instead of just a pointer

Alan Anderson
05-02-2015, 14:24
If you can't pass a Joystick, change the function to expect a Joystick * and change the stick.GetX() etc. to stick->GetX() instead.

droswell
05-02-2015, 16:33
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.

Alan Anderson
05-02-2015, 17:05
"undefined reference to `DriveSystem::takeJoystickInputs(Joystick*)"

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

droswell
05-02-2015, 18:05
This is the exact error, including the tick: undefined reference to `DriveSystem::takeJoystickInputs(Joystick*, Joystick*)'

FleventyFive
06-02-2015, 21:44
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 :)