c++ motor control

I need help controlling a jaguar using the Y-axis of a joystick.:ahh: I am trying to complete code for last year’s robot in c++ to have a working base to program on this year. I have most of my code done, if you’d like to see it just ask and i’ll post, I can also post the error that wind river is giving me.

Thank you all in advanced!

I’m predicting no useful replies to this unless you post the error messages – at least.

My Code is:
#include “WPILib.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 *m_rollerstick;
    DriverStation *ds; // driver station
    Joystick *m_leftstick;
    Joystick *m_rightstick;
    Jaguar *RollerMotor;
    Solenoid *Sol1;
    Jaguar *rollermotor;

public:
RobotDemo(void)
{
ds = DriverStation::GetInstance();
myRobot = new RobotDrive(1, 2); // create robot drive base
m_leftstick = new Joystick(1); // create the joysticks
m_rightstick = new Joystick (2);
m_rollerstick = new Joystick (3);
RollerMotor = new Jaguar (3); // create the Jaguar for the roller
Compressor *c = new Compressor(4, 2); //creates the compressor object
c->Start(); //starts compressor
Sol1 = new Solenoid(1); // creates solenoid obects
GetWatchdog().SetExpiration(100);
}

/**
 * Drive left & right motors for 2 seconds then stop
 */
void Autonomous(void)
{
	GetWatchdog().SetEnabled(false);
	myRobot->Drive(0.5, 0.0); 	// drive forwards half speed
	Wait(2000); 				//    for 2 seconds
	myRobot->Drive(0.0, 0.0); 	// stop robot
	Wait(2000);
	myRobot->Drive (-0.5, 0.0); //drive backwards half speed
	Wait(2000);
	myRobot->Drive (0.0, 0.0); 
	Wait (2000);				
}

/**
 * Runs the motors with tank steering. 
 */
void OperatorControl(void)
{
	GetWatchdog().SetEnabled(true);
	while (IsOperatorControl())
	{
		GetWatchdog().Feed();
		myRobot->TankDrive(m_leftstick, m_rightstick); //sets the left and right joysticks to control the left and right motors
		RollerMotor.Set( m_rollerstick.GetY() ); //sets joystick 3 y-axis to controll the roller motor
		if (m_rollerstick->GetRawButton(4)) //gets button 4 from joystick 3 to control the soleniod on port 1, note: it is port one in the code, but is labeled port 0 on the hardware
		{Sol1->Set(true);}

	}
}

};

START_ROBOT_CLASS(RobotDemo);

the red section of code gives the error:
error: request for member Set' in((RobotDemo*)this)->RobotDemo::RollerMotor’, which
is of non-class type `Jaguar*’

This is a shot in the dark from a die-hard C programmer who simply can’t understand why people use C++.

Can you try this instead?

float foo = m_rollerstick.GetY();
RollerMotor.Set(foo); //sets joystick 3 y-axis to controll the roller motor

I just tried that, it seems that the error isn’t in how i had it set up, it doesn’t like something about the GetY and the Set, because its still returning the same errors. but it does separate the two errors into different lines which should make them easier to deal with.

errors:

GetY error:
error: request for member GetY' in((RobotDemo*)this)->RobotDemo::m_rollerstick’,
which is of non-class type Joystick*' Set error: error: request for memberSet’ in ((RobotDemo*)this)->RobotDemo::RollerMotor', which is of non-class typeJaguar*’

It’s a simple mistake. You need to replace RollerMotor.Set with RollerMotor->Set because you’re using a pointer. Probably just a typo.

edit: same thing for the joystick error

Oh, that’s just because they’re pointers.
Instead of m_rollerstick.GetY(), do m_rollerstick->GetY()
Same with the jaguar.

EDIT: Ninja!

YAY!! you guys are my heros! it worked, and i did the same motor.Set:)

Now tomorrow after final’s I’ll try to get it on the bot, i may be back with some more problems, but hopefully it will all go smoothly :cool: