コード例 #1
0
ファイル: test_Servo.py プロジェクト: TurtlebotMec3/Turtlebot
def main():
	global bumper
	print("Lancement test servo")
	rospy.init_node('test_servo')
	rospy.sleep(0.5)
	pub = rospy.Publisher("/mobile_base/commands/digital_output", DigitalOutput)
	cmd=DigitalOutput()
	cmd.values= [True, True, True, True]
	cmd.mask=[True, False, False, False]
	while not rospy.is_shutdown():
		print(cmd)
		pub.publish(cmd)
		cmd.values=[False, False, False, False]
		rospy.sleep(5)
		print(cmd)
		pub.publish(cmd)
		rospy.sleep(5)
		cmd.values= [True, True, True, True]
	print("je suis desole, je n'ai pas de servo")
	rospy.spin() #boucle infinie tant qu'on quitte pas proprement
コード例 #2
0
def change_mode(request):
	pub = rospy.Publisher('mobile_base/commands/digital_output', DigitalOutput, queue_size = 1)
	
	output = DigitalOutput()
	output.mask = [False, True, True, True]
	
	if (request.mode == request.OFF):
		output.values[1] = False
		output.values[2] = False
		output.values[3] = False
	elif (request.mode == request.BLINK_SLOW):
		output.values[1] = False
		output.values[2] = True
		output.values[3] = False
	elif (request.mode == request.BLINK_FAST):
		output.values[1] = True
		output.values[2] = False
		output.values[3] = False
	elif (request.mode == request.ALIVE):
		output.values[1] = True
		output.values[2] = True
		output.values[3] = False
        elif (request.mode == request.R_ON):
                output.values[1] = False
                output.values[2] = False
                output.values[3] = True
        elif (request.mode == request.R_SLOW):
                output.values[1] = False
                output.values[2] = True
                output.values[3] = True
        elif (request.mode == request.R_FAST):
                output.values[1] = True
                output.values[2] = False
                output.values[3] = True
        elif (request.mode == request.ROSE):
                output.values[1] = True
                output.values[2] = True
                output.values[3] = True


	pub.publish(output)
コード例 #3
0
def callback(data):
	# topic 
	pub = rospy.Publisher('camera/orientation/value', Orientation, queue_size = 1, latch=True)
	command = rospy.Publisher('mobile_base/commands/digital_output', DigitalOutput, queue_size = 1, latch=True)
		
	# variable to publish
	digout = DigitalOutput()
	digout.mask = [True, False, False, False]
		
	angle = Orientation()

	if data.value == False:
		digout.values[0]=False
		angle.value = angle.low

	else:
		digout.values[0]=True
		angle.value = angle.up

	pub.publish(angle)
	command.publish(digout)
コード例 #4
0
def main():
    global bumper
    print("Lancement test servo")
    rospy.init_node('test_servo')
    rospy.sleep(0.5)
    pub = rospy.Publisher("/mobile_base/commands/digital_output",
                          DigitalOutput)
    cmd = DigitalOutput()
    cmd.values = [True, True, True, True]
    cmd.mask = [True, False, False, False]
    while not rospy.is_shutdown():
        print(cmd)
        pub.publish(cmd)
        cmd.values = [False, False, False, False]
        rospy.sleep(5)
        print(cmd)
        pub.publish(cmd)
        rospy.sleep(5)
        cmd.values = [True, True, True, True]
    print("je suis desole, je n'ai pas de servo")
    rospy.spin()  #boucle infinie tant qu'on quitte pas proprement
コード例 #5
0
def main():
    global bumper

    print("Lancement navigation aleatoire")
    rospy.init_node('navigation_aleatoire')
    rospy.sleep(0.5)
    rospy.Subscriber("/mobile_base/events/bumper", BumperEvent, bumper)
    rospy.Subscriber("/facedetector/faces", Detection, image)
    pub = rospy.Publisher("/mobile_base/commands/velocity", Twist)
    #	pub2 = rospy.Publisher("/robotsound", SoundRequest)
    pub3 = rospy.Publisher("/mobile_base/commands/sound", Sound)
    pub4 = rospy.Publisher("/mobile_base/commands/digital_output",
                           DigitalOutput)
    cmd = Twist()
    #	sound = SoundRequest()
    sonnerie = Sound()
    #	sound.arg = "/opt/ros/indigo/share/sound_play/sounds/R2D2a.wav"
    #	sound.sound = -2
    #	sound.command = 1
    sonnerie.value = 6
    digOut = DigitalOutput()
    digOut.values = [False, False, False, False]
    digOut.mask = [True, False, False, False]
    flag = 0

    rospy.sleep(1)
    indiana_jones.main()

    while not rospy.is_shutdown():

        duree = 1 + random.random() * 5
        tempsActuel = rospy.get_time()
        stop = rospy.get_time() + duree
        while (rospy.get_time() < stop):
            if bumper == 0:
                cmd.linear.x = 0
                cmd.angular.z = -2
                pub.publish(cmd)
                rospy.sleep(0.5)
                bumper = 3
            elif bumper == 1:
                cmd.linear.x = -0.2
                cmd.angular.z = 0
                digOut.values[0] = True
                pub.publish(cmd)
                vador2.main()
                #				pub2.publish(sound)
                pub4.publish(digOut)
                rospy.sleep(5)
                while (NbGens > 0):
                    rospy.sleep(2.5)
                    flag = 1
                digOut.values[0] = False
                if flag == 1:
                    pub3.publish(sonnerie)
                    rospy.sleep(0.5)
                    flag = 0
                pub4.publish(digOut)
                rospy.sleep(0.5)
                cmd.linear.x = -0.2
                cmd.angular.z = 2
                pub.publish(cmd)
                rospy.sleep(0.5)
                bumper = 3
            elif bumper == 2:
                cmd.linear.x = 0
                cmd.angular.z = 2
                pub.publish(cmd)
                rospy.sleep(0.5)
                bumper = 3
            else:
                cmd.linear.x = 0.2
                cmd.angular.z = 0
                pub.publish(cmd)
        if bumper > 2:
            bumper = math.floor(random.random() * 10)
            if bumper == 1:
                bumper = 3
    print("fin navigation autonome")
    rospy.spin()  #boucle infinie tant qu'on quitte pas proprement
コード例 #6
0
ファイル: test_output.py プロジェクト: fqez/kobuki_test
# rospy initial setup
rospy.init_node("test_output")
rospy.on_shutdown(clearing)
rate = rospy.Rate(10)

pub_ext_pwr = rospy.Publisher("/mobile_base/commands/external_power", DigitalOutput)
pub_dgt_out = rospy.Publisher("/mobile_base/commands/digital_output", DigitalOutput)
pub = []
pub.append(rospy.Publisher("/mobile_base/commands/led1", Led))
pub.append(rospy.Publisher("/mobile_base/commands/led2", Led))
pub_sounds = rospy.Publisher("/mobile_base/commands/sound", Sound)

# initial values
external_power = DigitalOutput()
external_power.values = [True, True, True, True]
external_power.mask = [True, True, True, True]

digital_output = DigitalOutput()
digital_output.values = [True, True, True, True]
digital_output.mask = [True, True, True, True]

leds = []
leds.append(Led())
leds.append(Led())
leds[0].value = Led.GREEN
leds[1].value = Led.GREEN

# initialize outputs
while not pub_ext_pwr.get_num_connections():
    rate.sleep()
pub_ext_pwr.publish(external_power)
コード例 #7
0
settings = termios.tcgetattr(sys.stdin)


def clearing():
    sys.stdout.write('\r\n')
    sys.stdout.flush()
    termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)


rospy.init_node("test_external_power")
rospy.on_shutdown(clearing)
pub = rospy.Publisher('/mobile_base/commands/external_power', DigitalOutput)
rate = rospy.Rate(10)
digital_output = DigitalOutput()
digital_output.values = [True, True, True, True]
digital_output.mask = [True, True, True, True]
print ""
#print "If you want to control the timing of publish, uses -p option."
#print ""
print "Control External Power"
print "----------------------"
print "1: Toggle the state of 3.3V"
print "2: Toggle the state of 5V"
print "3: Toggle the state of 12V5A(arm)"
print "4: Toggle the state of 12V1A(kinect)"
print ""
#print "p: publish power on/off status"
print "q: quit"
print ""
print "  3.3V  5.0V 12V5A 12V1A"
#print " [ On] [Off] [ On] [Off]"
コード例 #8
0
}

settings = termios.tcgetattr(sys.stdin)

def clearing():
    sys.stdout.write('\r\n')
    sys.stdout.flush()
    termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)

rospy.init_node("test_external_power")
rospy.on_shutdown(clearing)
pub = rospy.Publisher('/mobile_base/commands/external_power',DigitalOutput)
rate = rospy.Rate(10)
digital_output = DigitalOutput()
digital_output.values = [ True, True, True, True ]
digital_output.mask = [ True, True, True, True ]
print ""
#print "If you want to control the timing of publish, uses -p option."
#print ""
print "Control External Power"
print "----------------------"
print "1: Toggle the state of 3.3V"
print "2: Toggle the state of 5V"
print "3: Toggle the state of 12V5A(arm)"
print "4: Toggle the state of 12V1A(kinect)"
print ""
#print "p: publish power on/off status"
print "q: quit"
print ""
print "  3.3V  5.0V 12V5A 12V1A"
#print " [ On] [Off] [ On] [Off]"
コード例 #9
0
rospy.on_shutdown(clearing)
rate = rospy.Rate(10)

pub_ext_pwr = rospy.Publisher('/mobile_base/commands/external_power',
                              DigitalOutput)
pub_dgt_out = rospy.Publisher('/mobile_base/commands/digital_output',
                              DigitalOutput)
pub = []
pub.append(rospy.Publisher('/mobile_base/commands/led1', Led))
pub.append(rospy.Publisher('/mobile_base/commands/led2', Led))
pub_sounds = rospy.Publisher('/mobile_base/commands/sound', Sound)

# initial values
external_power = DigitalOutput()
external_power.values = [True, True, True, True]
external_power.mask = [True, True, True, True]

digital_output = DigitalOutput()
digital_output.values = [True, True, True, True]
digital_output.mask = [True, True, True, True]

leds = []
leds.append(Led())
leds.append(Led())
leds[0].value = Led.GREEN
leds[1].value = Led.GREEN

# initialize outputs
while not pub_ext_pwr.get_num_connections():
    rate.sleep()
pub_ext_pwr.publish(external_power)
コード例 #10
0
def main():
	global bumper

	print("Lancement navigation aleatoire")
	rospy.init_node('navigation_aleatoire')
	rospy.sleep(0.5)
	rospy.Subscriber("/mobile_base/events/bumper", BumperEvent, bumper)
#	rospy.Subscriber("/facedetector/faces",Detection , face)
#	rospy.Subscriber("/camera/depth/image_rect",Image, image)
	pub = rospy.Publisher("/mobile_base/commands/velocity", Twist)
#	pub2 = rospy.Publisher("/robotsound", SoundRequest)
	pub3 = rospy.Publisher("/mobile_base/commands/sound", Sound)
	pub4 = rospy.Publisher("/mobile_base/commands/digital_output", DigitalOutput)
	
	ic=image_converter()

	cmd = Twist()
#	sound = SoundRequest()
	sonnerie = Sound()
#	sound.arg = "/opt/ros/indigo/share/sound_play/sounds/R2D2a.wav"
#	sound.sound = -2
#	sound.command = 1
	sonnerie.value= 6
	digOut=DigitalOutput()
	digOut.values= [False, False, False, False]
	digOut.mask=[True, False, False, False]
	flag=0


	while not rospy.is_shutdown():

		duree= 1+random.random()*5
		tempsActuel = rospy.get_time()
		stop = rospy.get_time() + duree
		while (rospy.get_time() < stop):
			if bumper==0 or bumper1 ==0 :
				cmd.linear.x = 0
				cmd.angular.z = -2
				pub.publish(cmd)
				rospy.sleep(0.5)
				bumper=3
			elif bumper==1 or bumper1==1:
				cmd.linear.x = -0.2
				cmd.angular.z = 0
				digOut.values[0]=True
				pub.publish(cmd)
#				pub2.publish(sound)
				pub4.publish(digOut)
				rospy.sleep(5)
				while (NbGens>0):
					rospy.sleep(2.5)
					flag=1
				digOut.values[0]=False
				if flag==1:
					pub3.publish(sonnerie)
					rospy.sleep(0.5)
					flag=0
				pub4.publish(digOut)
				rospy.sleep(0.5)
				cmd.linear.x = -0.2
				cmd.angular.z = 2
				pub.publish(cmd)
				rospy.sleep(0.5)
				bumper=3
			elif bumper==2 or bumper1==2:
				cmd.linear.x = 0
				cmd.angular.z = 2
				pub.publish(cmd)
				rospy.sleep(0.5)
				bumper=3
			else:
				cmd.linear.x = 0.2
				cmd.angular.z = 0
				pub.publish(cmd)
				rospy.sleep(0.5)
#		if bumper>2:
#			bumper = math.floor(random.random()*10)
#			if bumper == 1:
#				bumper=3
	print("fin navigation autonome")
	rospy.spin() #boucle infinie tant qu'on quitte pas proprement