ManusArm.hpp
Go to the documentation of this file.
00001 /*
00002  * ManusArm.hpp
00003  * Copyright 2013 University of Massachusetts Lowell
00004  * Authors: Abraham Shultz, Jonathan Hasenzahl
00005  */
00006 
00007 #ifndef MANUS_ARM_HPP_
00008 #define MANUS_ARM_HPP_
00009 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <sys/types.h>
00013 #include <sys/socket.h>
00014 #include <sys/ioctl.h>
00015 #include <net/if.h>
00016 #include <linux/can.h>
00017 #include <linux/can/raw.h>
00018 #include <string>
00019 #include <sstream>
00020 #include <string.h> //C strings, for strcpy
00021 #include <boost/thread.hpp>
00022 #include <exception>
00023 #include <vector>
00024 #include <time.h>
00025 #include "movement_definitions.h"
00026 
00027 // from can_comm.cpp by ktsui
00028 // MANUS STATUS; from Exact Dynamics
00029 // TRANSPARENT MODE MANUAL; SECTION 6.9
00030 #define STAT_NONE                                    0
00031 
00032 #define STAT_WARNING                              1
00033 #define MSG_GRIPPER_STUCK                    0
00034 #define MSG_WRONG_AREA                       1
00035 #define MSG_ARM_FOLDED_STRETCHED   2
00036 #define MSG_BLOCKED_MOTOR                  3
00037 #define MSG_MAX_ROT                               4
00038 
00039 #define STAT_GENERAL                               2
00040 #define MSG_FOLDED                                  0
00041 #define MSG_UNFOLDED                             1
00042 #define MSG_GRIPPER_INIT                         2
00043 #define MSG_ABS_MEASURE                       3
00044 
00045 #define STAT_ERROR                                   3
00046 #define MSG_IO_80C552                                     1
00047 #define MSG_ABS_ENCODER                               4
00048 #define MSG_MOVE_WITHOUT_INPUT         15
00049 
00050 #define CBOX_0_INIT                                   0x370
00051 #define CBOX_1_CARTESIAN                       0x371
00052 #define CBOX_4_JOINT                                 0x374
00053 #define CBOX_5_UNFOLD                            0x375
00054 #define CBOX_6_FOLD                                 0x376
00055 
00056 /* Amount of error allowed to consider a movement "over"
00057  * In cartesian motion units (0.022 mm)
00058  */
00059 #define CARTESIAN_SLOP 300
00060 
00061 /* About a foot, in 0.022mm units
00062  */
00063 #define CARTESIAN_FOOT 13854.54
00064 
00065 // Constant speed limits for each axis
00066 const int SPEED_LIMITS[][5] = { { 3, 10, 17, 23, 30 },  // X
00067                                                             { 10, 30, 50, 70, 90 }, // Y
00068                                                             { 10, 30, 50, 70, 90 }, // Z
00069                                                             { 1, 3, 5, 7, 9 },      // Yaw
00070                                                             { 1, 3, 5, 7, 9 },      // Pitch
00071                                                             { 1, 3, 5, 7, 9 },      // Roll
00072                                                             { 1, 4, 7, 10, 14 } };  // Grip
00073 
00074 int sign(int n)
00075 {
00076     return ((n >= 0) ? 1 : -1);
00077 }
00078 
00079 float sign(float n)
00080 {
00081     return ((n >= 0) ? 1.0f : -1.0f);
00082 }
00083 
00087 struct armState
00088 {
00089         bool isValid;
00090         int jointPositions[7];
00091         int cbox;
00092         std::string message;
00093 };
00094 
00101 class ManusArm
00102 {
00103 private:
00104         /* Constructor, copy constructor, assignment operator are all private to make singleton */
00105         ManusArm();
00106         ManusArm(ManusArm const&){};
00107         ManusArm& operator=(ManusArm const&);
00108         /* Pointer to the existing instance */
00109         static ManusArm* armInstance;
00110 
00111         /* for SocketCan communication */
00112         int canSock;
00113         bool running;
00114         void pollCanSocket();
00115 
00116         /* State maintenance and thread safety */
00117         armState currState;
00118         bool moveComplete;
00119         boost::mutex stateMutex;
00120         void setCbox(int cbox, can_frame* frm);
00121 
00122         /* Sending messages to the arm */
00123         void sendFrames(can_frame frame);
00124         std::vector<can_frame> sendQueue;
00125         void enqueueFrame(can_frame toSend);
00126 
00127         //Mode setting commands
00128         void setCartesian();
00129 
00130         //Motion
00131         boost::thread motionThread;
00132         void doCartesianMove(const CartesianMove& cmd);
00133         void doConstantMove(const ConstantMove& cmd);
00134 
00135 public:
00136         static ManusArm* instance();
00137         int init(std::string interface);
00138         std::string getPrintState();
00139         std::string getCsvState();
00140         void getPosition(float position[]);
00141         bool isMoveComplete() { return moveComplete; }
00142         void setMoveComplete(bool move_complete)
00143         {
00144                 boost::mutex::scoped_lock lock(stateMutex);
00145                 moveComplete = move_complete;
00146         }
00147 
00148         //Motion commands
00149         void fold();
00150         void unfold();
00151         void moveCartesian(const CartesianMove& cmd);
00152         void moveConstant(const ConstantMove& cmd);
00153 };
00154 
00155 class ArmException: public std::exception
00156 {
00157 private:
00158         char* msg;
00159 public:
00160         ArmException(char* message) throw();
00161         virtual const char* what() const throw();
00162 };
00163 
00164 #endif


arm
Author(s): Jonathan Hasenzahl
autogenerated on Sun Jan 5 2014 11:12:32