Your First Program
To start coding, you first need to create a MARLIN Project. To create a new project:
- click New Project in the MARLIN Control Station.
- Choose the location to save the project in.
- Name your project.
- Select either Blank or Example project. The example project contains the code needed to use the Starter Robot.
Ensure that you have the Controller connected and the Robot Brain paired. Refer to the Extension Walkthrough.
Example Program
Section titled “Example Program”The example program contains the code needed to use the Starter Robot. It can be found in src/main.py. project.marlin stores the Controller Joystick calibration data.
import timefrom marlin import Robot, Thruster, Servo, IMU, RadioBeacon
# Brain port definitionsIMU_PORT = "S1"RADIOBEACON_PORT = "S6"LEFT = "M8"RIGHT = "M1"ARM = "M2"
robot = Robot()robot.configure( sensors={IMU_PORT: IMU, RADIOBEACON_PORT: RadioBeacon}, effectors={LEFT: Thruster, RIGHT: Thruster, ARM: Servo},)
def initialize(robot): time.sleep(0.5) print("Battery:", robot.battery_voltage, "V")
def autonomous(robot): while robot.running: pass
def driver(robot): while robot.running: # Drive forward with joystick ONE and THREE. left = robot.controller.joystick("ONE").value right = robot.controller.joystick("THREE").value
robot.thruster(LEFT).set_duty(left) robot.thruster(RIGHT).set_duty(right)
# Set Servo speed to 180 deg/s robot.servo(ARM).set_speed(180)
if robot.controller.button("LEFT_TRIGGER").is_down: robot.servo(ARM).angle(120) else: robot.servo(ARM).angle(0)
# print IMU readings imu_reading = robot.imu(IMU_PORT).read() if imu_reading.ok: print(imu_reading)
# print RadioBeacon readings radiobeacon_reading = robot.radiobeacon(RADIOBEACON_PORT).read() if radiobeacon_reading.ok: print(radiobeacon_reading)
robot.run( initialize=initialize, autonomous=autonomous, driver=driver,)Zero your servo
Section titled “Zero your servo”Before you attach the T-flipper, set the servo to its zero position so the flipper sits correctly. The T-flipper is what the example program moves with the left trigger.
- Turn on the robot and connect the Controller to your laptop. If the robot is not paired yet, pair it to the Controller first.
- Load the example program.
- In the MARLIN Control Station, select Driver. This sets the servo to 0. Please don’t press any buttons on the Controller while you do this.
- Fit your T-flipper onto the servo horn, and screw all 3 screws on the horn into the servo. Take care to tighten all 3. The T-flipper should point downwards.
- Press the trigger. The T-flipper should flip up to the upward position. If it does, you’re done.
Learn more about the MARLIN API.