Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Smehnov authored Feb 10, 2024
1 parent 365f4b4 commit 6f57490
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,41 @@
import time
from spot_controller import SpotController

ROBOT_IP = "192.168.50.3"#os.environ['ROBOT_IP']
SPOT_USERNAME = "admin"#os.environ['SPOT_USERNAME']
SPOT_PASSWORD = "2zqa8dgw7lor"#os.environ['SPOT_PASSWORD']
from pycreate2 import Create2
import time

def launch_irobot():
port = "/dev/ttyUSB0" # where is your serial port?
bot = Create2(port)

# Start the Create 2
bot.start()

# Put the Create2 into 'safe' mode so we can drive it
# This will still provide some protection
bot.safe()

# You are responsible for handling issues, no protection/safety in
# this mode ... becareful
bot.full()

# directly set the motor speeds ... move forward
bot.drive_direct(100, 100)
time.sleep(2)

# turn in place
bot.drive_direct(200,-200) # inputs for motors are +/- 500 max
time.sleep(2)

# Stop the bot
bot.drive_stop()

# query some sensors
sensors = bot.get_sensors() # returns all data
print(sensors.light_bumper_left)

# Close the connection
bot.close()


def main():
Expand All @@ -26,25 +58,8 @@ def main():

# Use wrapper in context manager to lease control, turn on E-Stop, power on the robot and stand up at start
# and to return lease + sit down at the end
with SpotController(username=SPOT_USERNAME, password=SPOT_PASSWORD, robot_ip=ROBOT_IP) as spot:

time.sleep(2)

# Move head to specified positions with intermediate time.sleep
spot.move_head_in_points(yaws=[0.2, 0],
pitches=[0.3, 0],
rolls=[0.4, 0],
sleep_after_point_reached=1)
time.sleep(3)

# Make Spot to move by goal_x meters forward and goal_y meters left
spot.move_to_goal(goal_x=0.5, goal_y=0)
time.sleep(3)

# Control Spot by velocity in m/s (or in rad/s for rotation)
spot.move_by_velocity_control(v_x=-0.3, v_y=0, v_rot=0, cmd_duration=2)
time.sleep(3)

launch_irobot()

if __name__ == '__main__':
main()

0 comments on commit 6f57490

Please sign in to comment.