Writing a CSV File

From Mech
Revision as of 23:14, 3 July 2018 by Lynch (talk | contribs) (Created page with "right Several of the V-REP simulation scenes require a comma-separated values (CSV) file as input. A CSV file may represent the trajectory of a robot, w...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Youbot.jpg

Several of the V-REP simulation scenes require a comma-separated values (CSV) file as input. A CSV file may represent the trajectory of a robot, where each row contains the configuration of the robot at an instant in time, with a fixed time between each row. If the robot has joints, then each row has numbers separated by commas. For example, five rows of a CSV file for a six-joint robot might look like this:

2.950000,-1.570000,0.000000,0.000000,0.000000,0.000000
2.987484,-1.540050,0.019967,0.019992,0.012495,0.009996
3.024875,-1.510399,0.039734,0.039933,0.024958,0.019967
3.062079,-1.481344,0.059104,0.059775,0.037360,0.029888
3.099002,-1.453174,0.077884,0.079468,0.049667,0.039734

Below are code snippets in Python, MATLAB, and Mathematica that you can modify to create your own CSV files.

Getting_Started_with_the_V-REP_Simulator'''This page''' contains information on getting started quickly with V-REP. This page contains a number of scenes that accept CSV file inputs for visualization of robot trajectories.

Python

import numpy as np

  1. Generate random 3x4 matrix of floats y, 3x1 vector of ints d

y = np.random.rand(3, 4) d = np.random.randint(-100, 100, 3)

  1. Open a file for output
  2. Overwrite

f = open("output.csv", "w")

  1. Append
  2. f = open("output.csv", "a")
  1. For loop running 3 times to print each csv row

for i in range(len(d)):

   output = " %9.5f, %9.5f, %9.5f, %9.5f, %d\n" % (y[i,0], y[i,1], y[i,2], y[i,3], d[i])
   f.write(output)
   
  1. close file

f.close()

MATLAB

Mathematica