Writing a CSV File

From Mech
Revision as of 22:14, 3 July 2018 by Lynch (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 n joints, then each row has n numbers separated by commas. For example, five rows of a CSV file for a six-joint robot might look like this:


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.


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])
  1. close file




Personal tools