|
From: <mor...@us...> - 2008-04-23 21:33:26
|
Revision: 169
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=169&view=rev
Author: morgan_quigley
Date: 2008-04-23 14:33:34 -0700 (Wed, 23 Apr 2008)
Log Message:
-----------
input devices (just joysticks for now) coming over from ros core svn. I anticipate this to include things like pedals, spaceball, mice, keyboard, etc., anything you might want to ship onto the botnet to control stuff
Added Paths:
-----------
pkg/branches/rosbus/input/
pkg/branches/rosbus/input/Makefile
pkg/branches/rosbus/input/joy/
pkg/branches/rosbus/input/joy/Makefile
pkg/branches/rosbus/input/joy/joy.cpp
pkg/branches/rosbus/input/joy/manifest.xml
pkg/branches/rosbus/input/joy/msg/
pkg/branches/rosbus/input/joy/msg/Joy.msg
pkg/branches/rosbus/input/joy_view/
pkg/branches/rosbus/input/joy_view/Makefile
pkg/branches/rosbus/input/joy_view/joy_view.cpp
pkg/branches/rosbus/input/joy_view/manifest.xml
Added: pkg/branches/rosbus/input/Makefile
===================================================================
--- pkg/branches/rosbus/input/Makefile (rev 0)
+++ pkg/branches/rosbus/input/Makefile 2008-04-23 21:33:34 UTC (rev 169)
@@ -0,0 +1,3 @@
+SUBDIRS = joy joy_view
+include $(shell rospack find mk)/recurse_subdirs.mk
+
Added: pkg/branches/rosbus/input/joy/Makefile
===================================================================
--- pkg/branches/rosbus/input/joy/Makefile (rev 0)
+++ pkg/branches/rosbus/input/joy/Makefile 2008-04-23 21:33:34 UTC (rev 169)
@@ -0,0 +1,4 @@
+SRC = joy.cpp
+OUT = joy
+PKG = joy
+include $(shell rospack find mk)/node.mk
Added: pkg/branches/rosbus/input/joy/joy.cpp
===================================================================
--- pkg/branches/rosbus/input/joy/joy.cpp (rev 0)
+++ pkg/branches/rosbus/input/joy/joy.cpp 2008-04-23 21:33:34 UTC (rev 169)
@@ -0,0 +1,88 @@
+#include <unistd.h>
+#include <math.h>
+#include <linux/joystick.h>
+#include <fcntl.h>
+#include "ros/node.h"
+#include "joy/MsgJoy.h"
+#include "std_msgs/MsgEmpty.h"
+
+void *s_joy_func(void *);
+using namespace ros;
+
+class Joy : public node
+{
+public:
+ MsgJoy joy_msg;
+ MsgEmpty deadman_msg;
+
+ int joy_fd;
+ string joy_dev;
+ int joy_buttons;
+
+ Joy() : node("joy")
+ {
+ param("joy_dev", joy_dev, "/dev/input/js0");
+ joy_fd = open(joy_dev.c_str(), O_RDONLY);
+ if (joy_fd <= 0)
+ log(FATAL, "couldn't open joystick %s.", joy_dev.c_str());
+ pthread_t joy_thread;
+ pthread_create(&joy_thread, NULL, s_joy_func, this);
+
+ advertise("joy", joy_msg);
+ advertise("deadman", deadman_msg);
+ }
+ void monitor_deadman()
+ {
+ while (ok())
+ {
+ usleep(100000);
+ if (joy_buttons & 0x20)
+ publish("deadman", deadman_msg);
+ }
+ }
+ void joy_func()
+ {
+ js_event event;
+ while (ok())
+ {
+ read(joy_fd, &event, sizeof(js_event));
+ if (event.type & JS_EVENT_INIT)
+ continue;
+ switch(event.type)
+ {
+ case JS_EVENT_BUTTON:
+ if (event.value)
+ joy_buttons |= (1 << event.number);
+ else
+ joy_buttons &= ~(1 << event.number);
+ publish("joy", joy_msg);
+ break;
+ case JS_EVENT_AXIS:
+ switch(event.number)
+ {
+ case 0: joy_msg.x1 = event.value / 32767.0; break;
+ case 1: joy_msg.y1 = -event.value / 32767.0; break;
+ case 2: joy_msg.x2 = event.value / 32767.0; break;
+ case 3: joy_msg.y2 = -event.value / 32767.0; break;
+ default: break;
+ }
+ publish("joy", joy_msg);
+ break;
+ }
+ }
+ }
+};
+
+void *s_joy_func(void *parent)
+{
+ ((Joy *)parent)->joy_func();
+}
+
+int main(int argc, char **argv)
+{
+ ros::init(argc, argv);
+ Joy joy;
+ joy.monitor_deadman();
+ return 0;
+}
+
Added: pkg/branches/rosbus/input/joy/manifest.xml
===================================================================
--- pkg/branches/rosbus/input/joy/manifest.xml (rev 0)
+++ pkg/branches/rosbus/input/joy/manifest.xml 2008-04-23 21:33:34 UTC (rev 169)
@@ -0,0 +1,7 @@
+<package>
+ <depend package="roscpp"/>
+ <depend package="std_msgs"/>
+ <export>
+ <cpp cflags="-I${prefix}/msg/cpp" />
+ </export>
+</package>
Added: pkg/branches/rosbus/input/joy/msg/Joy.msg
===================================================================
--- pkg/branches/rosbus/input/joy/msg/Joy.msg (rev 0)
+++ pkg/branches/rosbus/input/joy/msg/Joy.msg 2008-04-23 21:33:34 UTC (rev 169)
@@ -0,0 +1,5 @@
+float32 x1
+float32 y1
+float32 x2
+float32 y2
+int32 buttons
Added: pkg/branches/rosbus/input/joy_view/Makefile
===================================================================
--- pkg/branches/rosbus/input/joy_view/Makefile (rev 0)
+++ pkg/branches/rosbus/input/joy_view/Makefile 2008-04-23 21:33:34 UTC (rev 169)
@@ -0,0 +1,4 @@
+SRC = joy_view.cpp
+OUT = joy_view
+PKG = joy_view
+include $(shell rospack find mk)/node.mk
Added: pkg/branches/rosbus/input/joy_view/joy_view.cpp
===================================================================
--- pkg/branches/rosbus/input/joy_view/joy_view.cpp (rev 0)
+++ pkg/branches/rosbus/input/joy_view/joy_view.cpp 2008-04-23 21:33:34 UTC (rev 169)
@@ -0,0 +1,60 @@
+#include <unistd.h>
+#include <math.h>
+#include <GL/gl.h>
+#include "ros/node.h"
+#include "joy/MsgJoy.h"
+#include "sdlgl/sdlgl.h"
+
+using namespace ros;
+
+class JoyView : public node, public SDLGL
+{
+public:
+ MsgJoy joy;
+
+ JoyView() : node("joy_view")
+ {
+ subscribe("joy", joy, &JoyView::joy_cb);
+ init_gui(640, 480, "nav view");
+ }
+ void joy_cb()
+ {
+ request_render();
+ }
+ void render()
+ {
+ glClearColor(0.2,0.2,0.2,0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glLoadIdentity();
+ joy.lock();
+ glLineWidth(5);
+ glBegin(GL_LINES);
+ glColor3f(1, 0, 0);
+ glVertex2f(-1,0);
+ glVertex2f(-1 + joy.x1, joy.y1);
+
+ glColor3f(0, 1, 0);
+ glVertex2f(1, 0);
+ glVertex2f(1 + joy.x2, joy.y2);
+ glEnd();
+ joy.unlock();
+ SDL_GL_SwapBuffers();
+ }
+ void set_view_params(int width, int height)
+ {
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-2, 2, -2, 2, -1, 1);
+ glMatrixMode(GL_MODELVIEW);
+ request_render();
+ }
+};
+
+int main(int argc, char **argv)
+{
+ ros::init(argc, argv);
+ JoyView view;
+ view.main_loop();
+ return 0;
+}
+
Added: pkg/branches/rosbus/input/joy_view/manifest.xml
===================================================================
--- pkg/branches/rosbus/input/joy_view/manifest.xml (rev 0)
+++ pkg/branches/rosbus/input/joy_view/manifest.xml 2008-04-23 21:33:34 UTC (rev 169)
@@ -0,0 +1,6 @@
+<package>
+ <depend package="roscpp"/>
+ <depend package="std_msgs"/>
+ <depend package="joy"/>
+ <depend package="sdlgl"/>
+</package>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|