00001
00002
00003 #ifndef _ROBOTINOCOM_H_
00004 #define _ROBOTINOCOM_H_
00005
00006 #ifdef WIN32
00007 #ifdef robotinocom_EXPORTS
00008 #define ROBOTINOCOM_EXPORT __declspec(dllexport)
00009 #else
00010 #define ROBOTINOCOM_EXPORT //__declspec(dllimport)
00011 #endif
00012 #else
00013 #define ROBOTINOCOM_EXPORT __attribute__ ((visibility ("default")))
00014 #endif
00015
00016 #include <string>
00017 #include "robotinocom/camerastuff.h"
00018 #include "northstar/northstar_interface.h"
00019 #include "robotinocom/robotinoinfo.h"
00020
00021 class RobotinoComImpl;
00022
00036 enum RobotinoComError {NoError,ErrorConnectionRefused,ErrorSocketSend,ErrorSocketRead,ErrorImageServerCreate,ErrorImageServerBind,
00037 ErrorTimeout,ErrorConnectionBusy,ErrorClientCreate,ErrorHostNotFound,ErrorUndefined,ErrorWinsock2Initialization};
00038
00039
00040
00046 enum RobotinoComState {IdleState,ConnectingState,ConnectedState};
00047
00048 typedef void(*RobotinoErrorCb_t)( void* data, int error );
00049 typedef void(*RobotinoConnectionClosedCb_t)( void* data );
00050 typedef void(*RobotinoConnectedCb_t)( void* data );
00051 typedef void(*RobotinoInfoReceivedCb_t)( void* data );
00052 typedef void(*RobotinoImageReceivedCb_t)( void* userData, const unsigned char* imageData, unsigned int imageDataSize, RobotinoImageType imageType );
00053
00061 class ROBOTINOCOM_EXPORT RobotinoCom
00062 {
00063 public:
00064 RobotinoCom();
00065 ~RobotinoCom();
00066
00075 bool init( bool initWinsock2 = true );
00076
00089 void connectToHost( const std::string& hostname, int port, bool startAsyncCommunicationAfterConnect = true );
00090
00101 void connectToHost( std::string hostname, bool startAsyncCommunicationAfterConnect = true );
00102
00107 void close();
00108
00114 void setImagePort( unsigned int port );
00120 unsigned int imagePort() const;
00121
00128 void setTimeout( unsigned int msecs );
00134 unsigned int timeout() const;
00135
00142 static std::string errorString( int error );
00143
00152 void startAsyncCommunication();
00153
00160 void stopAsyncCommunication();
00161
00168 bool isConnected() const;
00169
00177 RobotinoComError error() const;
00178
00184 void clearError();
00185
00191 bool isValid() const;
00192
00198 bool update();
00199
00205 bool receiveImage();
00206
00212
00213
00222 void setConnectedCallback( RobotinoConnectedCb_t f, void* data );
00223
00233 void setErrorCallback( RobotinoErrorCb_t f, void* data );
00234
00243 void setConnectionClosedCallback( RobotinoConnectionClosedCb_t f, void* data);
00244
00251 void setRobotinoInfoReceivedCallback( RobotinoInfoReceivedCb_t f, void* data );
00252
00260 void setRobotinoImageReceivedCallback( RobotinoImageReceivedCb_t f, void* data );
00261
00269 const RobotinoImage* const lockImage();
00270
00276 void unlockImage();
00277
00284 void setImageRequest( bool request );
00285
00292 unsigned int numMotors() const;
00293
00302 void setVelocity( unsigned int motor, float rpm );
00303
00314 void setDriveLayout( double rb = 125.0f , double rw = 40.0, double fctrl = 900.0, double gear = 16, double mer = 2000 );
00315
00326 void getDriveLayout( double* rb, double* rw, double* fctrl, double* gear, double* mer );
00327
00336 void setVelocity( double vx, double vy, double omega );
00337
00346 void addVelocity( unsigned int motor, float rpm, float priority );
00347
00357 float actualVelocity( unsigned int motor );
00358
00366 void setKp( unsigned int motor, float value );
00367
00375 void setKd( unsigned int motor, float value );
00376
00384 void setKi( unsigned int motor, float value );
00385
00393 void setPowerOutput( float value );
00394
00400 float powerOutputCurrent( float* rawValue = NULL ) const;
00401
00407 void encoderInput( int* velocity, int* position ) const;
00408
00413 void resetEncoderInputPosition( bool reset );
00414
00421 float motorCurrent( unsigned int motor, float* rawValue = NULL ) const;
00422
00423
00429 bool bumper() const;
00430
00437 unsigned int numDistanceSensors() const;
00438
00445 float distance( unsigned int n ) const;
00446
00454 unsigned int adc( const std::string& name ) const;
00455
00463 float analogInput( unsigned int n ) const;
00464
00473 void setDigitalOutput( const std::string& name, bool value );
00474
00482 void setDigitalOutput( unsigned int n, bool value );
00483
00491 bool digitalInput( const std::string& name ) const;
00492
00500 bool digitalInput( unsigned int n ) const;
00501
00508 unsigned int numADC() const;
00509
00516 unsigned int numDigitalInput() const;
00517
00524 unsigned int numDigitalOutput() const;
00525
00530 unsigned int numRelays() const;
00531
00537 void setRelay( unsigned int relay, bool close );
00538
00544 unsigned int serialLineFrequency() const;
00545
00551 void setShutdown();
00552
00559 void setCameraParameters( const RobotinoCameraParameters& param );
00560
00567 RobotinoCameraParameters cameraParameters() const;
00568
00575 RobotinoComState state() const;
00576
00587 bool saveImageToFile( const RobotinoImage* image, const std::string& fileName );
00588
00596 float motorTime( unsigned int motor ) const;
00597
00603 void resetPosition( unsigned int motor, bool reset );
00604
00610 int position( unsigned int motor ) const;
00611
00619 void resetMotorTime( unsigned int motor, bool reset );
00620
00627 void setBrake( unsigned int motor, bool on );
00628
00635 float msecsElapsed() const;
00636
00643 NorthStarReadings northStarReadings() const;
00644
00651 void setNorthStarCommand( const NorthStarCommand& northStarCommand );
00652
00659 float current() const;
00660
00667 float voltageBatt1() const;
00668
00675 float voltageBatt1plus2() const;
00676
00683 RobotinoInfo robotinoInfo() const;
00684
00689 void setGripperEnabled( bool enable );
00690
00695 bool isGripperEnabled() const;
00696
00701 void setGripperClosed( bool close );
00702
00706 bool isGripperOpened() const;
00707
00711 bool isGripperClosed() const;
00712
00719 void setOdometry( float x, float y, float phi );
00720
00727 void getOdometry( float* x, float* y, float* phi );
00728
00729
00735 static unsigned int version();
00736
00737 private:
00738 RobotinoComImpl* _impl;
00739 };
00740
00741 #endif
00742