The project I’m learning is using a BNO055 9 axis IMU sensor. As a newbie I’m teaching myself using python and vpython for the first time and took on board some your very helpful previous comments. I used the learning to successfully build 3 bouncing balls in an opaque box representing gas molecules.
I’m now trying to follow the lessons where using vpython you read the values from the sensor to visually manipulate an image representing the physical item(s).
I tried running the FULL code but got errors which I don’t understand, so I broke the program down in places to determine which part of the code generates the error.
Here is my current code:-
from vpython import *
from time import *
import numpy as np
import math
scene.range = 5
toRad = 2*np.pi/360
toDeg = 1/toRad
scene.forward = vector(-1,-1,-1)
scene.width = 600
sceneheight = 600
ArrowX = arrow(size=vector(2,0,0), axis=vector(1,0,0), shaftwidth=0.1, color=color.red)
ArrowY = arrow(size=vector(2,0,0), axis=vector(0,1,0), shaftwidth=0.1, color=color.green)
ArrowZ = arrow(size=vector(2,0,0), axis=vector(0,0,1), shaftwidth=0.1, color=color.blue)
myBoard = box(size=vector(6,0.2,2), pos=vector(0,0,0), opacity=0.5)
BNO055 = box(size=vector(2,0.15,0.6), pos=vector(-2,0.175,0), opacity=0.8, color=color.green)
nanoBoard = box(size=vector(1,0.15,0.8), pos=vector(2,0.175,0), opacity=0.8, color=color.blue)
DevBoard = compound ( [myBoard, BNO055, nanoBoard] )
When I use DevBoard = compound ( [myBoard, BNO055, nanoBoard] )
I get the following error(s) which I’m struggling to understand why after following the code example from (compound — VPython 3.2 documentation)
Task exception was never retrieved
future: <Task finished name='Task-7' coro=<WSserver.onMessage() done, defined at C:\Users\derek\AppData\Local\Programs\Python\Python312\Lib\site-packages\vpython\no_notebook.py:181> exception=TypeError("unsupported operand type(s) for *: 'float' and 'vpython.cyvector.vector'")>
Traceback (most recent call last):
File "C:\Users\derek\AppData\Local\Programs\Python\Python312\Lib\site-packages\vpython\no_notebook.py", line 214, in onMessage
await loop.run_in_executor(None, GW.handle_msg, msg)
File "C:\Users\derek\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\derek\AppData\Local\Programs\Python\Python312\Lib\site-packages\vpython\vpython.py", line 415, in handle_msg
cvs.handle_event(evt)
File "C:\Users\derek\AppData\Local\Programs\Python\Python312\Lib\site-packages\vpython\vpython.py", line 3262, in handle_event
obj._axis.value = obj._size._x*norm(obj._axis)
~~~~~~~~~~~~^~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for *: 'float' and 'vpython.cyvector.vector'
I expected that by using the compound method it would create a single object that can be used in a while true loop to be moved in co-ordination with the sensor readings which is where the lessons are going. But I can’t get past why compound is not working as I expected?
As a newbie I’m not proficient enough yet to fully understand what the error messages mean?
Thank you in advance for any help.