WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-31-2009, 02:55 PM
whj whj is offline
Member
 
Join Date: Apr 2008
Posts: 60
Real-time export data to simulink

Hello,

I'm seeking a solution to output position and orientation data to another computer running Simulink in real time. Does anybody have any experience?

Thanks!
Reply With Quote
  #2  
Old 09-03-2009, 04:48 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Can Simulink read data coming over a network socket? If so, you can use the Python socket module to send data over the network.
Reply With Quote
  #3  
Old 09-04-2009, 09:32 AM
whj whj is offline
Member
 
Join Date: Apr 2008
Posts: 60
I found a UDP Receive block in Simulink. It requires the other end of the communication, which is vizard, to specify the port that receives data. I'm not sure how to do it. I think my code only specifies the port that sends data. Am I missing something?

Code:
import viz
viz.go()

import socket

COMPUTER_IP_ADDRESS = socket.gethostbyname('192.59.88.91')

PORT = 25000 #The port to send data on

OutSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
OutSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

def SendData(data):
	OutSocket.sendto(data,(COMPUTER_IP_ADDRESS,PORT))

vizact.onkeydown(' ',SendData,'hello there')
Thanks!
Reply With Quote
  #4  
Old 09-04-2009, 04:29 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
This post shows how to send and receive data on UDP sockets using different ports.
Reply With Quote
  #5  
Old 09-05-2009, 08:49 PM
whj whj is offline
Member
 
Join Date: Apr 2008
Posts: 60
I'm confused, in the sample code, there is only one port 4999, which is "#The port to send/receive data on". Why does it show using different ports? Thanks.
Reply With Quote
  #6  
Old 09-08-2009, 12:51 PM
whj whj is offline
Member
 
Join Date: Apr 2008
Posts: 60
So far I'm sure simulink on computer B can receive data from specified IP address and port over UDP. Then my question is, how do I specify the port that the remote computer B accepts data from in vizard on this computer A? Thanks.
Reply With Quote
  #7  
Old 09-08-2009, 02:31 PM
whj whj is offline
Member
 
Join Date: Apr 2008
Posts: 60
I just got them communicated successfully. PORT = xxxx seems to be used to specify the remote port to receive from. Please forget my previous question.

My next problem is I would like to send two values from vizard to simulink every 0.05 second. My code would be like this:

Code:
import viz
viz.go()

import socket
import random

COMPUTER_IP_ADDRESS = '129.59.82.229'
PORT = 25000 
OutSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
OutSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

def SendData(data):
	OutSocket.sendto(data,(COMPUTER_IP_ADDRESS,PORT))

def mytimer(num):
	value1 = random.randint(0, 70)
	value2 = random.randint(1, 100)
	SendData(value1, value2)


viz.callback(viz.TIMER_EVENT, mytimer)
viz.starttimer(0,0.05,viz.FOREVER)
I know SendData(value1, value2) wouldn't work. Could somebody tell me how to use SendDate at this context.

Thanks a lot.
Reply With Quote
  #8  
Old 09-09-2009, 12:16 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
When sending data using the socket module, the data needs to be a string containing the raw byte data. Have a look at the Python struct module for packing Python integer/float values into raw byte data. The following example shows how to generate raw byte data from 2 integer values:
Code:
import struct
data = struct.pack('ii',value1,value2)
Reply With Quote
  #9  
Old 09-11-2009, 09:33 AM
whj whj is offline
Member
 
Join Date: Apr 2008
Posts: 60
Thanks a lot. That really helps.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
real time collision on animation path whj Vizard 10 10-06-2008 04:38 PM
Real Time Audio Data lomendil Vizard 2 06-02-2008 08:18 PM
Can I get real time Intersense tracking data from another computer on the network? GoldenSun Vizard 4 04-30-2008 07:42 PM
Flagging the Data Elittdogg Vizard 5 04-11-2008 11:40 AM
timer question Elittdogg Vizard 5 10-10-2007 02:49 PM


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


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