Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArRatioInputRobotJoydrive.cpp

00001 /*
00002 ActivMedia Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004,2005 ActivMedia Robotics, LLC
00004 
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 ActivMedia Robotics for information about a commercial version of ARIA at 
00022 robots@activmedia.com or 
00023 ActivMedia Robotics, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 
00025 */
00026 
00027 #include "ArExport.h"
00028 #include "ariaOSDef.h"
00029 #include "ArRatioInputRobotJoydrive.h"
00030 #include "ArRobot.h"
00031 #include "ArRobotJoyHandler.h"
00032 #include "ariaInternal.h"
00033 #include "ArCommands.h"
00034 
00041 ArRatioInputRobotJoydrive::ArRatioInputRobotJoydrive(
00042         ArRobot *robot, ArActionRatioInput *input, 
00043         int priority, bool requireDeadmanPushed) :
00044   myFireCB(this, &ArRatioInputRobotJoydrive::fireCallback)
00045 {
00046   myRobot = robot;
00047   myInput = input;
00048   myInput->addFireCallback(priority, &myFireCB);
00049   myRequireDeadmanPushed = requireDeadmanPushed;
00050   myDeadZoneLast = false;
00051   myFireCB.setName("RobotJoydrive");
00052   
00053   if ((myRobotJoyHandler = Aria::getRobotJoyHandler()) == NULL)
00054   {
00055     myRobotJoyHandler = new ArRobotJoyHandler(robot);
00056     Aria::setRobotJoyHandler(myRobotJoyHandler);
00057   }
00058 
00059 }
00060 
00061 ArRatioInputRobotJoydrive::~ArRatioInputRobotJoydrive()
00062 {
00063 
00064 }
00065 
00066 void ArRatioInputRobotJoydrive::fireCallback(void)
00067 {
00068   bool printing = false;
00069 
00070   bool button1 = myRobotJoyHandler->getButton1();
00071   // if we need the deadman to activate and it isn't pushed just bail
00072   if (myRequireDeadmanPushed && !button1)
00073   {
00074     if (printing)
00075       printf("Nothing\n");
00076     myDeadZoneLast = false;
00077     return;
00078   }
00079 
00080   double rotRatio;
00081   double transRatio;
00082   double throttleRatio;
00083 
00084   myRobotJoyHandler->getDoubles(&rotRatio, &transRatio, &throttleRatio);
00085   
00086   rotRatio *= 100.0;
00087   transRatio *= 100.0;
00088   throttleRatio *= 100.0;
00089 
00090   bool doTrans = true;
00091   bool doRot = true;
00092 
00093   
00094   if (!myRequireDeadmanPushed)
00095   {
00096     doTrans = ArMath::fabs(transRatio) > 33;
00097     doRot = ArMath::fabs(rotRatio) > 33;
00098   }
00099 
00100   if (!doTrans && !doRot)
00101   {
00102     // if the joystick is in the center, we don't need the deadman,
00103     // and we were stopped lasttime, then just let other stuff go
00104     if (myDeadZoneLast && !myRequireDeadmanPushed) 
00105     {
00106       if (printing)
00107         printf("deadzone Nothing\n");
00108       return;
00109     }
00110     // if the deadman doesn't need to be pushed let something else happen here
00111     if (printing)
00112       printf("deadzone\n");
00113     //myInput->setRatios(transRatio, rotRatio, throttleRatio);
00114     myInput->setRatios(0, 0, throttleRatio);
00115     myDeadZoneLast = true;
00116     return;
00117   }
00118 
00119   myDeadZoneLast = false;
00120   if (!doRot)
00121     rotRatio = 0;
00122   if (!doTrans)
00123     transRatio = 0;
00124 
00125   if (printing)
00126     printf("%.0f %.0f %.0f\n", transRatio, rotRatio, throttleRatio);
00127   
00128   if (printing)
00129     printf("(%ld ms ago) we got %d %d %.2f %.2f %.2f (speed %.0f %.0f)\n", 
00130            myRobotJoyHandler->getDataReceivedTime().mSecSince(),
00131            button1, myRobotJoyHandler->getButton2(), transRatio, rotRatio, 
00132            throttleRatio, myRobot->getVel(), myRobot->getRotVel());
00133 
00134   myInput->setRatios(transRatio, rotRatio, throttleRatio);
00135 }

Generated on Wed Oct 19 12:56:36 2005 for Aria by  doxygen 1.4.0