|
From: <jl...@us...> - 2008-04-21 21:48:57
|
Revision: 149
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=149&view=rev
Author: jleibs
Date: 2008-04-21 14:48:44 -0700 (Mon, 21 Apr 2008)
Log Message:
-----------
Some cleanup of etherdrive node.
Added Paths:
-----------
pkg/trunk/etherdrive/include/etherdrive/
pkg/trunk/etherdrive/include/etherdrive/etherdrive.h
pkg/trunk/etherdrive/nodes/
pkg/trunk/etherdrive/src/etherdrive_control/
pkg/trunk/etherdrive/src/etherdrive_control/Makefile
pkg/trunk/etherdrive/src/etherdrive_control/etherdrive_control.cpp
pkg/trunk/etherdrive/test/test_etherdrive/
pkg/trunk/etherdrive/test/test_etherdrive/Makefile
pkg/trunk/etherdrive/test/test_etherdrive/test_etherdrive.cpp
Removed Paths:
-------------
pkg/trunk/etherdrive/test/Makefile
pkg/trunk/etherdrive/test/test_etherdrive.cpp
Added: pkg/trunk/etherdrive/include/etherdrive/etherdrive.h
===================================================================
--- pkg/trunk/etherdrive/include/etherdrive/etherdrive.h (rev 0)
+++ pkg/trunk/etherdrive/include/etherdrive/etherdrive.h 2008-04-21 21:48:44 UTC (rev 149)
@@ -0,0 +1,84 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+#ifndef ETHERDRIVE_H
+#define ETHERDRIVE_H
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include <string>
+
+using namespace std;
+
+class EtherDrive
+{
+public:
+ EtherDrive();
+ ~EtherDrive();
+
+ // Initialize
+ bool init(string ip);
+
+ void shutdown();
+
+ // Manually send EtherDrive command.
+ int send_cmd(char* cmd, size_t cmd_len, char* buf, size_t buf_len);
+
+ // Enable motors
+ bool motors_on();
+
+ // Disable motors
+ bool motors_off();
+
+ // Send an array of motor commands up to 6 in length.
+ bool drive(size_t num, int32_t* drv);
+
+ // Send most recent motor commands, and retrieve update (this must be run at sufficient rate).
+ bool tick(size_t num = 0, int32_t* enc = 0, int32_t* curr = 0, int32_t* pwm = 0);
+private:
+ bool ready;
+
+ int32_t last_drv[6];
+
+ int mot_sock;
+ int cmd_sock;
+
+ struct sockaddr_in mot_addr_out;
+ struct sockaddr_in cmd_addr_out;
+};
+
+#endif
+
Added: pkg/trunk/etherdrive/src/etherdrive_control/Makefile
===================================================================
--- pkg/trunk/etherdrive/src/etherdrive_control/Makefile (rev 0)
+++ pkg/trunk/etherdrive/src/etherdrive_control/Makefile 2008-04-21 21:48:44 UTC (rev 149)
@@ -0,0 +1,4 @@
+SRC = etherdrive_control.cpp
+OUT = ../../nodes/etherdrive
+PKG = etherdrive
+include $(shell $(ROS_ROOT)/rospack find roscpp)/make_include/node.mk
Added: pkg/trunk/etherdrive/src/etherdrive_control/etherdrive_control.cpp
===================================================================
--- pkg/trunk/etherdrive/src/etherdrive_control/etherdrive_control.cpp (rev 0)
+++ pkg/trunk/etherdrive/src/etherdrive_control/etherdrive_control.cpp 2008-04-21 21:48:44 UTC (rev 149)
@@ -0,0 +1,152 @@
+///////////////////////////////////////////////////////////////////////////////
+// The axis_cam package provides a library that talks to Axis IP-based cameras
+// as well as ROS nodes which use these libraries
+//
+// Copyright (C) 2008, Morgan Quigley
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of Stanford University nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+
+#include "ros/ros_slave.h"
+#include "unstable_flows/FlowActuator.h"
+#include "etherdrive/etherdrive.h"
+#include <sstream>
+
+class EtherDrive_Control : public ROS_Slave
+{
+public:
+ FlowActuator* mot[6];
+ FlowActuator* mot_cmd[6];
+
+ string host;
+ EtherDrive *ed;
+ int frame_id;
+
+ float last_mot_val[6];
+ double pulse_per_rad[6];
+
+ ROS_Mutex control_mutex;
+
+ EtherDrive_Control() : ROS_Slave(), ed(NULL)
+ {
+
+ for (int i = 0;i < 6;i++) {
+ ostringstream oss;
+ oss << "mot" << i;
+ register_source(mot[i] = new FlowActuator(oss.str().c_str()));
+
+ oss << "_cmd";
+ register_sink(mot_cmd[i] = new FlowActuator(oss.str().c_str()), ROS_CALLBACK(EtherDrive_Control, mot_callback));
+
+ last_mot_val[i] = 0;
+ }
+
+ register_with_master();
+
+ if (!get_string_param(".host", host))
+ host = "10.0.0.151";
+ printf("EtherDrive host set to [%s]\n", host.c_str());
+
+ if (!get_int_param(".frame_id", &frame_id))
+ frame_id = -1;
+ printf("EtherDrive frame_id set to [%d]\n", frame_id);
+
+ for (int i = 0;i < 6;i++) {
+ ostringstream oss;
+ oss << ".pulse_per_rad" << i;
+ if (!get_double_param(oss.str().c_str(), &(pulse_per_rad[i])))
+ pulse_per_rad[i] = 1591.54943;
+ }
+
+ ed = new EtherDrive();
+ ed->init(host);
+ ed->motors_on();
+ }
+
+ virtual ~EtherDrive_Control()
+ {
+ if (ed)
+ delete ed;
+ }
+
+ bool do_tick()
+ {
+
+ int tmp_mot_cmd[6];
+
+ for (int i = 0; i < 6; i++) {
+ mot_cmd[i]->lock_atom();
+ if (mot_cmd[i]->valid) {
+ if (mot_cmd[i]->rel) {
+ last_mot_val[i] = mot[i]->val + mot_cmd[i]->val;
+ } else {
+ last_mot_val[i] = mot_cmd[i]->val;
+ }
+ }
+ mot_cmd[i]->valid = false; // set to invalid so we don't re-use
+
+ tmp_mot_cmd[i] = (int)(last_mot_val[i] * pulse_per_rad[i]);
+
+ mot_cmd[i]->unlock_atom();
+ }
+
+ control_mutex.lock();
+
+ printf("Commanding: %g -- %d\n", last_mot_val[1], tmp_mot_cmd[1]);
+
+ ed->drive(6,tmp_mot_cmd);
+
+ control_mutex.unlock();
+
+ int val[6];
+
+ if (!ed->tick(6,val)) {
+ return false;
+ }
+
+ for (int i = 0; i < 6; i++) {
+ mot[i]->val = val[i] / pulse_per_rad[i];
+ mot[i]->rel = false;
+ mot[i]->valid = true;
+ mot[i]->publish();
+ }
+ return true;
+ }
+
+ void mot_callback() { }
+
+};
+
+int main(int argc, char **argv)
+{
+ EtherDrive_Control a;
+ while (a.happy()) {
+ if (!a.do_tick())
+ {
+ a.log(ROS::ERROR,"Etherdrive tick failed.");
+ break;
+ }
+ }
+ return 0;
+}
+
Deleted: pkg/trunk/etherdrive/test/Makefile
===================================================================
--- pkg/trunk/etherdrive/test/Makefile 2008-04-21 21:46:26 UTC (rev 148)
+++ pkg/trunk/etherdrive/test/Makefile 2008-04-21 21:48:44 UTC (rev 149)
@@ -1,4 +0,0 @@
-SRC = test_etherdrive.cpp
-OUT = ../bin/test_etherdrive
-PKG = etherdrive
-include $(shell $(ROS_ROOT)/rospack find roscpp)/make_include/node.mk
Added: pkg/trunk/etherdrive/test/test_etherdrive/Makefile
===================================================================
--- pkg/trunk/etherdrive/test/test_etherdrive/Makefile (rev 0)
+++ pkg/trunk/etherdrive/test/test_etherdrive/Makefile 2008-04-21 21:48:44 UTC (rev 149)
@@ -0,0 +1,4 @@
+SRC = test_etherdrive.cpp
+OUT = test_etherdrive
+PKG = etherdrive
+include $(shell $(ROS_ROOT)/rospack find roscpp)/make_include/node.mk
Added: pkg/trunk/etherdrive/test/test_etherdrive/test_etherdrive.cpp
===================================================================
--- pkg/trunk/etherdrive/test/test_etherdrive/test_etherdrive.cpp (rev 0)
+++ pkg/trunk/etherdrive/test/test_etherdrive/test_etherdrive.cpp 2008-04-21 21:48:44 UTC (rev 149)
@@ -0,0 +1,80 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+#include "etherdrive/etherdrive.h"
+#include <iostream>
+
+using namespace std;
+
+int main() {
+
+ EtherDrive e;
+
+ if (!e.init("10.0.0.151")) {
+ cout << "Could not initialize etherdrive." << endl;
+ return -1;
+ }
+ e.motors_on();
+
+ int drv = 100000;
+ int enc[2];
+ int cur[2];
+
+ int count = 0;
+
+ while (1) {
+ if (!e.drive(1,&drv))
+ printf("Drive problem!.");
+ if (!e.tick(2,enc,cur))
+// // // printf("Tick problem!.");
+
+ printf("Encoder0: %d Current: %d\n", enc[0], cur[0]);
+ printf("Encoder1: %d Current: %d\n", enc[1], cur[1]);
+
+ if (abs(cur[0]) > 200) {
+ if (count++ > 50)
+ e.motors_off();
+ } else {
+ count = 0;
+ }
+
+ if (enc[0] == 100000) {
+ drv = -100000;
+ } else if (enc[0] == -100000) {
+ drv = 100000;
+ }
+ }
+
+ e.shutdown();
+}
Deleted: pkg/trunk/etherdrive/test/test_etherdrive.cpp
===================================================================
--- pkg/trunk/etherdrive/test/test_etherdrive.cpp 2008-04-21 21:46:26 UTC (rev 148)
+++ pkg/trunk/etherdrive/test/test_etherdrive.cpp 2008-04-21 21:48:44 UTC (rev 149)
@@ -1,67 +0,0 @@
-/*********************************************************************
-* Software License Agreement (BSD License)
-*
-* Copyright (c) 2008, Willow Garage, Inc.
-* All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-*
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above
-* copyright notice, this list of conditions and the following
-* disclaimer in the documentation and/or other materials provided
-* with the distribution.
-* * Neither the name of the Willow Garage nor the names of its
-* contributors may be used to endorse or promote products derived
-* from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-* POSSIBILITY OF SUCH DAMAGE.
-*********************************************************************/
-
-#include "etherdrive.h"
-#include <iostream>
-
-using namespace std;
-
-int main() {
-
- EtherDrive e;
-
- if (!e.init("10.0.0.151")) {
- cout << "Could not initialize etherdrive." << endl;
- return -1;
- }
- e.motors_on();
-
- int drv = 100000;
- int enc;
-
- while (1) {
- e.drive(1,&drv);
- e.tick(1,&enc);
-
- printf("Encoder: %d\n", enc);
-
- if (enc == 100000) {
- drv = -100000;
- } else if (enc == -100000) {
- drv = 100000;
- }
- }
-
- e.shutdown();
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jl...@us...> - 2008-04-25 19:43:58
|
Revision: 178
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=178&view=rev
Author: jleibs
Date: 2008-04-25 12:43:55 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
A little bit of clean up to the ethedrive class.
Modified Paths:
--------------
pkg/trunk/etherdrive/include/etherdrive/etherdrive.h
pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp
pkg/trunk/etherdrive/test/test_etherdrive/test_etherdrive.cpp
Added Paths:
-----------
pkg/trunk/etherdrive/test/test_etherdrive2/
pkg/trunk/etherdrive/test/test_etherdrive2/Makefile
pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp
Modified: pkg/trunk/etherdrive/include/etherdrive/etherdrive.h
===================================================================
--- pkg/trunk/etherdrive/include/etherdrive/etherdrive.h 2008-04-25 00:56:12 UTC (rev 177)
+++ pkg/trunk/etherdrive/include/etherdrive/etherdrive.h 2008-04-25 19:43:55 UTC (rev 178)
@@ -43,6 +43,8 @@
using namespace std;
+class EDMotor;
+
class EtherDrive
{
public:
@@ -63,15 +65,28 @@
// Disable motors
bool motors_off();
+ EDMotor get_motor(uint32_t m);
+
+ void set_drv(uint32_t m, int32_t drv);
+ int32_t get_enc(uint32_t m);
+ int32_t get_cur(uint32_t m);
+ int32_t get_pwm(uint32_t m);
+
// Send an array of motor commands up to 6 in length.
bool drive(size_t num, int32_t* drv);
// Send most recent motor commands, and retrieve update (this must be run at sufficient rate).
bool tick(size_t num = 0, int32_t* enc = 0, int32_t* curr = 0, int32_t* pwm = 0);
+
+
+
private:
bool ready;
int32_t last_drv[6];
+ int32_t last_enc[6];
+ int32_t last_cur[6];
+ int32_t last_pwm[6];
int mot_sock;
int cmd_sock;
@@ -80,5 +95,34 @@
struct sockaddr_in cmd_addr_out;
};
+class EDMotor
+{
+ friend class EtherDrive;
+public:
+ void set_drv(int32_t drv) {
+ driver->set_drv(motor, drv);
+ }
+
+ int32_t get_enc() {
+ return driver->get_enc(motor);
+ }
+
+ int32_t get_cur() {
+ return driver->get_cur(motor);
+ }
+
+ int32_t get_pwm() {
+ return driver->get_pwm(motor);
+ }
+protected:
+ EDMotor(EtherDrive* driver, uint32_t motor) : driver(driver), motor(motor) {}
+
+private:
+ EtherDrive* driver;
+
+ uint32_t motor;
+};
+
+
#endif
Modified: pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp
===================================================================
--- pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp 2008-04-25 00:56:12 UTC (rev 177)
+++ pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp 2008-04-25 19:43:55 UTC (rev 178)
@@ -48,6 +48,11 @@
}
+EtherDrive::~EtherDrive()
+{
+ shutdown();
+}
+
bool EtherDrive::init(string ip) {
if (ready) {
@@ -94,12 +99,6 @@
}
-EtherDrive::~EtherDrive()
-{
- shutdown();
-}
-
-
void EtherDrive::shutdown() {
if (ready = true) {
@@ -112,6 +111,26 @@
}
+int EtherDrive::send_cmd(char* cmd, size_t cmd_len, char* buf, size_t buf_len) {
+
+ int n_sent;
+ int n_recv;
+
+ struct sockaddr_in from;
+ socklen_t fromlen = sizeof(struct sockaddr_in);
+
+ n_sent = sendto(cmd_sock, cmd, cmd_len, 0, (struct sockaddr *)&cmd_addr_out, sizeof(mot_addr_out));
+
+ if (n_sent != cmd_len) {
+ return -1;
+ }
+
+ n_recv = recvfrom(cmd_sock, buf, buf_len, 0, (struct sockaddr *)&from, &fromlen);
+
+ return n_recv;
+
+}
+
bool EtherDrive::motors_on() {
if (ready) {
@@ -159,45 +178,36 @@
}
-int EtherDrive::send_cmd(char* cmd, size_t cmd_len, char* buf, size_t buf_len) {
+EDMotor EtherDrive::get_motor(uint32_t m) {
+ return EDMotor(this, m);
+}
- int n_sent;
- int n_recv;
-
- struct sockaddr_in from;
- socklen_t fromlen = sizeof(struct sockaddr_in);
-
- n_sent = sendto(cmd_sock, cmd, cmd_len, 0, (struct sockaddr *)&cmd_addr_out, sizeof(mot_addr_out));
-
- if (n_sent != cmd_len) {
- return -1;
+void EtherDrive::set_drv(uint32_t m, int32_t drv) {
+ if (m < 6) {
+ last_drv[m] = drv;
}
-
- n_recv = recvfrom(cmd_sock, buf, buf_len, 0, (struct sockaddr *)&from, &fromlen);
-
- return n_recv;
-
}
-
-bool EtherDrive::drive(size_t num, int32_t* drv)
-{
- if (num > 6) {
- return false;
+int32_t EtherDrive::get_enc(uint32_t m) {
+ if (m < 6) {
+ return last_enc[m];
}
+}
- for (int i = 0; i < num; i++) {
- last_drv[i] = drv[i];
+int32_t EtherDrive::get_cur(uint32_t m) {
+ if (m < 6) {
+ return last_enc[m];
}
+}
- for (int i = num; i < 6; i++) {
- last_drv[i] = 0;
+int32_t EtherDrive::get_pwm(uint32_t m) {
+ if (m < 6) {
+ return last_pwm[m];
}
-
- return true;
}
-bool EtherDrive::tick(size_t num, int32_t* enc, int32_t* curr, int32_t* pwm)
+
+bool EtherDrive::tick(size_t num, int32_t* enc, int32_t* cur, int32_t* pwm)
{
if (num > 6) {
@@ -224,23 +234,47 @@
return false;
}
+
+ for (int i = 0; i < 6; i++) {
+ last_enc[i] = buf[i];
+ }
+ for (int i = 0; i < 6; i++) {
+ last_cur[i] = buf[6+i];
+ }
+ for (int i = 0; i < 6; i++) {
+ last_pwm[i] = buf[6+i];
+ }
+
+
if (enc > 0) {
for (int i = 0; i < num; i++) {
- enc[i] = buf[i];
+ enc[i] = last_enc[i];
}
}
-
- if (curr > 0) {
+ if (cur > 0) {
for (int i = 0; i < num; i++) {
- curr[i] = buf[6+i];
+ cur[i] = last_cur[i];
}
}
-
if (pwm > 0) {
for (int i = 0; i < num; i++) {
- pwm[i] = buf[12+i];
+ pwm[i] = last_pwm[i];
}
}
return n_recv;
}
+
+bool EtherDrive::drive(size_t num, int32_t* drv)
+{
+ if (num > 6) {
+ return false;
+ }
+
+ for (int i = 0; i < num; i++) {
+ last_drv[i] = drv[i];
+ }
+
+ return true;
+}
+
Modified: pkg/trunk/etherdrive/test/test_etherdrive/test_etherdrive.cpp
===================================================================
--- pkg/trunk/etherdrive/test/test_etherdrive/test_etherdrive.cpp 2008-04-25 00:56:12 UTC (rev 177)
+++ pkg/trunk/etherdrive/test/test_etherdrive/test_etherdrive.cpp 2008-04-25 19:43:55 UTC (rev 178)
@@ -57,7 +57,7 @@
if (!e.drive(1,&drv))
printf("Drive problem!.");
if (!e.tick(2,enc,cur))
-// // // printf("Tick problem!.");
+ printf("Tick problem!.");
printf("Encoder0: %d Current: %d\n", enc[0], cur[0]);
printf("Encoder1: %d Current: %d\n", enc[1], cur[1]);
Added: pkg/trunk/etherdrive/test/test_etherdrive2/Makefile
===================================================================
--- pkg/trunk/etherdrive/test/test_etherdrive2/Makefile (rev 0)
+++ pkg/trunk/etherdrive/test/test_etherdrive2/Makefile 2008-04-25 19:43:55 UTC (rev 178)
@@ -0,0 +1,4 @@
+SRC = test_etherdrive2.cpp
+OUT = test_etherdrive2
+PKG = etherdrive
+include $(shell $(ROS_ROOT)/rospack find roscpp)/make_include/node.mk
Added: pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp
===================================================================
--- pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp (rev 0)
+++ pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp 2008-04-25 19:43:55 UTC (rev 178)
@@ -0,0 +1,85 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, Willow Garage, Inc.
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of the Willow Garage nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*********************************************************************/
+
+#include "etherdrive/etherdrive.h"
+#include <iostream>
+
+using namespace std;
+
+int main() {
+
+ EtherDrive e;
+
+ if (!e.init("10.0.0.151")) {
+ cout << "Could not initialize etherdrive." << endl;
+ return -1;
+ }
+
+ EDMotor m0 = e.get_motor(0);
+ EDMotor m1 = e.get_motor(1);
+
+ e.motors_on();
+
+ int count = 0;
+
+ int drv = 100000;
+
+ while (1) {
+
+ m0.set_drv(drv);
+
+ if (!e.tick())
+ printf("Tick problem!.");
+
+ printf("Encoder0: %d Current: %d\n", m0.get_enc(), m0.get_cur());
+ printf("Encoder1: %d Current: %d\n", m1.get_enc(), m1.get_cur());
+
+
+ // Crappy control
+ if (abs(m0.get_cur()) > 200) {
+ if (count++ > 50)
+ e.motors_off();
+ } else {
+ count = 0;
+ }
+
+ if (m0.get_enc() == 100000) {
+ drv = -100000;
+ } else if (m0.get_enc() == -100000) {
+ drv = 100000;
+ }
+ }
+
+ e.shutdown();
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jl...@us...> - 2008-04-25 20:33:01
|
Revision: 179
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=179&view=rev
Author: jleibs
Date: 2008-04-25 13:33:04 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
Fixing some small bugs in etherdrive driver.
Modified Paths:
--------------
pkg/trunk/etherdrive/build.yaml
pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp
pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp
Modified: pkg/trunk/etherdrive/build.yaml
===================================================================
--- pkg/trunk/etherdrive/build.yaml 2008-04-25 19:43:55 UTC (rev 178)
+++ pkg/trunk/etherdrive/build.yaml 2008-04-25 20:33:04 UTC (rev 179)
@@ -3,4 +3,5 @@
- src/libetherdrive
- src/etherdrive_control
- test/test_etherdrive
+ - test/test_etherdrive2
Modified: pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp
===================================================================
--- pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp 2008-04-25 19:43:55 UTC (rev 178)
+++ pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp 2008-04-25 20:33:04 UTC (rev 179)
@@ -196,7 +196,7 @@
int32_t EtherDrive::get_cur(uint32_t m) {
if (m < 6) {
- return last_enc[m];
+ return last_cur[m];
}
}
@@ -242,7 +242,7 @@
last_cur[i] = buf[6+i];
}
for (int i = 0; i < 6; i++) {
- last_pwm[i] = buf[6+i];
+ last_pwm[i] = buf[12+i];
}
Modified: pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp
===================================================================
--- pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp 2008-04-25 19:43:55 UTC (rev 178)
+++ pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp 2008-04-25 20:33:04 UTC (rev 179)
@@ -62,8 +62,8 @@
if (!e.tick())
printf("Tick problem!.");
- printf("Encoder0: %d Current: %d\n", m0.get_enc(), m0.get_cur());
- printf("Encoder1: %d Current: %d\n", m1.get_enc(), m1.get_cur());
+ printf("Encoder0: %d Current: %d PWM: %d\n", m0.get_enc(), m0.get_cur(), m0.get_pwm());
+ printf("Encoder1: %d Current: %d PWM: %d\n", m1.get_enc(), m1.get_cur(), m1.get_pwm());
// Crappy control
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jl...@us...> - 2008-04-28 22:08:12
|
Revision: 214
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=214&view=rev
Author: jleibs
Date: 2008-04-28 15:08:16 -0700 (Mon, 28 Apr 2008)
Log Message:
-----------
Code to change the control mode and gains from software (removes need for ever using serial other than to
debug).
Modified Paths:
--------------
pkg/trunk/etherdrive/include/etherdrive/etherdrive.h
pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp
pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp
Modified: pkg/trunk/etherdrive/include/etherdrive/etherdrive.h
===================================================================
--- pkg/trunk/etherdrive/include/etherdrive/etherdrive.h 2008-04-28 21:32:32 UTC (rev 213)
+++ pkg/trunk/etherdrive/include/etherdrive/etherdrive.h 2008-04-28 22:08:16 UTC (rev 214)
@@ -65,6 +65,10 @@
// Disable motors
bool motors_off();
+ bool set_control_mode(int8_t m);
+
+ bool set_gain(uint32_t m, char G, int32_t val);
+
EDMotor get_motor(uint32_t m);
void set_drv(uint32_t m, int32_t drv);
@@ -114,6 +118,15 @@
int32_t get_pwm() {
return driver->get_pwm(motor);
}
+
+ bool set_gains(int32_t P, int32_t I, int32_t D, int32_t W, int32_t M, int32_t Z) {
+ return driver->set_gain(motor, 'P', P) &
+ driver->set_gain(motor, 'I', I) &
+ driver->set_gain(motor, 'D', D) &
+ driver->set_gain(motor, 'W', W) &
+ driver->set_gain(motor, 'M', M) &
+ driver->set_gain(motor, 'Z', Z);
+ }
protected:
EDMotor(EtherDrive* driver, uint32_t motor) : driver(driver), motor(motor) {}
Modified: pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp
===================================================================
--- pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp 2008-04-28 21:32:32 UTC (rev 213)
+++ pkg/trunk/etherdrive/src/libetherdrive/etherdrive.cpp 2008-04-28 22:08:16 UTC (rev 214)
@@ -107,12 +107,14 @@
}
ready = false;
-
}
int EtherDrive::send_cmd(char* cmd, size_t cmd_len, char* buf, size_t buf_len) {
+ if (!ready)
+ return -1;
+
int n_sent;
int n_recv;
@@ -128,7 +130,6 @@
n_recv = recvfrom(cmd_sock, buf, buf_len, 0, (struct sockaddr *)&from, &fromlen);
return n_recv;
-
}
bool EtherDrive::motors_on() {
@@ -138,11 +139,11 @@
cmd[0] = 'm';
cmd[1] = 1;
cmd[2] = 0;
-
+
int32_t res[3];
-
+
int res_len = send_cmd((char*)cmd, 3*sizeof(int32_t), (char*)res, 100*sizeof(int32_t));
-
+
if (res_len == 3) {
if (res[1] == 1) {
return true;
@@ -151,7 +152,6 @@
}
return false;
-
}
bool EtherDrive::motors_off() {
@@ -177,7 +177,61 @@
}
+bool EtherDrive::set_control_mode(int8_t m) {
+ if (ready) {
+
+ if (m == 0 || m == 1 || m == 2) {
+
+ int32_t cmd[3];
+ cmd[0] = 'i';
+ cmd[1] = m;
+ cmd[2] = 0;
+
+ int32_t res[3];
+
+ int res_len = send_cmd((char*)cmd, 3*sizeof(int32_t), (char*)res, 100*sizeof(int32_t));
+
+ if (res_len == 3) {
+ if (res[1] == m) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+}
+
+
+bool EtherDrive::set_gain(uint32_t m, char G, int32_t val) {
+ if (ready) {
+
+ if (m < 6) {
+
+ char cmds[] = "PIDWMZ";
+ if ( memchr(cmds, G, strlen(cmds)) != NULL) {
+
+ int32_t cmd[3];
+ cmd[0] = G;
+ cmd[1] = m;
+ cmd[2] = val;
+
+ int32_t res[3];
+
+ int res_len = send_cmd((char*)cmd, 3*sizeof(int32_t), (char*)res, 100*sizeof(int32_t));
+
+ if (res_len == 3) {
+ if (res[1] == m && res[2] == val) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+}
+
+
EDMotor EtherDrive::get_motor(uint32_t m) {
return EDMotor(this, m);
}
@@ -210,6 +264,9 @@
bool EtherDrive::tick(size_t num, int32_t* enc, int32_t* cur, int32_t* pwm)
{
+ if (!ready)
+ return false;
+
if (num > 6) {
return false;
}
Modified: pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp
===================================================================
--- pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp 2008-04-28 21:32:32 UTC (rev 213)
+++ pkg/trunk/etherdrive/test/test_etherdrive2/test_etherdrive2.cpp 2008-04-28 22:08:16 UTC (rev 214)
@@ -55,6 +55,13 @@
int drv = 100000;
+ e.set_control_mode(2);
+
+ if (!m1.set_gains(150, 20, -10, 50, 200, 13)) {
+ printf("Setting gains failed!\n");
+ return 0;
+ }
+
while (1) {
m0.set_drv(drv);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|