diff --git a/src/ros_joint_state.cpp b/src/ros_joint_state.cpp
index 367fca1c51acdbb8a88810525025de07bbc84430..4837afe8280b4e707c669724abafb6b26c325f93 100644
--- a/src/ros_joint_state.cpp
+++ b/src/ros_joint_state.cpp
@@ -37,12 +37,14 @@ namespace dynamicgraph
 
     namespace {
       void  buildJointNames (sensor_msgs::JointState& jointState, se3::Model* robot_model) {
-	for (int i=0;i<robot_model->nbody-1;i++) {
+	int cnt = 0;
+	for (int i=1;i<robot_model.nbody;i++) {
 	  // Ignore anchors.
 	  if (se3::nv(robot_model->joints[i]) != 0) {
 	    // If we only have one dof, the dof name is the joint name.
 	    if (se3::nv(robot_model->joints[i]) == 1) {
-	      jointState.name[i] =  robot_model->names[i];
+	      jointState.name[cnt] =  robot_model.names[i];
+	      cnt++;
 	    }
 	    else {
 	      // ...otherwise, the dof name is the joint name on which
@@ -52,8 +54,9 @@ namespace dynamicgraph
 		boost::format fmt("%1%_%2%");
 		fmt % robot_model->names[i];
 		fmt % j;
-		jointState.name[i + j] =  fmt.str();
+		jointState.name[cnt + j] =  fmt.str();
 	      }
+	      cnt+=joint_dof;
 	    }
 	  }
 	}