Example #1
0
def start():
    RaveInitialize()

    kitchen_env = os.path.dirname(__file__) + "/resources/kitchen.env.xml"
    env = Environment()  # create the environment
    env.SetViewer('qtcoin')  # start the viewer
    env.Load(kitchen_env)  # load a model

    ssRave = interpeter_extended()
    ssRave.addVariable('kitchen', env)

    ## Example 1: Generate a map from the enitre environment
    expr = "SELECT obj FROM kitchen AS OccupancyGrid ( z_pos=0.22, grid_size=0.025 );"
    print "query:", expr
    prog = SelectScript.compile(expr)
    map = ssRave.eval(prog)

    # plot the map
    plt.imshow(map.astype(numpy.float), cmap=plt.cm.gray)
    plt.show()

    ## Example 2: Generate a map from all objects that are close to roomba
    expr = "roomba = SELECT obj FROM kitchen WHERE id(this)=='roomba_625x' AS value;"
    expr += "SELECT obj FROM kitchen WHERE distance(roomba, this) <= 1.6 AS OccupancyGrid (z_pos=0.22, grid_size=0.025 );"
    print "query:", expr
    prog = SelectScript.compile(expr)
    map = ssRave.eval(prog)

    plt.imshow(map.astype(numpy.float), cmap=plt.cm.gray)
    plt.show()
def start():
    kitchen_env = "resources/kitchen.env.xml"
    env = Environment()  # create the environment
    env.SetViewer('qtcoin')  # start the viewer
    env.Load(kitchen_env)  # load a model

    ssRave = interpeter_extended()
    ssRave.addVariable('kitchen', env)

    ## Example 1: Generate a map from the enitre environment
    expr = """SELECT  above(a.this, b.this), 
                      below(a.this, b.this), 
                      isEnabled(a.this),     
                      volume(a.this),        
                      position(a.this),      
                      isRobot(a.this),       
                      isKinbody(a.this)      
            FROM a=kitchen, b=kitchen      
            WHERE not (isSensor(a.this) or isSensor(b.this)) 
            AS prolog;"""

    print "query:", expr
    prog = SelectScript.compile(expr)
    prolog = Prolog()
    for result in ssRave.eval(prog):
        print result
        prolog.assertz(result)

    print list(prolog.query("above(table, X)"))
    print list(prolog.query("volume(Obj, V), V > 1.0"))
    print list(prolog.query("position(_, P)"))
def start():
    global env
    kitchen_env = os.path.dirname(__file__) + "/resources/kitchen.env.xml"
    env = Environment()  # create the environment
    env.SetViewer('qtcoin')  # start the viewer
    env.Load(kitchen_env)  # load a model

    ssRave = ssRAVE()
    ssRave.addVariable('env', env)
    ssRave.addVariable('kitchen', env)

    robot1 = env.GetRobot('barrett_4918')
    robot2 = env.GetRobot('roomba_625x')

    for sensor in env.GetSensors():
        sensor.Configure(Sensor.ConfigureCommand.PowerOn)
        #sensor.Configure(Sensor.ConfigureCommand.RenderDataOn)

    nav1 = SimpleNavigationPlanning(robot1)
    nav2 = SimpleNavigationPlanning(robot2)

    expr = "measure{5} = select obj(env.this) \
               from env=kitchen, env2=kitchen \
                 where isSensor(env.this) and \
                       isRobot(env2.this) and \
               isSensing(env.this, env2.this) \
               as list; \
               [getTime(), measure{-2}];"

    prog = SelectScript.compile(expr)
    ssRave.addTrigger('test', prog, 0.5, callback)

    start_new_thread(nav1.performNavigationPlanning, ())
    start_new_thread(nav2.performNavigationPlanning, ())
Example #4
0
def start():
    kitchen_env = "resources/kitchen.env.xml"
    env = Environment()  # create the environment
    env.Load(kitchen_env)  # load a model
    #env.SetViewer('qtcoin') # start the viewer

    ssRave = ssRAVE()
    # add the environment as variable to the interpreter
    ssRave.addVariable('kitchen', env)
    # ssRave.addVariable('durability', [5, "Feb", 2014])
    #thread.start_new_thread( switch, (env.GetSensors(),) )

    ## Example 1: Query for information about sensors and robots
    expr = "SELECT id, to(position(this),'pos'), type FROM kitchen WHERE isSensor(this) or isRobot(this) AS dict;"
    print "query 1:", expr, "\nresults:"
    prog = SelectScript.compile(expr)
    for result in ssRave.eval(prog):
        print result

    ## Example 2: Query for the object with id table and store it in a variable
    expr = "table = SELECT obj FROM kitchen WHERE id(this) == 'table' as value;"
    print "\nquery 2:", expr, "\nresult:",
    prog = SelectScript.compile(expr)
    print ssRave.eval(prog)

    ## Example 3: Query for all objects that are on the table and store them in a list
    ssRave.addFunction('on', on)
    expr = "objects_on_table = SELECT obj FROM kitchen WHERE on(table, this) AS list;"
    print "\nquery 3:", expr, "\nresults:"
    prog = SelectScript.compile(expr)
    for result in ssRave.eval(prog):
        print result

    ## Example 4: Query for all objects not on the table
    expr = "SELECT obj FROM kitchen WHERE not on(table, this) or on(table, this) AS list;"
    print "\nquery 4:", expr, "\nresults:"
    prog = SelectScript.compile(expr)
    for result in ssRave.eval(prog):
        print result

    expr = "SELECT volume(this), id FROM kitchen WHERE not on(table, this) or on(table, this) GROUP BY volume(this) AS dict;"
    print "\nquery 5:", expr, "\nresults:"
    prog = SelectScript.compile(expr)
    result = ssRave.eval(prog)
    print result
def start():
    kitchen_env = os.path.dirname(__file__) + "/resources/kitchen.env.xml"
    env = Environment()  # create the environment
    env.SetViewer('qtcoin')  # start the viewer
    env.Load(kitchen_env)  # load a model

    ssRave = ssRAVE()
    ssRave.addVariable('kitchen', env)

    #   sensor_ids = ['barrett_4918_laser_scaner', 'roomba_625x_webcam_a40f', 'roomba_625x_dist1', 'roomba_625x_dist2', 'roomba_625x_dist3', 'roomba_625x_dist4']
    #   for ID in sensor_ids:
    #       env.GetSensor(ID).Configure(Sensor.ConfigureCommand.PowerOn)
    #       env.GetSensor(ID).Configure(Sensor.ConfigureCommand.RenderDataOn)

    ## Example:
    ssRave.addFunction('on', on)
    robot = env.GetRobot("barrett_4918")
    ssRave.addVariable('robot', robot)
    expr = "sink = SELECT obj FROM kitchen WHERE id(this) == 'sink' AS value;"
    expr += "table = SELECT obj FROM kitchen WHERE id(this) == 'table' as value;"
    expr += "cleanUp = SELECT obj FROM kitchen WHERE on(table, this) AND distance(robot, this) < 1.3 AS list;"

    prog = SelectScript.compile(expr)
    print ssRave.eval(prog)

    ## start grasping
    grasp = GraspPlanning(robot)
    grasp.graspables = []
    for object in ssRave.callVariable('cleanUp'):
        destination = grasp.setRandomDestinations([object],
                                                  ssRave.callVariable('sink'),
                                                  randomize=True,
                                                  preserverotation=False)

        gModel = databases.grasping.GraspingModel(robot=robot, target=object)
        if not gModel.load():
            gModel.autogenerate()
        destination = [x.tolist() for x in destination[0]]

        grasp.graspables.append([gModel, destination])

    grasp.performGraspPlanning(withreplacement=True)
def start():
    kitchen_env = "resources/kitchen.env.xml"
    env = Environment()  # create the environment
    #env.SetViewer('qtcoin') # start the viewer
    env.Load(kitchen_env)  # load a model

    ssRaveX = interpeter_extended()
    ssRaveX.addVariable('kitchen', env)

    ## Example 1: Query for information about sensors and robots
    expr = "roomba = SELECT obj FROM kitchen WHERE id(this)=='roomba_625x' AS value;"
    expr += "SELECT obj FROM kitchen WHERE distance(roomba, this) <= 1.6 AS environment;"
    print "query:", expr
    prog = SelectScript.compile(expr)

    newEnv = ssRaveX.eval(prog)

    #env.Reset()
    env = newEnv

    newEnv.SetViewer('qtcoin')  # start the viewer
def callbackPush(output):
    for elem in output:
        [x, y, z] = elem['pos']
        odeBody = elem['obj'].getBody()
        odeBody.addForce(
            (cmp(x, 0) * 4 - x, cmp(y, 0) * 4 - y, cmp(z, 0) * 4 - z))


############################################################

sim = my_ode_sim(0.005, dx=11)

sim.setParam(seed=18,
             gravity=(0, 0, 0),
             bounce=0.3,
             Mu=500,
             minmaxForce=10000,
             probExplode=0.1,
             probInsert=0.5)

sim.ssODE.addFunction('color', color)

expr = """SELECT obj, pos FROM space 
          WHERE color(this)==[1,1,1] AND distance([0,0,0], this) < 4
          AS dict;"""

prog = SelectScript.compile(expr)
sim.addCallback(prog, callbackPush)

sim.start()
####################################################################################
problem1 = """# Basic nested functions iterating over all combinations, not very effective
moves  = [[0,1], [0,2], [1,0], [1,2], [2,0], [2,1]];

SELECT mov1.this, mov2.this, mov3.this, mov4.this, mov5.this, mov6.this, mov7.this
FROM mov1=moves, mov2=moves, mov3=moves, mov4=moves, mov5=moves, mov6=moves, mov7=moves
WHERE [[],[],["c","b","a"]] == move( mov7.this,
                               move( mov6.this,
                                     move( mov5.this,
                                           move( mov4.this,
                                                 move( mov3.this,
                                                       move( mov2.this,
                                                             move( mov1.this, [["c","b","a"],[],[]] )))))))
AS list; """

bytecode = SelectScript.compile(problem1)

t_start = time()
result  = ss.eval(bytecode)
t_end   = time()

print "----------------------------------------------------------------------------"
print problem1
print "----------------------------------------------------------------------------"
print "time:", t_end - t_start
print "result:", result
# time: 10.0932531357
# result: [[0, 2], [0, 1], [2, 1], [0, 2], [1, 0], [1, 2], [0, 2]]
####################################################################################
####################################################################################
problem2 = """# Basic recursive query
Example #9
0
import SelectScript
import SelectScript.Interpreter

ss = SelectScript.Interpreter()

problem = """# if is like in functional programming, and the last statement within
# the then or else-part defines the return value... every part is segregated
# with a semi-colon
b = IF ( 2<3;
         a=1., 2.; # then
         a=2., 1.);# else
a/b;
"""
bytecode = SelectScript.compile(problem)
print "----------------------------------------------------------------------------"
print problem
print "----------------------------------------------------------------------------"
print "result:", ss.eval(bytecode)
# result: 0.5
####################################################################################
####################################################################################
problem = """# the opposite way ...
b = IF ( 2>3;
         a=1., 2.; # then
         a=2., 1.);# else
a/b;
"""
bytecode = SelectScript.compile(problem)
print "----------------------------------------------------------------------------"
print problem
print "----------------------------------------------------------------------------"
             gravity=(0, 0, 0),
             bounce=0.3,
             Mu=500,
             minmaxForce=10000,
             probExplode=0.1,
             probInsert=0.5)

ssODE = ssODE()
ssODE.addVariable('space', sim.space[0])

start_new_thread(sim.start, ())  #

##################################################################
wait(10)
expr = "SELECT id(this, space), mass, velocity FROM space WHERE isSphere(this) AS dict;"
prog = SelectScript.compile(expr)  # generate byte-code
result = ssODE.eval(prog)

print "------------------------------- Example 1 -------------------------------"
print "expr = \"", expr, '"'
print "prog = SelectScript.compile(expr)"
#print prog
print "result = ssODE.eval(prog)"
for result in ssODE.eval(prog):
    print result

##################################################################
wait(10)
expr = "SELECT id(this, space), type, volume FROM space WHERE isSphere(this) AS dict;"
prog = SelectScript.compile(expr)  # generate byte-code