import motorLib as motor import rospy from std_msgs.msg import Int64 class LeftMotorControl(): def __init__(self, motor): self.motor = motor # Set up node rospy.init_node('left_motor_test') rospy.Subscriber('left_motor/cmd_vel', Int64, self.callback) rospy.loginfo('Ready') def control_main(self): rospy.spin() self.motor.stop() def callback(self, data): self.rpm = data.data self.duty = self.motor.setRPM(self.rpm) rospy.loginfo('RPM: ' + str(self.rpm)) rospy.loginfo('Duty: ' + str(self.duty)) if __name__ == '__main__': left_motor = motor.Motor(port=[16, 20, 21]) left_motor_control = LeftMotorControl(left_motor) left_motor_control.control_main()
import motorLib as motor import rospy from std_msgs.msg import Int64 class RightMotorControl(): def __init__(self, motor): self.motor = motor # Set up node rospy.init_node('right_motor_test') rospy.Subscriber('right_motor/cmd_vel', Int64, self.callback) rospy.loginfo('Ready') def control_main(self): rospy.spin() self.motor.stop() def callback(self, data): self.rpm = data.data self.duty = self.motor.setRPM(self.rpm) rospy.loginfo('RPM: ' + str(self.rpm)) rospy.loginfo('Duty: ' + str(self.duty)) if __name__ == '__main__': right_motor = motor.Motor(port=[13, 19, 26]) right_motor_control = RightMotorControl(right_motor) right_motor_control.control_main()
from Tkinter import * import motorLib right = motorLib.Motor() left = motorLib.Motor(12, 16, 18, 22) root = Tk() def key(event): letter = event.char if letter == 'w': print "up" left.fwd() right.fwd() elif letter == 'a': print "left" left.rev() right.fwd() elif letter == "d": print "right" left.fwd() right.rev() elif letter == "s": print "down" left.rev() right.rev() else: print "stop" left.stop() right.stop()
import motorLib m1 = motorLib.Motor() m2 = motorLib.Motor(12, 16, 18, 22) #EXPLODE!!!!!!!!!!! m1.fwd() m2.fwd(2) m1.stop() m2.stop() m1.rev() m2.rev(2) m1.stop() m2.stop()