You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run pip install -r requirements.txtOR run python setup.py
For update run python setup.py --update --upgrade
.anki code language
Syntax
{
"function": "def",
"#include utils": "import anki_sdk.utils as utils",
"#include cars": "import anki_sdk.cars as cars",
"#include controllers": "import anki_sdk.controllers as controllers",
"#include api": "import anki_sdk.api as api",
"new Car": "cars.CarClass",
"new Controller": "controllers.ControllerClass",
"#import": "import",
"#": "@",
"//": "#",
"log": "print",
".end": "exit()"
}
Default Example
importanki_sdkassdkimporttimedefcontroll_car(address: str):
# Create a new car object with the given addresscar=sdk.cars.CarClass(address)
car.connect() # Connect to the carcar.start_notify() # Start receiving notifications from the carcontroller=sdk.controller.ControllerClass(car)
print(f"Pong! {car.ping()}ms") # Print the ping time to the carcontroller.set_speed(500, 500) # Set the speed of the cartime.sleep(10) # Wait for 10 secondscontroller.left_lane(1.0) # Move the car to the left lanetime.sleep(10) # Wait for 10 secondscontroller.right_lane(1.0) # Move the car to the right lanetime.sleep(10) # Wait for 10 seconds# Define a callback function for when a new track is detected@car.notifycallback(sdk.cars.Receive.Track.TRACK_CHANGE)defnew_track(sender, data):
print("New Track!")
# Define a callback function for when the car crosses the finish line@car.notifycallback(sdk.cars.Receive.Track.FINISHLINE)deffinish_line(sender, data):
print("Finish!")
# Define a callback function for when a special track is encountered@car.notifycallback(sdk.cars.Receive.Track.SPECIAL_TRACK)defspecial_track(sender, data):
print("Special Track!")
# Define a callback function for when a straight track is detected@car.notifycallback(sdk.cars.Receive.Track.STRAIGHT_TRACK)defstraight_track(sender, data):
print("New Straight Track!")
# Define a callback function for when a ping response is received@car.notifycallback(sdk.cars.Receive.Connection.PING_RESPONSE)defping_response(sender, data):
print("Ping Response!")
car.stop_notify() # Stop receiving notifications from the carcar.disconnect() # Disconnect from the car
API Example
Python
Client
fromanki_sdkimportapi# Create the client and establish a connection to the serverclient=api.Client("localhost")
# Create a car and get the tokentoken=client.create_car("AA:BB:CC:DD:EE:FF")
print("Token:", token)
# Set the speed of the carspeed=500# Speed value (in millimeters per second)accel=1000# Acceleration value (in millimeters per second squared)response=client.set_speed(speed, accel)
print("Set Speed Response:", response)
# Make the car switch to the left lanelanes=0.5# Number of lanes to switch (can be a decimal value)response=client.left_lane(lanes)
print("Left Lane Response:", response)
# Make the car switch to the right lanelanes=1.0# Number of lanes to switch (can be a decimal value)response=client.right_lane(lanes)
print("Right Lane Response:", response)
# Get a list of available carsactive=True# Flag to retrieve only active carscar_list=client.get_cars(active=active)
print("Available Cars:")
forcarincar_list:
print(car)
Javascript
Client
const{ Client }=require("./api/anki_api");asyncfunctionmain(){// Create the client and establish a connection to the serverconstclient=newClient("localhost");// Create a car and get the tokenconsttoken=awaitclient.create_car("AA:BB:CC:DD:EE:FF");console.log("Token:",token);// Set the speed of the carconstsetSpeedResponse=awaitclient.set_speed(500);console.log("Set Speed Response:",setSpeedResponse);// Make the car switch to the left laneconstleftLaneResponse=awaitclient.left_lane(0.5);console.log("Left Lane Response:",leftLaneResponse);// Make the car switch to the right laneconstrightLaneResponse=awaitclient.right_lane(1.0);console.log("Right Lane Response:",rightLaneResponse);// Get a list of available carsconstcarList=awaitclient.get_cars(true);console.log("Available Cars:");for(constcarofcarList){console.log(car);}}main();