orca-robotics INTRODUCTION Overview Download and Install Documentation REPOSITORY Interfaces Drivers Libraries Utilities Software Map DEVELOPER Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
canpacket.h00001 /* 00002 * Orca-Robotics Project: Components for robotics 00003 * http://orca-robotics.sf.net/ 00004 * Copyright (c) 2004-2008 Alex Brooks, Alexei Makarenko, Tobias Kaupp 00005 * 00006 * This copy of Orca is licensed to you under the terms described in 00007 * the LICENSE file included in this distribution. 00008 * 00009 */ 00010 00011 #ifndef ORCA_SEGWAY_RMP_CAN_PACKET_H_ 00012 #define ORCA_SEGWAY_RMP_CAN_PACKET_H_ 00013 00014 #include <sys/types.h> 00015 #include <stdint.h> 00016 #include <string.h> 00017 00018 namespace segwayrmpacfr 00019 { 00020 00021 /* 00022 CAN Packets consist of: 00023 - Header (2 bytes in standard packet (which the RMP always uses)) 00024 - Data Length Code (2 bytes, always '8' for RMP) 00025 - Data (8 bytes, split into 4 2-byte slots) 00026 00027 Even if we're interfacing with USB, we still pass CAN packets 00028 (wrapped up in USB packets). 00029 00030 @note This code originates from Player/Stage project 00031 http://playerstage.sf.net, file: canio.h 00032 @author Alex Makarenko 00033 */ 00034 class CanPacket 00035 { 00036 public: 00037 00038 // Always use all 8 bytes 00039 static const int CAN_DATA_SIZE = 8; 00040 00041 CanPacket( uint32_t id=0 ); 00042 00043 // Sets the ID (what the RMP docs call the header) 00044 void setId( uint32_t id ) { id_ = id; } 00045 00046 // RMP has fixed-size messages 00047 const uint16_t dataLengthCode() { return 0x0008; } 00048 00049 // returns the value of the slotNum'th slot 00050 uint16_t getSlot(int slotNum) const; 00051 00052 // sets the slotNum'th slot to val 00053 void putSlot(const int slotNum, const uint16_t val); 00054 00055 // The id is the 'header' field in the RMP docs 00056 uint32_t id() const { return id_; } 00057 00058 // Allow direct access for memcpy 00059 uint8_t *msg() { return msg_; } 00060 const uint8_t *msg() const { return msg_; } 00061 00062 // Human-readable string for debugging 00063 char* toString() const; 00064 00065 private: 00066 00067 long id_; 00068 uint8_t msg_[CAN_DATA_SIZE]; 00069 00070 // Could store dataLengthCode and flags here, 00071 // but don't bother cause for the RMP they're always the same. 00072 // uint32_t dlc; 00073 // uint32_t flags; 00074 00075 }; 00076 00077 // 00078 // Some functions for building CAN packets 00079 // (all values are in the RMP's native representation) 00080 // 00081 00082 CanPacket 00083 statusCommandPacket( uint16_t statusCommandType, 00084 uint16_t value, 00085 int16_t speedCount, 00086 int16_t turnrateCount ); 00087 00088 CanPacket 00089 motionCommandPacket( int16_t speedCount, 00090 int16_t turnrateCount ); 00091 00092 CanPacket 00093 shutdownCommandPacket(); 00094 00095 } // namespace 00096 00097 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)