0% found this document useful (0 votes)
216 views2 pages

Coderz

The document contains code to control a robot using Python. It sets the robot's motor powers, uses time delays to pause execution, and includes a for loop to repeat a driving process multiple times. It also includes a while loop to drive the robot forward a desired distance before braking.

Uploaded by

ffelixx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
216 views2 pages

Coderz

The document contains code to control a robot using Python. It sets the robot's motor powers, uses time delays to pause execution, and includes a for loop to repeat a driving process multiple times. It also includes a while loop to drive the robot forward a desired distance before braking.

Uploaded by

ffelixx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

print "I Love Ruby"

print "In 5 seconds I will say Hello..."

# Halt the execution for 2 seconds:


time.sleep(2)

# And again for 1 second:


time.sleep(1)
print "3"

# And again:
time.sleep(1)
print "2"

# And one more time:


time.sleep(1)
print "1"

# If we got here, it means that 3 seconds has passed


print "...Hello world!"

----------------------------------------------
from robot import Robot
import time

robot = Robot({"communication":{"communication_manager_type":"js"}})

#start your code here:

robot.cs.set_power(0, 0)
----------------------------------------------------

robot.cs.set_power(100,100)

time.sleep(3)

robot.cs.brake("both")
------------------------------------------------------
robot.cs.set_power(-100,-100)
time.sleep(2)

robot.cs.brake("both")

robot.cs.set_power(100,100)
-------------------------------------------------------
ciclo for cuantas veces repetira el proceso
for t in range(5):
robot.cs.set_power(-100,-100)
time.sleep(2)
robot.cs.set_power(100,100)
time.sleep(6)
------------------------------------------------------------
while True:
time.sleep(0.01) # <---- DO NOT REMOVE

if robot.cs.get_speed() < 50:


# driving too slow, let's accelerate
robot.cs.set_power(100, 100)
else:
# driving too fast, let's brake
robot.cs.brake("both")
---------------------------------------------------------
robot.cs.set_speed(25, 25)
------------------------------------------------------
import time

robot = Robot({"communication":{"communication_manager_type":"js"}})

# The distance we want Ruby to drive:


desired_distance = 5 # <---- THIS IS THE ONLY PLACE YOU NEED TO EDIT

# Read GPS - this is Ruby’s starting location:


x_start, y_start, z_start = robot.gps.get_position()

# Initialize the current position. These values are going to change as Ruby's
driving:
x_now, y_now, z_now = x_start, y_start, z_start

# Start moving:
robot.cs.set_speed(80,80)

# Put execution in a loop until Ruby passed the desired distance:


while (z_now - z_start < desired_distance):
time.sleep(0.01) # <---- DO NOT REMOVE

# Sends Ruby’s current distance value to the console:


print (z_now)

# Read GPS again:


x_now, y_now, z_now = robot.gps.get_position()

# Stop moving:
robot.cs.brake("both")

You might also like