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>
|
||||
<description brief="ros_arduino_firmware">
|
||||
|
||||
ros_arduino_firmware
|
||||
ROS Arduino Firmware
|
||||
|
||||
</description>
|
||||
<author>Patrick Goebel</author>
|
||||
|
@ -208,8 +208,6 @@ int runCommand() {
|
||||
#ifdef USE_SERVOS
|
||||
case SERVO_WRITE:
|
||||
servos[arg1].write(arg2);
|
||||
Serial.print(arg1);
|
||||
Serial.print(arg2);
|
||||
Serial.println("OK");
|
||||
break;
|
||||
case SERVO_READ:
|
||||
|
@ -1,11 +1,11 @@
|
||||
/* 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
|
||||
|
||||
Servo servos [N_SERVOS];
|
||||
byte servoPins [N_SERVOS] = {3, 6};
|
||||
byte servoPins [N_SERVOS] = {3, 5};
|
||||
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<package>
|
||||
<description brief="ros_arduino_msgs">
|
||||
|
||||
ros_arduino_msgs
|
||||
ROS Arduino Messages
|
||||
|
||||
</description>
|
||||
<author>Patrick Goebel</author>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<package>
|
||||
<description brief="ros_arduino_python">
|
||||
|
||||
ros_arduino_python
|
||||
ROS Arduino Python
|
||||
|
||||
</description>
|
||||
<author>Patrick Goebel</author>
|
||||
|
@ -22,13 +22,16 @@
|
||||
"""
|
||||
|
||||
import thread
|
||||
from math import pi as PI
|
||||
from math import pi as PI, degrees, radians
|
||||
import os
|
||||
import time
|
||||
import sys
|
||||
from serial.serialutil import SerialException
|
||||
from serial import Serial
|
||||
|
||||
SERVO_MAX = 180
|
||||
SERVO_MIN = 0
|
||||
|
||||
class Arduino:
|
||||
''' Configuration Parameters
|
||||
'''
|
||||
@ -309,13 +312,15 @@ class Arduino:
|
||||
|
||||
def servo_write(self, 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):
|
||||
''' 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):
|
||||
''' The srf05/Ping command queries an SRF05/Ping sonar sensor
|
||||
|
Binary file not shown.
@ -72,7 +72,7 @@ class Sensor(object):
|
||||
else:
|
||||
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.pub.publish(self.msg)
|
||||
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user