mirror of
https://github.com/YikeStone/ros_arduino_bridge.git
synced 2025-08-03 19:24:09 +05:30
Servo positions are now specified in radians instead of degrees
This commit is contained in:
parent
eaf6b422ad
commit
177171332a
@ -1,7 +1,7 @@
|
|||||||
<package>
|
<package>
|
||||||
<description brief="ros_arduino_firmware">
|
<description brief="ros_arduino_firmware">
|
||||||
|
|
||||||
ros_arduino_firmware
|
ROS Arduino Firmware
|
||||||
|
|
||||||
</description>
|
</description>
|
||||||
<author>Patrick Goebel</author>
|
<author>Patrick Goebel</author>
|
||||||
|
@ -208,8 +208,6 @@ int runCommand() {
|
|||||||
#ifdef USE_SERVOS
|
#ifdef USE_SERVOS
|
||||||
case SERVO_WRITE:
|
case SERVO_WRITE:
|
||||||
servos[arg1].write(arg2);
|
servos[arg1].write(arg2);
|
||||||
Serial.print(arg1);
|
|
||||||
Serial.print(arg2);
|
|
||||||
Serial.println("OK");
|
Serial.println("OK");
|
||||||
break;
|
break;
|
||||||
case SERVO_READ:
|
case SERVO_READ:
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/* Define the attachment of any servos here.
|
/* Define the attachment of any servos here.
|
||||||
The example shows two servos attached on pins 3 and 6.
|
The example shows two servos attached on pins 3 and 5.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define N_SERVOS 2
|
#define N_SERVOS 2
|
||||||
|
|
||||||
Servo servos [N_SERVOS];
|
Servo servos [N_SERVOS];
|
||||||
byte servoPins [N_SERVOS] = {3, 6};
|
byte servoPins [N_SERVOS] = {3, 5};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<package>
|
<package>
|
||||||
<description brief="ros_arduino_msgs">
|
<description brief="ros_arduino_msgs">
|
||||||
|
|
||||||
ros_arduino_msgs
|
ROS Arduino Messages
|
||||||
|
|
||||||
</description>
|
</description>
|
||||||
<author>Patrick Goebel</author>
|
<author>Patrick Goebel</author>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<package>
|
<package>
|
||||||
<description brief="ros_arduino_python">
|
<description brief="ros_arduino_python">
|
||||||
|
|
||||||
ros_arduino_python
|
ROS Arduino Python
|
||||||
|
|
||||||
</description>
|
</description>
|
||||||
<author>Patrick Goebel</author>
|
<author>Patrick Goebel</author>
|
||||||
|
@ -22,14 +22,17 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import thread
|
import thread
|
||||||
from math import pi as PI
|
from math import pi as PI, degrees, radians
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
from serial.serialutil import SerialException
|
from serial.serialutil import SerialException
|
||||||
from serial import Serial
|
from serial import Serial
|
||||||
|
|
||||||
class Arduino:
|
SERVO_MAX = 180
|
||||||
|
SERVO_MIN = 0
|
||||||
|
|
||||||
|
class Arduino:
|
||||||
''' Configuration Parameters
|
''' Configuration Parameters
|
||||||
'''
|
'''
|
||||||
N_ANALOG_PORTS = 6
|
N_ANALOG_PORTS = 6
|
||||||
@ -309,13 +312,15 @@ class Arduino:
|
|||||||
|
|
||||||
def servo_write(self, id, pos):
|
def servo_write(self, id, pos):
|
||||||
''' Usage: servo_write(id, pos)
|
''' Usage: servo_write(id, pos)
|
||||||
|
Position is given in radians and converted to degrees before sending
|
||||||
'''
|
'''
|
||||||
return self.execute_ack('s %d %d' %(id, pos))
|
return self.execute_ack('s %d %d' %(id, min(SERVO_MAX, max(SERVO_MIN, degrees(pos)))))
|
||||||
|
|
||||||
def servo_read(self, id):
|
def servo_read(self, id):
|
||||||
''' Usage: servo_read(id)
|
''' Usage: servo_read(id)
|
||||||
|
The returned position is converted from degrees to radians
|
||||||
'''
|
'''
|
||||||
return self.execute('t %d' %id)
|
return radians(self.execute('t %d' %id))
|
||||||
|
|
||||||
def ping(self, pin):
|
def ping(self, pin):
|
||||||
''' The srf05/Ping command queries an SRF05/Ping sonar sensor
|
''' The srf05/Ping command queries an SRF05/Ping sonar sensor
|
||||||
|
Binary file not shown.
@ -72,7 +72,7 @@ class Sensor(object):
|
|||||||
else:
|
else:
|
||||||
self.msg.value = self.value
|
self.msg.value = self.value
|
||||||
|
|
||||||
# At a timestamp and publish the message
|
# Add a timestamp and publish the message
|
||||||
self.msg.header.stamp = rospy.Time.now()
|
self.msg.header.stamp = rospy.Time.now()
|
||||||
self.pub.publish(self.msg)
|
self.pub.publish(self.msg)
|
||||||
|
|
||||||
|
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
<stack>
|
<stack>
|
||||||
<description brief="ros_arduino_bridge">ros_arduino_bridge</description>
|
<description brief="ros_arduino_bridge">ROS Arduino Bridge</description>
|
||||||
<author>Maintained by Patrick Goebel</author>
|
<author>Maintained by Patrick Goebel</author>
|
||||||
<license>BSD</license>
|
<license>BSD</license>
|
||||||
<review status="unreviewed" notes=""/>
|
<review status="unreviewed" notes=""/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user