Esempio n. 1
0
def main():
    wanderer = Tortoise()

    while True:

        touchSensor_1 = wanderer.getSensorData(enums.SensorType.touch, 1)
        touchSensor_2 = wanderer.getSensorData(enums.SensorType.touch, 2)
        touchSensor_3 = wanderer.getSensorData(enums.SensorType.touch, 3)

        if touchSensor_1 == 1:
                print "Switch 1 is on"
        else:
                print "Switch 1 is off"

        if touchSensor_2 == 1:
                print "Switch 2 is on"
        else:
                print "Switch 2 is off"

        if touchSensor_3 == 1:
                print "Switch 3 is on"
        else:
                print "Switch 3 is off"

        print

        time.sleep(1)
Esempio n. 2
0
def main():
    wanderer = Tortoise()

    while True:
        #pass
        wanderer.moveForward(100)
        print wanderer.getSensorData(enums.SensorType.light, 1)
def main():
    wanderer = Tortoise()

    while True:

        proximitySensor_1 = wanderer.getSensorData(enums.SensorType.proximity, 1)
        proximitySensor_2 = wanderer.getSensorData(enums.SensorType.proximity, 2)
        proximitySensor_3 = wanderer.getSensorData(enums.SensorType.proximity, 3)
        proximitySensor_4 = wanderer.getSensorData(enums.SensorType.proximity, 4)

        if proximitySensor_1 == 1:
                print "Proximity sensor 1 is ON"
        else:
                print "Proximity sensor 1 is OFF"

        if proximitySensor_2 == 1:
                print "Proximity sensor 2 is ON"
        else:
                print "Proximity sensor 2 is OFF"

        if proximitySensor_3 == 1:
                print "Proximity sensor 3 is ON"
        else:
                print "Proximity sensor 3 is OFF"

        if proximitySensor_4 == 1:
                print "Proximity sensor 4 is ON"
        else:
                print "Proximity sensor 4 is OFF"

        print

        time.sleep(1)
Esempio n. 4
0
 def test_truthy_thingy(self):
     templ = Tortoise('{% if items %}we have items{% end %}')
     self.assertEquals(templ.render({'items': []}), '')
     rv = Tortoise('{% if items %}we have items{% end %}').render({
         'items': None})
     self.assertEquals(rv, '')
     rv = Tortoise('{% if items %}we have items{% end %}').render({
         'items': ''})
     self.assertEquals(rv, '')
     rv = Tortoise('{% if items %}we have items{% end %}').render({
         'items': [1]})
     self.assertEquals(rv, 'we have items')
Esempio n. 5
0
def main():
	Mike = Tortoise()

	while True:
		if Mike.getSensorData(SensorType.light, 1) < 6:
			Mike.doRandomStep()
			print "Where's the light?"
		elif 6<= Mike.getSensorData(SensorType.light, 1)  and Mike.getSensorData(SensorType.light, 1) <9:
			print "Found Light"
			Mike.moveForward(30)	
		else: 
			print "Argh! Too much light!"
			Mike.moveBackward(30)
def main():
    wanderer = Tortoise()

    while True:

        proximitySensor_1 = wanderer.getSensorData(enums.SensorType.proximity, 4)

        if proximitySensor_1 == 1:
                print "Proximity sensor 1 is ON"
        else:
                print "Proximity sensor 1 is OFF"

        print

        time.sleep(0.1)
Esempio n. 7
0
def main():
	Bob=Tortoise()
	while True:
		if Bob.getSensorData(SensorType.light,1)<4:
			Bob.doRandomStep()
			print "where are you?"
		elif Bob.getSensorData(SensorType.light,1)<9:
			Bob.moveForward(30)
			print "ah-ha!"
		else :
			Bob.moveBackward(30)
			print "Burning burning!"
def main():
    wanderer = Tortoise()

    while True:
        #pass
        wanderer.moveForward(100)
        #print wanderer.getSensorData(enums.SensorType.light, 1)
        if wanderer.getSensorData(enums.SensorType.emergencySwitch, 1) == 1:
                        #print "1"
	        wanderer.setActuatorValue(enums.ActuatorType.led, 1,1)
        else:
                        #print "0"
	        wanderer.setActuatorValue(enums.ActuatorType.led, 1,0)
Esempio n. 9
0
def main():
    wanderer = Tortoise()

    wanderer.setLEDValue(1, 1)
    wanderer.setLEDValue(2, 1)
    wanderer.setLEDValue(3, 1)
    wanderer.setLEDValue(4, 1)

    while True:

        wanderer.moveForwards(2000)
Esempio n. 10
0
def main():
    wanderer = Tortoise()

    while True:

        print "Blinking LED 1"
        wanderer.blinkLEDs(1, 3, 0.5, blocking = False)
        print "\tPress enter to continue"
        raw_input()

        print "Blinking LED 2"
        wanderer.blinkLEDs(2, 3, 0.5, blocking = False)
        print "\tPress enter to continue"
        raw_input()

        print "Blinking LED 3"
        wanderer.blinkLEDs(3, 3, 0.5, blocking = False)
        print "\tPress enter to continue"
        raw_input()

        print "Blinking LED 4"
        wanderer.blinkLEDs(4, 3, 0.5, blocking = False)
        print "\tPress enter to continue"
        raw_input()
Esempio n. 11
0
 def continue_if_safe_indexes(self, supported: bool):
     db = Tortoise.get_connection("default")
     if db.capabilities.safe_indexes != supported:
         raise test.SkipTest("safe_indexes != {}".format(supported))
Esempio n. 12
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Elsie=Tortoise()

while True:

    proxSensor = Elsie.getSensorData(SensorType.proximity,2)
    if proxSensor == 1:
        print "Obstacle detected behind"
        Elsie.setLEDValue(1, 1) #self.setLEDValue(position, value)
	Elsie.moveForwards(150)
    else:
        print "No obstacle detected"
        Elsie.setLEDValue(1, 0) #self.setLEDValue(position, value)
        Elsie.doRandomMovement()
Esempio n. 13
0
 async def test_init_yaml_file(self):
     await Tortoise.init(config_file=os.path.dirname(__file__) +
                         "/init.yaml")
     self.assertIn("models", Tortoise.apps)
     self.assertIsNotNone(Tortoise.get_connection("default"))
Esempio n. 14
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Elmer=Tortoise()

while True:

    proxSensor = Elmer.getSensorData(SensorType.proximity,1)
    proxSensor2 = Elmer.getSensorData(SensorType.proximity,2)

    if proxSensor == 1 and proxSensor2 == 0:

        print "Obstacle detected in front"
        Elmer.setLEDValue(1, 1) #self.setLEDValue(position, value)
        Elmer.setLEDValue(2, 0) #self.setLEDValue(position, value)
        Elmer.moveBackwards(150)

    elif proxSensor == 1 and proxSensor2 == 1:

        print "Obstacles detected in front and behind!"
        Elmer.setLEDValue(1, 1) #self.setLEDValue(position, value)
        Elmer.setLEDValue(2, 1) #self.setLEDValue(position, value)

    elif proxSensor == 0 and proxSensor2 == 1:

        print "Obstacle detected behind"
        Elmer.setLEDValue(1, 0) #self.setLEDValue(position, value)
        Elmer.setLEDValue(2, 1) #self.setLEDValue(position, value)
        Elmer.moveForwards(150)

    else:
Esempio n. 15
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Name=Tortoise()

while True:

    touchSensor = Name.getSensorData(SensorType.touch,1)
    print "Front switch is:" 
    print touchSensor
    touchSensor2 = Name.getSensorData(SensorType.touch,3)
    print "Back switch is: " 
    print touchSensor2
    if touchSensor == 1:
        print "Switch is on"
        Name.moveBackwards(30)
        Name.setLEDValue(1, 1) #self.setLEDValue(position, value)
        Name.setLEDValue(2, 0) #self.setLEDValue(position, value)
	touchSensor2Loop = Name.getSensorData(SensorType.touch,3)
	print "Back switch as read inside loop: " 
        print touchSensor2Loop
	if touchSensor2 == 1:
		print "Back switch has been hit"
		Name.moveForwards(30)
		Name.setLEDValue(2, 0) #self.setLEDValue(position, value)
		if touchSensor == 0:
			break
   # else:
        #print "Switch is off"
        #Name.moveForwards(30)
        #Name.setLEDValue(1, 0) #self.setLEDValue(position, value)
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Name=Tortoise()

while True:

    proxSensor = Name.getSensorData(SensorType.proximity,1)
    proxSensor2 = Name.getSensorData(SensorType.proximity,2)
    if proxSensor == 1 and proxSensor2 == 0:
        print "Obstacle detected in front"
        Name.setLEDValue(1, 1) #self.setLEDValue(position, value)
    	Name.setLEDValue(2, 0) #self.setLEDValue(position, value)
    	Name.moveBackwards(100)
    if proxSensor == 1 and proxSensor2 == 1:
    	print "Obstacles detected in front and behind!"
    	Name.setLEDValue(1, 1) #self.setLEDValue(position, value)
   	Name.setLEDValue(2, 1) #self.setLEDValue(position, value)
    if proxSensor == 0 and proxSensor2 == 1:
        print "Obstacle detected behind"
        Name.setLEDValue(1, 0) #self.setLEDValue(position, value)
    	Name.setLEDValue(2, 1) #self.setLEDValue(position, value)
    	Name.moveForwards(100)
    else:
        print "No obstacle detected"
        Name.doRandomMovement()
        Name.setLEDValue(1, 0) #self.setLEDValue(position, value)
   	Name.setLEDValue(2, 0) #self.setLEDValue(position, value)
    async def test_schema_safe(self):
        self.maxDiff = None
        await self.init_for("tests.schema.models_schema_create")
        sql = get_schema_sql(Tortoise.get_connection("default"), safe=True)
        self.assertEqual(
            sql.strip(),
            """
CREATE TABLE IF NOT EXISTS "defaultpk" (
    "id" SERIAL NOT NULL PRIMARY KEY,
    "val" INT NOT NULL
);
CREATE TABLE IF NOT EXISTS "inheritedmodel" (
    "id" SERIAL NOT NULL PRIMARY KEY,
    "zero" INT NOT NULL,
    "one" VARCHAR(40),
    "new_field" VARCHAR(100) NOT NULL,
    "two" VARCHAR(40) NOT NULL,
    "name" TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS "sometable" (
    "sometable_id" SERIAL NOT NULL PRIMARY KEY,
    "some_chars_table" VARCHAR(255) NOT NULL,
    "fk_sometable" INT REFERENCES "sometable" ("sometable_id") ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS "idx_sometable_some_ch_3d69eb" ON "sometable" ("some_chars_table");
CREATE TABLE IF NOT EXISTS "team" (
    "name" VARCHAR(50) NOT NULL  PRIMARY KEY,
    "key" INT NOT NULL,
    "manager_id" VARCHAR(50) REFERENCES "team" ("name") ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS "idx_team_manager_676134" ON "team" ("manager_id", "key");
CREATE INDEX IF NOT EXISTS "idx_team_manager_ef8f69" ON "team" ("manager_id", "name");
COMMENT ON COLUMN "team"."name" IS 'The TEAM name (and PK)';
COMMENT ON TABLE "team" IS 'The TEAMS!';
CREATE TABLE IF NOT EXISTS "teamaddress" (
    "city" VARCHAR(50) NOT NULL,
    "country" VARCHAR(50) NOT NULL,
    "street" VARCHAR(128) NOT NULL,
    "team_id" VARCHAR(50) NOT NULL UNIQUE PRIMARY KEY REFERENCES "team" ("name") ON DELETE CASCADE
);
COMMENT ON COLUMN "teamaddress"."city" IS 'City';
COMMENT ON COLUMN "teamaddress"."country" IS 'Country';
COMMENT ON COLUMN "teamaddress"."street" IS 'Street Address';
CREATE TABLE IF NOT EXISTS "tournament" (
    "tid" SMALLSERIAL NOT NULL PRIMARY KEY,
    "name" VARCHAR(100) NOT NULL,
    "created" TIMESTAMP NOT NULL
);
CREATE INDEX IF NOT EXISTS "idx_tournament_name_6fe200" ON "tournament" ("name");
COMMENT ON COLUMN "tournament"."name" IS 'Tournament name';
COMMENT ON COLUMN "tournament"."created" IS 'Created */''`/* datetime';
COMMENT ON TABLE "tournament" IS 'What Tournaments */''`/* we have';
CREATE TABLE IF NOT EXISTS "event" (
    "id" BIGSERIAL NOT NULL PRIMARY KEY,
    "name" TEXT NOT NULL,
    "modified" TIMESTAMP NOT NULL,
    "prize" DECIMAL(10,2),
    "token" VARCHAR(100) NOT NULL UNIQUE,
    "key" VARCHAR(100) NOT NULL,
    "tournament_id" SMALLINT NOT NULL REFERENCES "tournament" ("tid") ON DELETE CASCADE,
    CONSTRAINT "uid_event_name_c6f89f" UNIQUE ("name", "prize"),
    CONSTRAINT "uid_event_tournam_a5b730" UNIQUE ("tournament_id", "key")
);
COMMENT ON COLUMN "event"."id" IS 'Event ID';
COMMENT ON COLUMN "event"."token" IS 'Unique token';
COMMENT ON COLUMN "event"."tournament_id" IS 'FK to tournament';
COMMENT ON TABLE "event" IS 'This table contains a list of all the events';
CREATE TABLE IF NOT EXISTS "venueinformation" (
    "id" SERIAL NOT NULL PRIMARY KEY,
    "name" VARCHAR(128) NOT NULL,
    "capacity" INT NOT NULL,
    "rent" DOUBLE PRECISION NOT NULL,
    "team_id" VARCHAR(50)  UNIQUE REFERENCES "team" ("name") ON DELETE SET NULL
);
CREATE TABLE IF NOT EXISTS "sometable_self" (
    "backward_sts" INT NOT NULL REFERENCES "sometable" ("sometable_id") ON DELETE CASCADE,
    "sts_forward" INT NOT NULL REFERENCES "sometable" ("sometable_id") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "team_team" (
    "team_rel_id" VARCHAR(50) NOT NULL REFERENCES "team" ("name") ON DELETE CASCADE,
    "team_id" VARCHAR(50) NOT NULL REFERENCES "team" ("name") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "teamevents" (
    "event_id" BIGINT NOT NULL REFERENCES "event" ("id") ON DELETE CASCADE,
    "team_id" VARCHAR(50) NOT NULL REFERENCES "team" ("name") ON DELETE CASCADE
);
COMMENT ON TABLE "teamevents" IS 'How participants relate';
""".strip(),
        )
Esempio n. 18
0
 async def test_bad_charset(self):
     self.db_config["connections"]["models"]["charset"] = "terrible"
     with self.assertRaisesRegex(ConnectionError, "Unknown charset"):
         Tortoise.init(self.db_config)
         await Tortoise.open_connections()
Esempio n. 19
0
    class PydanticMeta:
        exclude = ["password"]


class MyApis(models.Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=50, null=True)
    description = fields.CharField(max_length=200, null=True)
    polling_frequency = fields.IntField()
    polling_unit = fields.CharField(max_length=12, null=True)  #seconds/minute
    url = fields.CharField(max_length=100, null=True)
    http_headers = fields.CharField(max_length=100, null=True)
    query_params = fields.CharField(max_length=100, null=True)
    created_at = fields.DatetimeField(auto_now_add=True)
    modified_at = fields.DatetimeField(auto_now=True)
    created_by: fields.ForeignKeyRelation[Users] = fields.ForeignKeyField(
        'models.Users', null=True, related_name="myapi_users")


Tortoise.init_models(["models"], "models")
UserPydantic = pydantic_model_creator(Users, name="User")
UserOutPydantic = pydantic_model_creator(Users, name="UserOutPydantic")
UserInPydantic = pydantic_model_creator(Users,
                                        name="UserIn",
                                        exclude_readonly=True)
MyApiPydantic = pydantic_model_creator(MyApis, name="MyApi")
MyApisInPydantic = pydantic_model_creator(MyApis,
                                          name="MyApiIn",
                                          exclude_readonly=True)
#print (UserPydantic.schema_json(indent=2))
Esempio n. 20
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Dennis=Tortoise()

while True:

    Dennis.setLEDValue(1, 0)
    Dennis.setLEDValue(2, 0)

    rightSensor = Dennis.getSensorData(SensorType.proximity,1)
    leftSensor = Dennis.getSensorData(SensorType.proximity,2)

    if rightSensor == 1:

        print "Obstruction right"
        Dennis.setLEDValue(1, 1) 
        Dennis.turnOnTheSpot(20,Direction.backwards_right)

    elif leftSensor == 1:

        print "Obstruction left"
        Dennis.setLEDValue(2,1)
        Dennis.turnOnTheSpot(20,Direction.backwards_left)

    else:

        print "I'm wandering..."
        Dennis.moveForwards(30)

Esempio n. 21
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Name=Tortoise()

while True:

    touchSensor = Name.getSensorData(SensorType.touch,1)
    if touchSensor == 1:
        print "Switch is on"
        Name.moveBackwards(30)
        Name.setLEDValue(1, 1) #self.setLEDValue(position, value)
        Name.setLEDValue(2, 0) #self.setLEDValue(position, value)
	if touchSensor == 1:
		print "Back switch has been hit"
		Name.moveForwards(30)
		Name.setLEDValue(2, 0) #self.setLEDValue(position, value)
    else:
        print "Switch is off"
        Name.moveForwards(30)
        Name.setLEDValue(1, 0) #self.setLEDValue(position, value)
        Name.setLEDValue(2, 1) #self.setLEDValue(position, value)
Esempio n. 22
0
 def test_reusability(self):
     # A single template can be used more than once with different data
     template = Tortoise("This is {{ name }}")
     self.assertEqual(template.render({'name': 'Foo'}), 'This is Foo')
     self.assertEqual(template.render({'name': 'Bar'}), 'This is Bar')
Esempio n. 23
0
""" It's neccesary in order to import modules not in the same folder, but in a different one.
This is the way to tell python the location on those subfolders: """
import os, sys, inspect

cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0]))
if cmd_folder not in sys.path:
	sys.path.insert(0, cmd_folder)

sys.path.append('../')
# ------------------------------ #

from tortoise import Tortoise
import enums
import time

t = Tortoise()

while(True):

    t.turn45degrees_sharp(enums.Direction.forwards_left)
    t.turn45degrees_sharp(enums.Direction.forwards_left)
    time.sleep(1)

    t.turn45degrees_sharp(enums.Direction.backwards_left)
    t.turn45degrees_sharp(enums.Direction.backwards_left)
    time.sleep(1)

    t.turn45degrees_sharp(enums.Direction.forwards_right)
    t.turn45degrees_sharp(enums.Direction.forwards_right)
    time.sleep(1)
    async def test_schema_safe(self):
        self.maxDiff = None
        await self.init_for("tests.schema.models_schema_create")
        sql = get_schema_sql(Tortoise.get_connection("default"), safe=True)

        self.assertEqual(
            sql.strip(),
            """
CREATE TABLE IF NOT EXISTS `defaultpk` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `val` INT NOT NULL
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `inheritedmodel` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `zero` INT NOT NULL,
    `one` VARCHAR(40),
    `new_field` VARCHAR(100) NOT NULL,
    `two` VARCHAR(40) NOT NULL,
    `name` TEXT NOT NULL
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `sometable` (
    `sometable_id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `some_chars_table` VARCHAR(255) NOT NULL,
    `fk_sometable` INT,
    CONSTRAINT `fk_sometabl_sometabl_6efae9bd` FOREIGN KEY (`fk_sometable`) REFERENCES `sometable` (`sometable_id`) ON DELETE CASCADE,
    KEY `idx_sometable_some_ch_3d69eb` (`some_chars_table`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `team` (
    `name` VARCHAR(50) NOT NULL  PRIMARY KEY COMMENT 'The TEAM name (and PK)',
    `key` INT NOT NULL,
    `manager_id` VARCHAR(50),
    CONSTRAINT `fk_team_team_9c77cd8f` FOREIGN KEY (`manager_id`) REFERENCES `team` (`name`) ON DELETE CASCADE,
    KEY `idx_team_manager_676134` (`manager_id`, `key`),
    KEY `idx_team_manager_ef8f69` (`manager_id`, `name`)
) CHARACTER SET utf8mb4 COMMENT='The TEAMS!';
CREATE TABLE IF NOT EXISTS `teamaddress` (
    `city` VARCHAR(50) NOT NULL  COMMENT 'City',
    `country` VARCHAR(50) NOT NULL  COMMENT 'Country',
    `street` VARCHAR(128) NOT NULL  COMMENT 'Street Address',
    `team_id` VARCHAR(50) NOT NULL UNIQUE PRIMARY KEY,
    CONSTRAINT `fk_teamaddr_team_1c78d737` FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `tournament` (
    `tid` SMALLINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `name` VARCHAR(100) NOT NULL  COMMENT 'Tournament name',
    `created` DATETIME(6) NOT NULL  COMMENT 'Created */\\'`/* datetime',
    KEY `idx_tournament_name_6fe200` (`name`)
) CHARACTER SET utf8mb4 COMMENT='What Tournaments */\\'`/* we have';
CREATE TABLE IF NOT EXISTS `event` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT 'Event ID',
    `name` TEXT NOT NULL,
    `modified` DATETIME(6) NOT NULL,
    `prize` DECIMAL(10,2),
    `token` VARCHAR(100) NOT NULL UNIQUE COMMENT 'Unique token',
    `key` VARCHAR(100) NOT NULL,
    `tournament_id` SMALLINT NOT NULL COMMENT 'FK to tournament',
    UNIQUE KEY `uid_event_name_c6f89f` (`name`, `prize`),
    UNIQUE KEY `uid_event_tournam_a5b730` (`tournament_id`, `key`),
    CONSTRAINT `fk_event_tourname_51c2b82d` FOREIGN KEY (`tournament_id`) REFERENCES `tournament` (`tid`) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COMMENT='This table contains a list of all the events';
CREATE TABLE IF NOT EXISTS `venueinformation` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `name` VARCHAR(128) NOT NULL,
    `capacity` INT NOT NULL,
    `rent` DOUBLE NOT NULL,
    `team_id` VARCHAR(50)  UNIQUE,
    CONSTRAINT `fk_venueinf_team_198af929` FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE SET NULL
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `sometable_self` (
    `backward_sts` INT NOT NULL,
    `sts_forward` INT NOT NULL,
    FOREIGN KEY (`backward_sts`) REFERENCES `sometable` (`sometable_id`) ON DELETE CASCADE,
    FOREIGN KEY (`sts_forward`) REFERENCES `sometable` (`sometable_id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `team_team` (
    `team_rel_id` VARCHAR(50) NOT NULL,
    `team_id` VARCHAR(50) NOT NULL,
    FOREIGN KEY (`team_rel_id`) REFERENCES `team` (`name`) ON DELETE CASCADE,
    FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `teamevents` (
    `event_id` BIGINT NOT NULL,
    `team_id` VARCHAR(50) NOT NULL,
    FOREIGN KEY (`event_id`) REFERENCES `event` (`id`) ON DELETE CASCADE,
    FOREIGN KEY (`team_id`) REFERENCES `team` (`name`) ON DELETE CASCADE
) CHARACTER SET utf8mb4 COMMENT='How participants relate';
""".strip(),
        )
Esempio n. 25
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Name=Tortoise()

while True:

    touchSensor = Name.getSensorData(SensorType.touch,1)
    if touchSensor == 1:
        print "Switch is on"
        Name.moveForwards(30)
        Name.setLEDValue(1, 1) #self.setLEDValue(position, value)
    else:
        print "Switch is off"
        Name.setLEDValue(1, 0) #self.setLEDValue(position, value)
    async def test_schema_safe(self):
        self.maxDiff = None
        await self.init_for("tests.schema.models_schema_create")
        sql = get_schema_sql(Tortoise.get_connection("default"), safe=True)
        self.assertEqual(
            sql.strip(),
            """
CREATE TABLE IF NOT EXISTS "defaultpk" (
    "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    "val" INT NOT NULL
);
CREATE TABLE IF NOT EXISTS "inheritedmodel" (
    "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    "zero" INT NOT NULL,
    "one" VARCHAR(40),
    "new_field" VARCHAR(100) NOT NULL,
    "two" VARCHAR(40) NOT NULL,
    "name" TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS "sometable" (
    "sometable_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    "some_chars_table" VARCHAR(255) NOT NULL,
    "fk_sometable" INT REFERENCES "sometable" ("sometable_id") ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS "idx_sometable_some_ch_3d69eb" ON "sometable" ("some_chars_table");
CREATE TABLE IF NOT EXISTS "team" (
    "name" VARCHAR(50) NOT NULL  PRIMARY KEY /* The TEAM name (and PK) */,
    "key" INT NOT NULL,
    "manager_id" VARCHAR(50) REFERENCES "team" ("name") ON DELETE CASCADE
) /* The TEAMS! */;
CREATE INDEX IF NOT EXISTS "idx_team_manager_676134" ON "team" ("manager_id", "key");
CREATE INDEX IF NOT EXISTS "idx_team_manager_ef8f69" ON "team" ("manager_id", "name");
CREATE TABLE IF NOT EXISTS "teamaddress" (
    "city" VARCHAR(50) NOT NULL  /* City */,
    "country" VARCHAR(50) NOT NULL  /* Country */,
    "street" VARCHAR(128) NOT NULL  /* Street Address */,
    "team_id" VARCHAR(50) NOT NULL UNIQUE PRIMARY KEY REFERENCES "team" ("name") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "tournament" (
    "tid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    "name" VARCHAR(100) NOT NULL  /* Tournament name */,
    "created" TIMESTAMP NOT NULL  /* Created *\\/'`\\/* datetime */
) /* What Tournaments *\\/'`\\/* we have */;
CREATE INDEX IF NOT EXISTS "idx_tournament_name_6fe200" ON "tournament" ("name");
CREATE TABLE IF NOT EXISTS "event" (
    "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL /* Event ID */,
    "name" TEXT NOT NULL,
    "modified" TIMESTAMP NOT NULL,
    "prize" VARCHAR(40),
    "token" VARCHAR(100) NOT NULL UNIQUE /* Unique token */,
    "key" VARCHAR(100) NOT NULL,
    "tournament_id" SMALLINT NOT NULL REFERENCES "tournament" ("tid") ON DELETE CASCADE /* FK to tournament */,
    CONSTRAINT "uid_event_name_c6f89f" UNIQUE ("name", "prize"),
    CONSTRAINT "uid_event_tournam_a5b730" UNIQUE ("tournament_id", "key")
) /* This table contains a list of all the events */;
CREATE TABLE IF NOT EXISTS "venueinformation" (
    "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    "name" VARCHAR(128) NOT NULL,
    "capacity" INT NOT NULL,
    "rent" REAL NOT NULL,
    "team_id" VARCHAR(50)  UNIQUE REFERENCES "team" ("name") ON DELETE SET NULL
);
CREATE TABLE IF NOT EXISTS "sometable_self" (
    "backward_sts" INT NOT NULL REFERENCES "sometable" ("sometable_id") ON DELETE CASCADE,
    "sts_forward" INT NOT NULL REFERENCES "sometable" ("sometable_id") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "team_team" (
    "team_rel_id" VARCHAR(50) NOT NULL REFERENCES "team" ("name") ON DELETE CASCADE,
    "team_id" VARCHAR(50) NOT NULL REFERENCES "team" ("name") ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "teamevents" (
    "event_id" BIGINT NOT NULL REFERENCES "event" ("id") ON DELETE CASCADE,
    "team_id" VARCHAR(50) NOT NULL REFERENCES "team" ("name") ON DELETE CASCADE
) /* How participants relate */;
""".strip(),
        )
Esempio n. 27
0
""" It's neccesary in order to import modules not in the same folder, but in a different one.
This is the way to tell python the location on those subfolders: """
import os, sys, inspect

cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]))
if cmd_folder not in sys.path:
    sys.path.insert(0, cmd_folder)

sys.path.append("../")
# ------------------------------ #

from tortoise import Tortoise
import enums
import time

t = Tortoise()

while True:

    t.turn30degrees_wide(enums.Direction.forwards_left)
    t.turn30degrees_wide(enums.Direction.forwards_left)
    t.turn30degrees_wide(enums.Direction.forwards_left)
    time.sleep(1)

    t.turn30degrees_wide(enums.Direction.backwards_left)
    t.turn30degrees_wide(enums.Direction.backwards_left)
    t.turn30degrees_wide(enums.Direction.backwards_left)
    time.sleep(1)

    t.turn30degrees_wide(enums.Direction.forwards_right)
    t.turn30degrees_wide(enums.Direction.forwards_right)
Esempio n. 28
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Name = Tortoise()

while True:

    proxSensor = Name.getSensorData(SensorType.proximity, 1)
    if proxSensor == 1:
        print "Obstacle dected"
        Name.setLEDValue(1, 1)  #self.setLEDValue(position, value)
    else:
        print "No obstacle detected"
        Name.moveForwards(30)
        Name.setLEDValue(1, 0)  #self.setLEDValue(position, value)
Esempio n. 29
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType
Walter=Tortoise()

lastMove = "forward"

while True:

    frontSwitch = Walter.getSensorData(SensorType.touch, 1)
    backSwitch = Walter.getSensorData(SensorType.touch, 2)

    if frontSwitch ==1 and backSwitch ==0:
        print "Obstacle in front - moving backwards"    
        Walter.setLEDValue(1, 0) #self.setLEDValue(position, value)
        Walter.setLEDValue(2, 1) #self.setLEDValue(position, value)
        Walter.moveBackwards(100)
        lastMove = "back"
    elif backSwitch ==1 and frontSwitch ==1:
        print "Can't move!"    
    elif frontSwitch ==0 and backSwitch ==1:
        print "Obstacle behind - moving forwards"    
        Walter.setLEDValue(1, 1) #self.setLEDValue(position, value)
        Walter.setLEDValue(2, 0) #self.setLEDValue(position, value)
        Walter.moveForwards(100)
        lastMove = "forward"
    else:
        print "Exploring"
        Walter.setLEDValue(1, 1) #self.setLEDValue(position, value)
        Walter.setLEDValue(2, 1) #self.setLEDValue(position, value)
	if lastMove == "forward":
	        Walter.moveForwards(100)
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Name=Tortoise()

lastFrontSwitch = 0
lastBackSwitch = 0

while True:
	currentFrontSwitch = Name.getSensorData(SensorType.touch,3)
	currentBackSwitch = Name.getSensorData(SensorType.touch,1)
    
	forwards = abs(lastBackSwitch - currentBackSwitch)
	backwards = abs(lastFrontSwitch - currentFrontSwitch)

	if forwards==1 and backwards==0:
		lastFrontSwitch=currentFrontSwitch
		print "Moving forwards"
        	Name.moveForwards(5)
		
	if backwards ==1 and forwards==0:
		lastbackSwitch=currentBackSwitch
		print "Moving backwards"
		Name.moveBackwards(5)
	else:
		print "No switches on"

Esempio n. 31
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

# F  B 
# 0  0  move forwards
# 1  0  move backwards
# 1  1  move forwards
# 0  1  move backwards

Name=Tortoise()

while True:

    forwardSwitch = Name.getSensorData(SensorType.touch, 1)
    backwardSwitch = Name.getSensorData(SensorType.touch, 2)
#    if (forwardSwitch == backwardSwitch):
    if (forwardSwitch == 0 and backwardSwitch == 0) or (forwardSwitch == 1 and backwardSwitch == 1):
	print "monkey"
	if forwardSwitch == 1:
                print "Switch 1 is on"
        else:
                print "Switch 1 is off"

        if backwardSwitch == 1:
                print "Switch 2 is on"
        else:
                print "Switch 2 is off"

	print " "
        Name.moveForwards(100)
        Name.setLEDValue(1, 1) #self.setLEDValue(position, value)
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

# F  B 
# 0  0  move forwards
# 1  0  move backwards
# 1  1  move forwards
# 0  1  move backwards

Name=Tortoise()

while True:

    forwardSwitch = Name.getSensorData(SensorType.proximity, 1)
    backwardSwitch = Name.getSensorData(SensorType.proximity, 2)
#    if (forwardSwitch == backwardSwitch):
    if (forwardSwitch == 0 and backwardSwitch == 0) or (forwardSwitch == 1 and backwardSwitch == 1):
	print "monkey"
	if forwardSwitch == 1:
                print "Switch 1 is on"
        else:
                print "Switch 1 is off"

        if backwardSwitch == 1:
                print "Switch 2 is on"
        else:
                print "Switch 2 is off"

	print " "
        Name.moveForwards(30)
        Name.setLEDValue(1, 1) #self.setLEDValue(position, value)
Esempio n. 33
0
def main():
    wanderer = Tortoise()

    while True:
	    wanderer.moveForward(100)
Esempio n. 34
0
 async def test_shorthand_init(self):
     await Tortoise.init(db_url=f"sqlite://{':memory:'}",
                         modules={"models": ["tests.testmodels"]})
     self.assertIn("models", Tortoise.apps)
     self.assertIsNotNone(Tortoise.get_connection("default"))
Esempio n. 35
0
from tortoise import Tortoise
from enums import Direction, SensorType, ActuatorType

Grey = Tortoise()

while True:

    touchSensor = Grey.getSensorData(SensorType.touch, 1)

    if touchSensor == 1:

        print "Switch is on"
        Grey.setLEDValue(1, 1)  # self.setLEDValue(position, value)
        Grey.moveForwards(50)

    else:

        print "Switch is off"
        Grey.setLEDValue(1, 0)  # self.setLEDValue(position, value)
Esempio n. 36
0
    events: fields.ReverseRelation["Event"]

    class Meta:
        ordering = ["name"]


class Event(Model):
    id = fields.IntField(pk=True)
    name = fields.TextField()
    created_at = fields.DatetimeField(auto_now_add=True)
    tournament: fields.ForeignKeyNullableRelation[
        Tournament] = fields.ForeignKeyField("models.Tournament",
                                             related_name="events",
                                             null=True)

    class Meta:
        ordering = ["name"]


Event_TooEarly = pydantic_model_creator(Event)
print("Relations are missing if models not initialized:")
print(Event_TooEarly.schema_json(indent=4))

Tortoise.init_models(["__main__"], "models")

Event_Pydantic = pydantic_model_creator(Event)
print("\nRelations are now present:")
print(Event_Pydantic.schema_json(indent=4))

# Now we can use the pydantic model early if needed
Esempio n. 37
0
def main():
    wanderer = Tortoise()

    while True:

        print "Moving forwards"
        wanderer.moveForwards(500)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()


        print "Moving backwards"
        wanderer.moveBackwards(500)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()


        print "Turning on the spot forwards_left"
        wanderer.turnOnTheSpot(500, enums.Direction.forwards_left)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning on the spot forwards_right"
        wanderer.turnOnTheSpot(500, enums.Direction.forwards_right)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning on the spot backwards_left"
        wanderer.turnOnTheSpot(500, enums.Direction.backwards_left)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning on the spot bakwards_right"
        wanderer.turnOnTheSpot(500, enums.Direction.backwards_right)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning naturally forwards_left"
        wanderer.turn(200, 500, enums.Direction.forwards_left)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning naturally backwards_left"
        wanderer.turn(200, 500, enums.Direction.backwards_left)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning naturally forwards_right"
        wanderer.turn(500, 200, enums.Direction.forwards_right)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Turning naturally backwards_right"
        wanderer.turn(500, 200, enums.Direction.backwards_right)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Gyrating clockwise"
        wanderer.shuffleOnTheSpot(500, enums.Direction.clockwise)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()

        print "Gyrating counter clockwise"
        wanderer.shuffleOnTheSpot(500, enums.Direction.counterClockwise)
        time.sleep(0.5)

        print
        print "\tPress enter to continue"
        print
        raw_input()
Esempio n. 38
0
from tortoise import Tortoise
from enums import Direction, SensorType
# In this version, they test the robot first and then fix the values and fill in the else. If format is good, but too much work, then prefill else.

# Change this to 1 when you've calibrated and have some values for not enough light, good light and too much light.
calibrated = 0;

# Name your tortoise here.
Name = Tortoise()

if (calibrated==0):
	print "Let's use different levels of light to see what calibrated readings we get"
	raw_input("First let's see what the room gives us, press enter when you're done")
	print Name.getSensorData(SensorType.light,1)
	raw_input("Now try it with a light source right up close and press enter when you're done")
	print Name.getSensorData(SensorType.light,1)
	raw_input("And now try somewhere in the middle")
	print Name.getSensorData(SensorType.light,1)

while True and (calibrated==1):
	# First we need a reading from the light sensor
	lightSensorReading = Name.getSensorData(SensorType.light,1)
	
	# Can you tune the light sensor values for the conditions based on your calibration findings?
	if lightSensorReading < 1:
		Name.moveForward(30, Direction)
		print "Where's the light?"
	elif 1<= lightSensorReading  and lightSensorReading <2:
		print "Found the light!"
		Name.moveBackward(30)	
	else: 
# IMPORT MODULES FROM SUBFOLDERS #
""" It's neccesary in order to import modules not in the same folder, but in a different one.
This is the way to tell python the location on those subfolders: """
import os, sys, inspect

cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0]))
if cmd_folder not in sys.path:
	sys.path.insert(0, cmd_folder)

sys.path.append('../')
# ------------------------------ #

from tortoise import Tortoise
import enums
import time

t = Tortoise()

while(True):

    t.doRandomMovement()
Esempio n. 40
0
def main():
    wanderer = Tortoise()

    while True:

        wanderer.setLEDValue(1, 1)
        wanderer.setLEDValue(2, 0)
        wanderer.setLEDValue(3, 1)
        wanderer.setLEDValue(4, 0)

        print "LEDs 1 and 3 set"
        print
        print "\tPress enter to continue"
        raw_input()

        print "Blinking LED 1, 2, 3 and 4"

        wanderer.blinkLEDs([3, 4, 1, 2], 3, 0.3, blocking=False)

        print "Check status of LEDs after blinking"
        print
        print "\tPress enter to continue"
        raw_input()

        wanderer.setLEDValue(1, 1)
        wanderer.setLEDValue(2, 1)
        wanderer.setLEDValue(3, 1)
        wanderer.setLEDValue(4, 1)

        print "LEDs 1, 2, 3 and 4 set"
        print
        print "\tPress enter to continue"
        raw_input()

        print "Blinking LED 1, 2, 3 and 4"

        wanderer.blinkLEDs([3, 4, 1, 2], 3, 0.3, blocking=False)

        print "Check status of LEDs after blinking"
        print
        print "\tPress enter to continue"
        raw_input()
Esempio n. 41
0
from tortoise import Tortoise
from enums import Direction, SensorType

Name = Tortoise()

while True:

    touchSensorValue = Name.getSensorData(SensorType.touch, 1)

    if touchSensorValue == 1:

        print "Touch sensor is being pressed"
        Name.setLEDValue(1, 1)
        Name.moveForwards(50)

    else:

        print "Nothing is pressing the touch sensor"
        Name.setLEDValue(1, 0)
Esempio n. 42
0
# IMPORT MODULES FROM SUBFOLDERS #
""" It's neccesary in order to import modules not in the same folder, but in a different one.
This is the way to tell python the location on those subfolders: """
import os, sys, inspect

cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0]))
if cmd_folder not in sys.path:
	sys.path.insert(0, cmd_folder)

sys.path.append('../')
# ------------------------------ #

from tortoise import Tortoise
import enums
import time

t = Tortoise()

while(True):

    t.shuffle45degrees(enums.Direction.clockwise)
    t.shuffle45degrees(enums.Direction.clockwise)
    time.sleep(1)

    t.shuffle45degrees(enums.Direction.counterClockwise)
    t.shuffle45degrees(enums.Direction.counterClockwise)
    time.sleep(1)

Esempio n. 43
-8
def main():
    wanderer = Tortoise()

    while True:
        # print "Light 1: " + str(wanderer.getSensorData(enums.SensorType.light, 1))
        print "Light 2: " + str(wanderer.getSensorData(enums.SensorType.light, 2))
        # print
        time.sleep(0.5)