We want to control a P3DX robot using values obtained from a potentiometer connected to a GPIO pin on the Raspberry pi 2. Currently we have two Python files: one that moves the robot, and one that reads the GPIO pin connected to a potentiometer. Both files are already working on their own. But is it possible to combine the two files into just one file and run it? Because I was thinking that the Python file interfacing with ROS would need to run separately. If not, what's the easiest way to implement what we want to do?
***Update: Essentially we are trying to use a catenary method to move two robots in formation. So we want to measure the angle the potentiometer makes with a rope, in which the other end is attached to another robot. Based on the angle, it gives the orientation of the robot, and then we can make the proper adjustments to realign the robot to the centerline so that the robot follows the first robot in front.
We followed this link on how to connect potentiometer to Raspberry Pi 2 and read values. It also includes the script file: https://learn.adafruit.com/downloads/pdf/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi.pdf
Here's the file for moving the P3DX:`
#!/usr/bin/env python
import getch
import roslib; roslib.load_manifest('p3dx_mover')
import rospy
from geometry_msgs.msg import Twist
KEY_UP = 65
KEY_DOWN = 66
KEY_RIGHT = 67
KEY_LEFT = 68
USER_QUIT = 100
MAX_FORWARD = 1.1
MAX_LEFT = 0.3
MIN_FORWARD = -1.1
MIN_LEFT = -0.3
forward = 0.0
left = 0.0
keyPress = 0
while(keyPress != USER_QUIT):
pub = rospy.Publisher('RosAria/cmd_vel', Twist)
rospy.init_node('p3dx_mover')
twist = Twist()
keyPress = getch.getArrow()
if((keyPress == KEY_UP) and (forward <= MAX_FORWARD)):
forward += 0.1
elif((keyPress == KEY_DOWN) and (forward >= MIN_FORWARD)):
forward -= 0.1
elif((keyPress == KEY_LEFT) and (left <= MAX_LEFT)):
left += 0.1
elif((keyPress == KEY_RIGHT) and (left >= MIN_LEFT)):
left -= 0.1
twist.linear.x = forward
twist.angular.z = left
pub.publish(twist)
pub = rospy.Publisher('RosAria/cmd_vel', Twist)
rospy.init_node('p3dx_mover')
twist = Twist()
pub.publish(twist)
exit()
` Here's the link we used for reading the potentiometer voltage level values: https://gist.github.com/ladyada/3151375 Ignore the volume stuff, we didn't include them. Just reading the pot.