To print out the data every half second we need to setup a continuous timer that will expire every half second.
This creates the timer and registers the function that will be called when it expires. Inside the callback function we simply print out the sensor position using sensor.getPosition().
For orientation tracking sensors, you will need to use sensor.getEuler(), sensor.getAxisAngle(), or sensor.getQuat(), depending on which rotation format you prefer.
If you run the script and your sensor is working, you should see a list of numbers being printed out every half second in the output window.