WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Meaning of Errors (https://forum.worldviz.com/showthread.php?t=2208)

jaclyn.bill 08-14-2009 03:16 AM

Meaning of Errors
 
Dear users,

I have a script which appears to be working fine but is throwing up the following error related to my "setting an animation path for passive steering" section in the script below. Is this related to only two points being at the beginning and end points of my animation path? as when I print out these control point locations the error isn't consistent with this and I want to be sure it's dropping frames.

** WARNING: Need at least three control points to calculate tangents
** WARNING: Need at least three control points to calculate tangents


Also, in starting line 71 of this code I want compute the heading angle of the road positioning. Is there a command in vizard similar to the viz.MainView.getEuler which I can use before the viewer sets off down the path, as I want to drop objects on the scene relative to heading (e.g. if they are heading right the object is on their right etc.). My attempts at this manually (commented) have resulted in the error "unsubscriptable object"




Code:

import viz
import math
import viztask
import random
import vizjoy
from numpy import *
import numpy as np
viz.go()


##############################################################################
######## refreshes/ params etc
##############################################################################
REPS = 60.00  ####screen refresh rate
TRIALLENGTH = 16.0 ##### block length
INC = 0.0166 ##### increment (1sec/refresh rate)
SPEED = 8  #####m/s
XVARY= [0.9,1.1]
POINTS = REPS*TRIALLENGTH ####determines detail of sine wave
METERS = TRIALLENGTH*SPEED #### how many meters travelled (linear)
PTOM = POINTS/METERS  #### points to meter ratio
NUM_CONES = 5

####### road parameters
XEXTENT = 5.0 ### furthest extent of road
ZCOORD = linspace(0.0, METERS,POINTS) #### z coords 0 - meters
XCOORD = cos(ZCOORD/18.0)*XEXTENT*sin(ZCOORD/10.0)
YCOORD = [0.25 for y in range(POINTS)] ##### y should be fiexed amount off the ground
positionlist = []
A = random.randint(8*PTOM,11*PTOM)
B = random.randint(16*PTOM,45*PTOM)
C = random.randint(50*PTOM,77*PTOM)
D = random.randint(81*PTOM,108*PTOM)
E = random.randint(113*PTOM,120*PTOM)
YS = 0.25
cones = []

################################################################################
####### viewpoint stuff
################################################################################
viz.clearcolor(viz.SKYBLUE)  ##### sky colour
viz.MainView.getPosition() ###### get potition of main viewpoit
view = viz.get(viz.MAIN_VIEWPOINT)  ##### get position of main viewpoint

##############################################################################
### setttin ground plane
###############################################################################
NUMBER_OF_REPEATS = 100
gravel = viz.add('gravel.jpg',wrap=viz.REPEAT)
ground = viz.add('tut_ground.wrl')
ground.setPosition(0,0,25)
ground.setScale([100,100,100])
ground.collidePlane()
ground.texture(gravel)
ground.texmat( viz.Matrix.scale(NUMBER_OF_REPEATS,NUMBER_OF_REPEATS,1) )
viz.clip(0.1,200)

##########################################################################
##setting an animation path for passive steering
###########################################################################


####################creates the points for the path
def createpath():
        global path,cp,positionlist,x,y,z,XDIFF,ZDIFF,ang
        for i in range(0,POINTS):
                        x=XCOORD[i]; z= ZCOORD[i]; y=YCOORD[i]
                        positions = [x,y,z]
                        positionlist.append(positions)
                       
        for m in range(0,POINTS-1):
                        XDIFF = XCOORD[m+1]- XCOORD[m]
                        ZDIFF = ZCOORD[m+1]- ZCOORD[m]
                        #ang = math.atan(ZDIFF/XDIFF)
                        #heading = ang[m+1]-ang[m]
                        #print heading
                       

createpath()
################# defines the control points and movement through these
def controlpoints():
        global path
        path = viz.add(viz.ANIMATION_PATH)
        for dist in range(0,len(positionlist)):
                cp = viz.add(viz.CONTROL_POINT)
                cp.setPosition(positionlist[dist])
                path.add(cp,dist+1)
                path.constantspeed(viz.ON,SPEED)
                path.loop(viz.OFF)
                path.computetangents()
                path.translatemode(viz.LINEAR)
                path.setAutoRotate(viz.ON)
                viz.link(path, viz.MainView)
controlpoints()

########################### plays the path when space is pressed
def playpath(key):
  if key == ' ':
    path.play()
viz.callback(viz.KEYDOWN_EVENT,playpath)




##############################################################################
###### drop objects on the scene
##############################################################################

pole = viz.add('pole.wrl')
pole.color(1,0,0)
pole.setPosition(positionlist[959])
moveleft = vizact.move(-0.5,-0.25,0,1)
moveright = vizact.move(0.5,-0.25,0,1)

def placecones():
        global cone, pos
        for place in (positionlist[A],positionlist[B],positionlist[C],positionlist[D],positionlist[E]):
                pos = (place)
                cone = viz.add('pole.wrl',cache=viz.CACHE_CLONE,pos=pos)
                cone.color(0,1,0)
                cone.setScale(2,0.05,2)
                cones.append(cone)
                if pos[0]>0:
                        cone.addAction(moveleft)
                if pos[0] <0:
                        cone.addAction(moveright)
               
placecones()
               
       

######################################################################
####movement params with keyboard
#######################################################################

MOVE_SPEED = 7
TURN_SPEED = 30
def steering(num):
       
        if viz.iskeydown(viz.KEY_UP):
                view.move(0,0,MOVE_SPEED*viz.elapsed(),viz.BODY_ORI)
        elif viz.iskeydown(viz.KEY_DOWN):
                view.move(0,0,-MOVE_SPEED*viz.elapsed(),viz.BODY_ORI)
               
        if viz.iskeydown(viz.KEY_RIGHT):
                view.rotate(0,1,0,TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.REL_PARENT)
        elif viz.iskeydown(viz.KEY_LEFT):
                view.rotate(0,1,0,-TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.REL_PARENT)

viz.callback(viz.TIMER_EVENT,steering)
viz.starttimer(0,0.01,viz.FOREVER)

##################################################################################################
######### Running the trials
##################################################################################################







logFile = open ('OBJECTAVOIDENCE_OUTPUT.txt','w')
def Mainviewpos():
        currentTime = viz.tick()
        pos=viz.MainView.getPosition()
        angpos=viz.MainView.getEuler(viz.VIEW_ORI)
        save = ( str(currentTime*1000) + '\t' + str(pos[0])+ '\t' + str(pos[1]) + '\t' + str(pos[2])+ '\t' + str(angpos[0])+ '\n')
        logFile.write(save)
Mainviewpos = vizact.onupdate(0,Mainviewpos)



All times are GMT -7. The time now is 06:29 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC