nimu.h
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2006
4  * Toby Collett
5  *
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <usb.h>
23 #include <stdint.h>
24 #include <stdio.h>
25 #include <arpa/inet.h>
26 
27 
28 #define NIMU_VENDORID 0x10c4
29 #define NIMU_PRODUCTID 0xEA61
30 
31 #define NIMU_DATA_SIZE 38
32 
33 typedef unsigned char uint8_t;
34 typedef unsigned short uint16_t;
35 
36 
37 
38 class nimu_data
39 {
40  public:
41  uint8_t DeviceID;
42  uint8_t MessageID;
43  uint16_t SampleTimer;
44  short GyroX;
45  short GyroY;
46  short GyroZ;
47  short AccelX;
48  short AccelY;
49  short AccelZ;
50  short MagX;
51  short MagY;
52  short MagZ;
53  short GyroTempX;
54  short GyroTempY;
55  short GyroTempZ;
56 
57  void Print() {
58  printf("%04X %04X %04X,%04X %04X %04X\n",GyroX,GyroY,GyroZ,AccelX,AccelY,AccelZ);
59  }
60 };
61 
62 class nimu
63 {
64  public:
65  nimu();
66  ~nimu();
67 
68  int Open();
69  int Close();
70 
71  nimu_data GetData();
72 
73  private:
74  usb_dev_handle * nimu_dev;
75 
76 };
77 
#define PLAYER_WARN1(msg, a)
Error message macros.
Definition: error.h:90
position 2d velocity command
Definition: player_interfaces.h:617
#define PLAYER_MSG3(level, msg, a, b, c)
Error message macros.
Definition: error.h:108
player_pose2d_t vel
translational velocities [m/s,m/s,rad/s] (x, y, yaw)
Definition: player_interfaces.h:620
#define PLAYER_LASER_DATA_SCAN
Data subtype: scan.
Definition: player_interfaces.h:845
static bool MatchMessage(player_msghdr_t *hdr, int type, int subtype, player_devaddr_t addr)
Helper for message processing.
Definition: message.h:159
uint32_t poses_count
The number of valid poses.
Definition: player_interfaces.h:788
double ReadFloat(int section, const char *name, double value)
Read a floating point (double) value.
Data: ranges (PLAYER_SONAR_DATA_RANGES)
Definition: player_interfaces.h:771
A pose in the plane.
Definition: player.h:217
Data AND Request/reply: geometry.
Definition: player_interfaces.h:785
player_pose3d_t pose
Laser pose, in robot cs (m, m, m, rad, rad, rad).
Definition: player_interfaces.h:948
double ReadTupleLength(int section, const char *name, int index, double value)
Read a length from a tuple (includes units conversion)
Generic message header.
Definition: player.h:161
virtual int MainSetup(void)
Sets up the resources needed by the driver thread.
Definition: driver.h:658
virtual void MainQuit(void)
Cleanup method for driver thread (called when main exits)
Definition: driver.h:664
Definition: nd.h:55
uint8_t type
Message type; must be one of PLAYER_MSGTYPE_*.
Definition: player.h:166
Encapsulates a device (i.e., a driver bound to an interface)
Definition: device.h:74
double px
X [m].
Definition: player.h:220
#define PLAYER_POSITION2D_CMD_VEL
Command: velocity (PLAYER_POSITION2D_CMD_VEL)
Definition: player_interfaces.h:581
uint8_t subtype
Message subtype; interface specific.
Definition: player.h:168
virtual void Main(void)=0
Main method for driver thread.
double ReadAngle(int section, const char *name, double value)
Read an angle (includes unit conversion).
int ReadInt(int section, const char *name, int value)
Read an integer value.
double ReadLength(int section, const char *name, double value)
Read a length (includes unit conversion, if any).
void * GetPayload()
Get pointer to payload.
Definition: message.h:188
#define PLAYER_MSGTYPE_DATA
A data message.
Definition: player.h:95
double py
Y [m].
Definition: player.h:222
#define PLAYER_POSITION2D_REQ_GET_GEOM
Request/reply: geometry.
Definition: player_interfaces.h:483
Definition: nd.h:177
Definition: nd.h:79
float * ranges
Range readings [m].
Definition: player_interfaces.h:896
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Message handler.
#define PLAYER_MSGTYPE_REQ
A request message.
Definition: player.h:106
#define PLAYER_LASER_REQ_GET_GEOM
Request/reply subtype: get geometry.
Definition: player_interfaces.h:854
#define PLAYER_SONAR_DATA_RANGES
Data subtype: ranges.
Definition: player_interfaces.h:761
Request/reply: Get geometry.
Definition: player_interfaces.h:945
double ReadTupleAngle(int section, const char *name, int index, double value)
Read an angle form a tuple (includes units conversion)
float * ranges
The range readings [m].
Definition: player_interfaces.h:776
int ReadDeviceAddr(player_devaddr_t *addr, int section, const char *name, int code, int index, const char *key)
Read a device id.
Definition: nd.h:140
int GetTupleCount(int section, const char *name)
Get the number of values in a tuple.
#define PLAYER_SONAR_REQ_GET_GEOM
Request/reply subtype: get geometry.
Definition: player_interfaces.h:755
Class for loading configuration file information.
Definition: configfile.h:196
int ReadTupleInt(int section, const char *name, int index, int value)
Read an integer from a tuple field.
A device address.
Definition: player.h:145
An autopointer for the message queue.
Definition: message.h:73
player_pose2d_t vel
translational velocities [m/s,m/s,rad/s] (x, y, yaw)
Definition: player_interfaces.h:611
position2d data
Definition: player_interfaces.h:606
position2d geom
Definition: player_interfaces.h:655
A pose in space.
Definition: player.h:228
Definition: nimu.h:62
#define PLAYER_ERROR(msg)
Error message macros.
Definition: error.h:81
float min_angle
Start and end angles for the laser scan [rad].
Definition: player_interfaces.h:886
Base class for drivers which oeprate with a thread.
Definition: driver.h:552
uint32_t ranges_count
The number of valid range readings.
Definition: player_interfaces.h:774
#define PLAYER_POSITION2D_DATA_STATE
Data: state (PLAYER_POSITION2D_DATA_STATE)
Definition: player_interfaces.h:568
player_pose3d_t * poses
Pose of each sonar, in robot cs.
Definition: player_interfaces.h:790
double timestamp
Time associated with message contents (seconds since epoch)
Definition: player.h:170
player_pose2d_t pos
position [m,m,rad] (x, y, yaw)
Definition: player_interfaces.h:609
Definition: nd.h:156
#define PLAYER_POSITION2D_CMD_POS
Command: position (PLAYER_POSITION2D_CMD_POS)
Definition: player_interfaces.h:588
uint32_t size
Size in bytes of the payload to follow.
Definition: player.h:174
Reference-counted message objects.
Definition: message.h:132
#define PLAYER_WARN(msg)
Warning message macros.
Definition: error.h:89
#define PLAYER_MSGTYPE_CMD
A command message.
Definition: player.h:99
double pa
yaw [rad]
Definition: player.h:224
Base class for all drivers.
Definition: driver.h:108
Definition: nimu.h:38
#define PLAYER_MSG0(level, msg)
General messages.
Definition: error.h:105
#define PLAYER_MSG2(level, msg, a, b)
Error message macros.
Definition: error.h:107
uint8_t state
Motor state (FALSE is either off or locked, depending on the driver).
Definition: player_interfaces.h:622
uint8_t stall
Are the motors stalled?
Definition: player_interfaces.h:613
float resolution
Angular resolution [rad].
Definition: player_interfaces.h:890
uint32_t ranges_count
Number of range readings.
Definition: player_interfaces.h:894
Data: scan (PLAYER_LASER_DATA_SCAN)
Definition: player_interfaces.h:883
player_msghdr_t * GetHeader()
Get pointer to header.
Definition: message.h:186
player_devaddr_t addr
Device to which this message pertains.
Definition: player.h:164
#define PLAYER_MSGQUEUE_DEFAULT_MAXLEN
Default maximum length for a message queue.
Definition: player.h:76
position2d position command
Definition: player_interfaces.h:626
player_pose2d_t pos
position [m,m,rad] (x, y, yaw)
Definition: player_interfaces.h:629