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

ArRatioInputRobotJoydrive.cpp

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
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 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #include "ArExport.h"
00027 #include "ariaOSDef.h"
00028 #include "ArRatioInputRobotJoydrive.h"
00029 #include "ArRobot.h"
00030 #include "ArRobotJoyHandler.h"
00031 #include "ariaInternal.h"
00032 #include "ArCommands.h"
00033 
00040 AREXPORT ArRatioInputRobotJoydrive::ArRatioInputRobotJoydrive(
00041     ArRobot *robot, ArActionRatioInput *input, 
00042     int priority, bool requireDeadmanPushed) :
00043   myFireCB(this, &ArRatioInputRobotJoydrive::fireCallback)
00044 {
00045   myRobot = robot;
00046   myInput = input;
00047   myInput->addFireCallback(priority, &myFireCB);
00048   myRequireDeadmanPushed = requireDeadmanPushed;
00049   myDeadZoneLast = false;
00050   myFireCB.setName("RobotJoydrive");
00051   
00052   if ((myRobotJoyHandler = Aria::getRobotJoyHandler()) == NULL)
00053   {
00054     myRobotJoyHandler = new ArRobotJoyHandler(robot);
00055     Aria::setRobotJoyHandler(myRobotJoyHandler);
00056   }
00057 
00058 }
00059 
00060 AREXPORT ArRatioInputRobotJoydrive::~ArRatioInputRobotJoydrive()
00061 {
00062 
00063 }
00064 
00065 AREXPORT void ArRatioInputRobotJoydrive::fireCallback(void)
00066 {
00067   bool printing = false;
00068 
00069   bool button1 = myRobotJoyHandler->getButton1();
00070   // if we need the deadman to activate and it isn't pushed just bail
00071   if (myRequireDeadmanPushed && !button1)
00072   {
00073     if (printing)
00074       printf("Nothing\n");
00075     myDeadZoneLast = false;
00076     return;
00077   }
00078 
00079   double rotRatio;
00080   double transRatio;
00081   double throttleRatio;
00082 
00083   myRobotJoyHandler->getDoubles(&rotRatio, &transRatio, &throttleRatio);
00084   
00085   rotRatio *= 100.0;
00086   transRatio *= 100.0;
00087   throttleRatio *= 100.0;
00088 
00089   bool doTrans = true;
00090   bool doRot = true;
00091 
00092   
00093   if (!myRequireDeadmanPushed)
00094   {
00095     doTrans = ArMath::fabs(transRatio) > 33;
00096     doRot = ArMath::fabs(rotRatio) > 33;
00097   }
00098 
00099   if (!doTrans && !doRot)
00100   {
00101     // if the joystick is in the center, we don't need the deadman,
00102     // and we were stopped lasttime, then just let other stuff go
00103     if (myDeadZoneLast && !myRequireDeadmanPushed) 
00104     {
00105       if (printing)
00106     printf("deadzone Nothing\n");
00107       return;
00108     }
00109     // if the deadman doesn't need to be pushed let something else happen here
00110     if (printing)
00111       printf("deadzone\n");
00112     //myInput->setRatios(transRatio, rotRatio, throttleRatio);
00113     myInput->setRatios(0, 0, throttleRatio);
00114     myDeadZoneLast = true;
00115     return;
00116   }
00117 
00118   myDeadZoneLast = false;
00119   if (!doRot)
00120     rotRatio = 0;
00121   if (!doTrans)
00122     transRatio = 0;
00123 
00124   if (printing)
00125     printf("%.0f %.0f %.0f\n", transRatio, rotRatio, throttleRatio);
00126   
00127   if (printing)
00128     printf("(%ld ms ago) we got %d %d %.2f %.2f %.2f (speed %.0f %.0f)\n", 
00129        myRobotJoyHandler->getDataReceivedTime().mSecSince(),
00130        button1, myRobotJoyHandler->getButton2(), transRatio, rotRatio, 
00131        throttleRatio, myRobot->getVel(), myRobot->getRotVel());
00132 
00133   myInput->setRatios(transRatio, rotRatio, throttleRatio);
00134 }

Generated on Tue Feb 20 10:51:41 2007 for Aria by  doxygen 1.4.0