#ifndef asserv_hh #define asserv_hh // asserv.hh // marvin - programme du robot 2006. {{{ // // Copyright (C) 2006 Nicolas Schodet // // Robot APB Team/Efrei 2006. // Web: http://assos.efrei.fr/robot/ // Email: robot AT efrei DOT fr // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // }}} #include "proto/proto.hh" /// Dialog class with the motor control board. /// Units: /// - step: one step distance. /// - period: one motor control sampling period. class Asserv : public Proto::Receiver { public: /// Asserv clients must implement Receiver. class Receiver { public: virtual ~Receiver (void) { } virtual void receiveAck (int seq) = 0; virtual void receiveCounterStat (int l, int r) = 0; virtual void receivePos (double x, double y, double a) = 0; virtual void receiveSpeedStat (int t, int a) = 0; virtual void receivePosStat (int te, int ti, int ae, int ai) = 0; virtual void receivePwmStat (int l, int r) = 0; virtual void receiveTimerStat (const int *t, int tn) = 0; virtual void receiveInPort (unsigned int port) = 0; }; private: Proto proto_; std::string tty_; Receiver &receiver_; int intervalCounterStat_, intervalPos_, intervalSpeedStat_, intervalPosStat_, intervalPwmStat_, intervalTimerStat_, intervalInPort_; int footing_; int tAccel_, aAccel_; int tMaxSpeed_, aMaxSpeed_, tMaxSpeedSlow_, aMaxSpeedSlow_; int tkp_, tki_, tkd_, akp_, aki_, akd_, esat_, isat_; bool lInvertPwm_, rInvertPwm_; double stepPerMm_; public: /// Constructor. Asserv (Asserv::Receiver &receiver); /// Essaie de purger la liste d'émission et indique si elle est vide. bool sync (void); /// Attend que toute les émissions soit terminées. bool wait (int timeout = -1); /// Récupère le File Descriptor int getFd (void) const; /// Reset the board and send parameters. void reset (void); /// Set PWM. void pwm (int l, int r); /// Position consign offset. void offset (double t, double a); /// Set speed. void speed (int t, int a); /// Speed controlled position consign offset. void speedTo (double t, double a, int seq); /// Speed controlled angle consign offset. void speedAngle (double a, int seq); /// Find a hole. void findHole (int seq); /// Acknoledge. void ack (int seq); /// Change counter stat interval. void setIntervalCounterStat (int i); /// Change position report interval. void setIntervalPos (int i); /// Change speed stat interval. void setIntervalSpeedStat (int i); /// Change position control stat interval. void setIntervalPosStat (int i); /// Change pwm stat interval. void setIntervalPwmStat (int i); /// Change timer stat interval. void setIntervalTimerStat (int i); /// Change input port report interval. void setIntervalInPort (int i); /// Set current position. void setPos (double x, double y, double a); /// Set current x position. void setXPos (double x); /// Set current y position. void setYPos (double y); /// Set current angle. void setAngle (double a); /// Set footing. void setFooting (int f); /// Set acceleration. void setAccel (int t, int a); /// Set maximum speed for automatic movements. void setMaxSpeed (int t, int a, int ts, int as); /// Set motor control coeficients. void setCoef (int tkp, int tki, int tkd, int akp, int aki, int akd, int esat, int isat); /// Set PWM direction. void setPwmDir (bool invertL, bool invertR); /// Store to eeprom. void storeParams (void); /// Clear eeprom. void clearParams (void); /// Implémentation du proto::Receiver. void receive (char command, const Proto::Frame &frame); private: /// Convert mm to steps. int mmToStep (double mm) const; /// Convert steps to mm. double stepToMm (int step) const; /// Convert rad to avr angles. int radToAvr (double a) const; /// Convert avr angles to rad. double avrToRad (int a) const; /// Convert rad to steps. int radToStep (double a) const; }; #endif // asserv_hh