/*

ARIA header files for use with ARNL 1.7.1

Copyright(C) 2004, 2005 ActivMedia Robotics, LLC. 
Copyright(C) 2006, 2007, 2008, 2009 MobileRobots Inc.
All rights reserved.

This copy of Aria was relicensed for use with Arnl and the Arnl
license by MobileRobots Inc.  If you wish to download a seperate
distribution of Aria licensed under the GPL or a commercial license go to
http://www.mobilerobots.com/SOFTWARE/aria.html or contact MobileRobots
Inc, at robots@mobilerobots.com or MobileRobots Inc,
10 Columbia Drive, Amherst, NH 03031; 800-639-9481

MobileRobots Inc hereby grants to other individuals or
organizations permission to use this software with Arnl and in
compliance with the Arnl license.  This software may not be
distributed to others except by MobileRobots Inc.

MobileRobots Inc does not make any representations about the
suitability of this software for any purpose.  It is provided "as is"
without express or implied warranty.

*/
#ifndef ARSERVERMODEDRIVE_H
#define ARSERVERMODEDRIVE_H

#include "ariaTypedefs.h"
#include "Aria.h"
#include "ArNetworking.h"
#include "ArServerMode.h"

class ArServerModeDrive : public ArServerMode
{
public:
  AREXPORT ArServerModeDrive(ArServerBase *server, ArRobot *robot,
			     bool takeControlOnJoystick = false);
  AREXPORT virtual ~ArServerModeDrive();
  AREXPORT virtual void activate(void);
  AREXPORT virtual void deactivate(void);
  /// This adds commands that'll let you disable and enable safe driving
  AREXPORT void addControlCommands(ArServerHandlerCommands *handlerCommands);
  AREXPORT void driveJoystick(double vel, 
                              double rotVel, 
                              bool isActivating = true);
  AREXPORT void serverDriveJoystick(ArServerClient *client,
				    ArNetPacket *packet);
  AREXPORT virtual void userTask(void);
  AREXPORT void setThrottleParams(int lowSpeed, int highSpeed);
  AREXPORT virtual ArActionGroup *getActionGroup(void) { return &myDriveGroup;}
  AREXPORT void setSafeDriving(bool safe);
  AREXPORT bool getSafeDriving(void);
  /// this action will be activated in unsafe mode
  AREXPORT void setExtraUnsafeAction(ArAction *action) 
    { myExtraUnsafeAction = action; }
protected:
  AREXPORT void serverSafeDrivingEnable(void);
  AREXPORT void serverSafeDrivingDisable(void);
  AREXPORT void joyUserTask(void);
  ArAction *myExtraUnsafeAction;
  ArJoyHandler *myJoyHandler;
  ArActionJoydrive myJoydriveAction;
  ArActionInput *myInputAction;
  ArActionStop myStopAction;
  ArActionGroupInput myDriveGroup;
  ArFunctor2C<ArServerModeDrive, ArServerClient *, ArNetPacket *> myServerDriveJoystickCB;
  ArFunctorC<ArServerModeDrive> myJoyUserTaskCB;
  bool myDriveSafely;
  bool myNewDriveSafely;
  double myVel;
  double myRotVel;
  bool myTakeControlOnJoystick;
  // for the simple commands
  ArServerHandlerCommands *myHandlerCommands;
  ArFunctorC<ArServerModeDrive> myServerSafeDrivingEnableCB;
  ArFunctorC<ArServerModeDrive> myServerSafeDrivingDisableCB;
};


#endif // ARNETMODEDRIVE_H
