Advanced Simulation

Learn some advanced features of simulation system.

In this tutorial, we are going to introduce some of the advanced features of simulation, including numerical physics system, and introduce human potentials. Let us get started!

Before you begin this tutorial, make sure you finished basic tutorial, since we are going to build on its code.

Numerical physics system

In the last tutorial, we added a physical state called "opened", which is a boolean state. But in reality, many physical states are numerical. For example, speed, luminance, magnetic. In this example, we are going to build around a numerical physics called "pressure".

As always, let us first define an action that can impact the state, an object that can have the state, assign an initial value to it, and add a sensor to it.

Action(name='sit',
       formula='x+hp*0.2',
       physics='pressure',
       hp='weight')
chair1 = myhome.add_object('chair1')
chair1.set_state('pressure', 20)
sensor1 = myhome.add_sensor('c1_p_sensor', 'chair1', rate=0.8, states=['pressure'])

In this case we have a "sit' action that can impact the physical state "pressure", an object called "chair1" that have initial physics state, and a sensor called "sensor1" that can monitoring the state.

Human potential

So what about the "x" and "hp" for in the formula of the action? That is for the human potential. U see, the result of the calculation are no longer a simple value of 0 or 1, it will be calculated based on the previous value, and the human potential "weight". Let us set it up!

jackman.set('weight', 70)

This assign jackman a weight of 70. Later this will be used for calculation for pressure state.

📘

Name of the human potential

In this version you can name your human potential to anything, as long as it is consistent with action. But in the future version, since we will limits the actions, there will only be a set of human potential you can use.

Let us start to play around with jackman. Now we have the ability to impact pressure, we can let jackman sit on the chair1.

jackman.do('sit chair1')

As always, you can get the object and sensor state by "get_state" function:

print 'Pressure after sit: {}'.format(chair1.get_state('pressure'))
print 'Sensor1 pressure: {}'.format(sensor1.get_state('pressure'))