Usage of hud in vismach?
- ross_dev
- Offline
- Senior Member
Less
More
- Posts: 56
- Thank you received: 2
17 Dec 2019 18:08 - 18 Dec 2019 09:19 #152804
by ross_dev
Usage of hud in vismach? was created by ross_dev
Hi
I have been trying to get the vismach HUD to display updating values, but am drawing a bit of a blank. In vismach.py, in the definition of the hud class, there is a comment:
Creating an object via myhud = Hud() and using myhud.show("example"), I can get the hud to display that text. However I want to stream live data such as joint positions and ultimately, tool number somehow.
Looking at the code for the HUD class, I have tried a few different things in my vismach script unsuccessfully, such as:
as draw() appears to work with the strs array. I tried passing c.joint as this is the HAL component for the x axis. Unfortunately the HUD does not appear with the draw command, only with the show which can only handle a static output.
I also tried:
Which gives a stack overflow.
This all comes before the final call to main, and I have experimented with using hud=myhud or hud=1 as the hud parameter.
Any suggestions on how best to use this function please?
Cheers!
I have been trying to get the vismach HUD to display updating values, but am drawing a bit of a blank. In vismach.py, in the definition of the hud class, there is a comment:
class Hud(object):
'''head up display - draws a semi-transparent text box.
use HUD.strs for things that must be updated constantly,
and HUD.show("stuff") for one-shot things like error messages'''
def __init__(self, showme=1):
self.app = []
self.strs = []
self.messages = []
self.showme = 0
Creating an object via myhud = Hud() and using myhud.show("example"), I can get the hud to display that text. However I want to stream live data such as joint positions and ultimately, tool number somehow.
Looking at the code for the HUD class, I have tried a few different things in my vismach script unsuccessfully, such as:
myhud = Hud()
myhud.strs = [c.joint0]
myhud.draw()
as draw() appears to work with the strs array. I tried passing c.joint as this is the HAL component for the x axis. Unfortunately the HUD does not appear with the draw command, only with the show which can only handle a static output.
I also tried:
myhud.show(myhud.strs)
Which gives a stack overflow.
This all comes before the final call to main, and I have experimented with using hud=myhud or hud=1 as the hud parameter.
Any suggestions on how best to use this function please?
Cheers!
Last edit: 18 Dec 2019 09:19 by ross_dev.
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
Less
More
- Posts: 23162
- Thank you received: 4860
27 Dec 2019 23:01 #153333
by andypugh
Replied by andypugh on topic Usage of hud in vismach?
Is there any indication that the live display is expecting to be associated with a HAL pin, like the joint positions are?
Please Log in or Create an account to join the conversation.
- ross_dev
- Offline
- Senior Member
Less
More
- Posts: 56
- Thank you received: 2
10 Jan 2020 11:03 #154535
by ross_dev
Replied by ross_dev on topic Usage of hud in vismach?
Hi Andy
I will check - I have kind of shelved this aspect of things for now as it was more of a "nice to have"!
Cheers
Ross
I will check - I have kind of shelved this aspect of things for now as it was more of a "nice to have"!
Cheers
Ross
Please Log in or Create an account to join the conversation.
- udoS
- Offline
- Elite Member
Less
More
- Posts: 216
- Thank you received: 25
16 Apr 2021 08:19 - 16 Apr 2021 08:20 #206091
by udoS
Replied by udoS on topic Usage of hud in vismach?
Hi Andy / ross_dev
there any new information on the vismach.
Because as soon as I try to start the hud, the vismach is not starting any more.
can someone help with that.
Best Regards
there any new information on the vismach.
Because as soon as I try to start the hud, the vismach is not starting any more.
can someone help with that.
Best Regards
Last edit: 16 Apr 2021 08:20 by udoS.
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
Less
More
- Posts: 23162
- Thank you received: 4860
16 Apr 2021 08:27 #206092
by andypugh
Replied by andypugh on topic Usage of hud in vismach?
I don't have the answer, but any info learned I will put in the (scant) Vismach docs.
Please Log in or Create an account to join the conversation.
- udoS
- Offline
- Elite Member
Less
More
- Posts: 216
- Thank you received: 25
02 Sep 2021 06:30 #219408
by udoS
Replied by udoS on topic Usage of hud in vismach?
@ross_dev
Hi ross_dev,
is there any new docu or information on how to get the HUD working.
Best rgds
Hi ross_dev,
is there any new docu or information on how to get the HUD working.
Best rgds
Please Log in or Create an account to join the conversation.
- Aciera
- Offline
- Administrator
Less
More
- Posts: 4003
- Thank you received: 1730
08 Jan 2023 13:47 - 08 Jan 2023 14:13 #261262
by Aciera
Replied by Aciera on topic Usage of hud in vismach?
I've been playing around with vismach lately and wanted the hud to display updated axis values. I have modified the 'Hud(object)' class to create a new class 'HalHud(object)' which lets me pass any number of pins to the hud from my vismach script like this:
# start hud
myhud = HalHud(c, ['axis-x: ' ,'axis-y: ', 'axis-z: '], ["{:10.4f}","{:10.4f}","{:10.4f}"], ["axis_x", "axis_y", "axis_z"])
myhud.show_top("XYZABC-TRSRN")
myhud.show_top("------------")
myhud.show("-------------")
myhud.show("The End")
# end hud
class HalHud(object):
'''head up display - draws a semi-transparent text box.
use HUD.strs for things that must be updated constantly,
and HUD.show("stuff") for one-shot things like error messages'''
def __init__(self, comp, strings, formats, var):
self.showme = 0
self.app =
self.strs =
self.messages =
self.messages_top =
self.fontbase =
self.comp = comp
self.strings = strings
self.formats = formats
self.var = var
def show_top(self, string):
self.showme = 1
self.messages_top += [str(string)]
def show(self, string):
self.showme = 1
self.messages += [str(string)]
def hide(self):
self.showme = 0
def clear(self):
self.messages =
def draw(self):
self.strs =
# create the strings with the updated values using the corresponding list elements
for n in range(len(self.strings)):
self.strs += [self.strings[n] + str(self.formats[n].format(self.comp[self.var[n]]))]
drawtext = self.messages_top + self.strs + self.messages
self.lines = len(drawtext)
#draw head-up-display
#see axis.py for more font/color configurability
if ((self.showme == 0) or (self.lines == 0)):
return
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
if not self.fontbase:
self.fontbase = int(self.app.loadbitmapfont("9x15"))
char_width, char_height = 9, 15
xmargin,ymargin = 5,5
ypos = float(self.app.winfo_height())
glOrtho(0.0, self.app.winfo_width(), 0.0, ypos, -1.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
#draw the text box
maxlen = max([len(p) for p in drawtext])
box_width = maxlen * char_width
glDepthFunc(GL_ALWAYS)
glDepthMask(GL_FALSE)
glDisable(GL_LIGHTING)
glEnable(GL_BLEND)
glEnable(GL_NORMALIZE)
glBlendFunc(GL_ONE, GL_CONSTANT_ALPHA)
glColor3f(0,0.2,0) # sets the color of the hud overlay
glBlendColor(0,0,0,0.5) #rgba, sets the transparency of the overlay using the 'a' value
glBegin(GL_QUADS)
glVertex3f(0, ypos, 1) #upper left
glVertex3f(0, ypos - 2*ymargin - char_height*len(drawtext), 1) #lower left
glVertex3f(box_width+2*xmargin, ypos - 2*ymargin - char_height*len(drawtext), 1) #lower right
glVertex3f(box_width+2*xmargin, ypos , 1) #upper right
glEnd()
glDisable(GL_BLEND)
glEnable(GL_LIGHTING)
#fill the box with text
maxlen = 0
ypos -= char_height+ymargin
i=0
glDisable(GL_LIGHTING)
glColor3f(0.9,0.9,0.0) # sets the color of the text in the hud
for string in drawtext:
maxlen = max(maxlen, len(string))
glRasterPos2i(xmargin, int(ypos))
for char in string:
glCallList(self.fontbase + ord(char))
ypos -= char_height
i = i + 1
glDepthFunc(GL_LESS)
glDepthMask(GL_TRUE)
glEnable(GL_LIGHTING)
glPopMatrix()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
Attachments:
Last edit: 08 Jan 2023 14:13 by Aciera. Reason: This editor is KILLING me
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
Less
More
- Posts: 7777
- Thank you received: 2073
10 Jan 2023 02:54 #261414
by cmorley
Replied by cmorley on topic Usage of hud in vismach?
I added this to qt_vismach in 2.9 and master.
I used slightly different code to set the HAL pin lines.
Very nice thank you.
I used slightly different code to set the HAL pin lines.
Very nice thank you.
The following user(s) said Thank You: Aciera
Please Log in or Create an account to join the conversation.
- Aciera
- Offline
- Administrator
Less
More
- Posts: 4003
- Thank you received: 1730
10 Jan 2023 16:22 - 10 Jan 2023 16:27 #261465
by Aciera
Replied by Aciera on topic Usage of hud in vismach?
I guess what I should have done is use optional arguments in the existing class instead of creating another one. This should also work with any existing code:
class Hud(object):
'''head up display - draws a semi-transparent text box.
use HUD.strs for things that must be updated constantly,
and HUD.show("stuff") for one-shot things like error messages'''
# for updating pin values use the optional argument lists. Display will be:
# 'strings[0]' var[0] formated by formats[0]]
# 'strings[1]' var[1] formated by formats[1]]
# and so on
# Example:
# Hud(c,["Axis-X: ", "Axis-Y: "], ["{:8.3f}","{:8.3f}"], ["halpin_pos_x", "halpin_pos_y"])
# for static messages to be displayed before the updating values use Hud.show_top("your_string_here")
# for static messages to be displayed after the updating values use Hud.show("your_string_here")
def __init__(self, comp=None, strings=, formats=, var=):
self.showme = 0
self.app =
self.strs =
self.messages =
self.messages_top =
self.fontbase =
self.comp = comp
self.strings = strings
self.formats = formats
self.var = var
def show_top(self, string):
self.showme = 1
self.messages_top += [str(string)]
def show(self, string):
self.showme = 1
self.messages += [str(string)]
def hide(self):
self.showme = 0
def clear(self):
self.messages =
def draw(self):
self.strs =
# create the strings with the updated values using the corresponding list elements
for n in range(len(self.strings)):
self.strs += [self.strings[n] + str(self.formats[n].format(self.comp[self.var[n]]))]
drawtext = self.messages_top + self.strs + self.messages
self.lines = len(drawtext)
#draw head-up-display
#see axis.py for more font/color configurability
if ((self.showme == 0) or (self.lines == 0)):
return
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
if not self.fontbase:
self.fontbase = int(self.app.loadbitmapfont("9x15"))
char_width, char_height = 9, 15
xmargin,ymargin = 5,5
ypos = float(self.app.winfo_height())
glOrtho(0.0, self.app.winfo_width(), 0.0, ypos, -1.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
#draw the text box
maxlen = max([len(p) for p in drawtext])
box_width = maxlen * char_width
glDepthFunc(GL_ALWAYS)
glDepthMask(GL_FALSE)
glDisable(GL_LIGHTING)
glEnable(GL_BLEND)
glEnable(GL_NORMALIZE)
glBlendFunc(GL_ONE, GL_CONSTANT_ALPHA)
glColor3f(0,0.2,0) # sets the color of the hud overlay
glBlendColor(0,0,0,0.5) #rgba, sets the transparency of the overlay using the 'a' value
glBegin(GL_QUADS)
glVertex3f(0, ypos, 1) #upper left
glVertex3f(0, ypos - 2*ymargin - char_height*len(drawtext), 1) #lower left
glVertex3f(box_width+2*xmargin, ypos - 2*ymargin - char_height*len(drawtext), 1) #lower right
glVertex3f(box_width+2*xmargin, ypos , 1) #upper right
glEnd()
glDisable(GL_BLEND)
glEnable(GL_LIGHTING)
#fill the box with text
maxlen = 0
ypos -= char_height+ymargin
i=0
glDisable(GL_LIGHTING)
glColor3f(1,0.8,0.4) # sets the color of the text in the hud
for string in drawtext:
maxlen = max(maxlen, len(string))
glRasterPos2i(xmargin, int(ypos))
for char in string:
glCallList(self.fontbase + ord(char))
ypos -= char_height
i = i + 1
glDepthFunc(GL_LESS)
glDepthMask(GL_TRUE)
glEnable(GL_LIGHTING)
glPopMatrix()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
Last edit: 10 Jan 2023 16:27 by Aciera. Reason: typo
Please Log in or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
Less
More
- Posts: 7777
- Thank you received: 2073
10 Jan 2023 19:31 - 10 Jan 2023 19:32 #261485
by cmorley
Replied by cmorley on topic Usage of hud in vismach?
(I don't know if you noticed put posting it seems to strip some of the brackets [] from the code.)
I added a function:
def add_pin(self, text, form, pinname):
rather then define the strings at initialization time.
And made the code be able to read any HAL pin rather then just the component pin.
It is a great idea thank you!
I added a function:
def add_pin(self, text, form, pinname):
rather then define the strings at initialization time.
And made the code be able to read any HAL pin rather then just the component pin.
It is a great idea thank you!
Last edit: 10 Jan 2023 19:32 by cmorley.
Please Log in or Create an account to join the conversation.
Time to create page: 0.084 seconds