Skip to content

Commit

Permalink
Aligning voice and text episode indices
Browse files Browse the repository at this point in the history
  • Loading branch information
jackvial committed Dec 25, 2024
1 parent 26a92fa commit 5eefcba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 63 deletions.
6 changes: 3 additions & 3 deletions lerobot/common/robot_devices/control_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _publish_config_update(self):
"play_sounds": self.config.play_sounds,
"assign_rewards": self.config.assign_rewards,
"control_phase": self.config.control_phase,
"num_episodes": self.config.num_episodes,
"num_episodes": self.config.num_episodes - 1,
"current_episode": self.current_episode_index,
}

Expand Down Expand Up @@ -150,7 +150,7 @@ def calculate_window_size(self, images: Dict[str, np.ndarray]):
def draw_top_bar(self, window_width: int):
top_text_str = f"Mode: {self.config.control_phase}"
if self.config.control_phase == ControlPhase.RECORD:
top_text_str += f" | Episode: {self.current_episode_index}/{self.config.num_episodes}"
top_text_str += f" | Episode: {self.current_episode_index}/{self.config.num_episodes - 1}"
if self.config.assign_rewards:
next_reward = self.events["next_reward"]
top_text_str += f" | Reward: {next_reward}"
Expand Down Expand Up @@ -260,7 +260,7 @@ def publish_observations(self, observation: Dict[str, np.ndarray], log_items: li
"play_sounds": self.config.play_sounds,
"assign_rewards": self.config.assign_rewards,
"control_phase": self.config.control_phase,
"num_episodes": self.config.num_episodes,
"num_episodes": self.config.num_episodes - 1,
"current_episode": self.current_episode_index,
}

Expand Down
2 changes: 1 addition & 1 deletion lerobot/scripts/control_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def record(
if has_method(robot, "teleop_safety_stop"):
robot.teleop_safety_stop()

recorded_episodes = 1
recorded_episodes = 0
while True:
if recorded_episodes >= num_episodes:
break
Expand Down
69 changes: 10 additions & 59 deletions lerobot/templates/browser_ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ <h3 class="text-lg font-semibold mb-4 text-gray-700">Logs</h3>
</div>
</div>

<!-- AlpineJS logic -->
<script>
document.addEventListener('alpine:init', () => {
Alpine.data('robotApp', () => ({
Expand All @@ -190,71 +189,34 @@ <h3 class="text-lg font-semibold mb-4 text-gray-700">Logs</h3>
},

initSocket() {
// Connect to Socket.IO server
this.socket = io();

// On connect
this.socket.on('connect', () => {
console.log('Connected to server');
});

// On disconnect
this.socket.on('disconnect', () => {
console.log('Disconnected from server');
this.resetData();
});

// On connect error
this.socket.on('connect_error', (error) => {
console.error('Connection error:', error);
});

// Observation updates
this.socket.on('observation_update', (data) => {
// Update timestamp
if (data.timestamp) {
this.timestamp = `Last Update: ${this.formatTimestamp(data.timestamp)}`;
}
// Update config
if (data.config) {
this.updateConfig(data.config);
}
// Update state
if (data.state) {
this.stateData = data.state;
}
// Update events
if (data.events) {
this.eventsData = data.events;
}
// Update logs
if (data.log_items) {
this.logs = data.log_items;
}
// Update cameras
if (data.images && this.configData.display_cameras) {
this.images = data.images;
}
// Update timers
if (data.countdown_time !== undefined) {
this.countdownTime = data.countdown_time;
}
if (data.timestamp) this.timestamp = `Last Update: ${this.formatTimestamp(data.timestamp)}`;
if (data.config) this.updateConfig(data.config);
if (data.state) this.stateData = data.state;
if (data.events) this.eventsData = data.events;
if (data.log_items) this.logs = data.log_items;
if (data.images && this.configData.display_cameras) this.images = data.images;
if (data.countdown_time !== undefined) this.countdownTime = data.countdown_time;
});

// Dedicated config updates
this.socket.on('config_update', (data) => {
if (data.config) {
this.updateConfig(data.config);
}
if (data.timestamp) {
this.timestamp = `Config Updated: ${this.formatTimestamp(data.timestamp)}`;
}
if (data.countdown_time !== undefined) {
this.countdownTime = data.countdown_time;
}
if (data.config) this.updateConfig(data.config);
if (data.timestamp) this.timestamp = `Config Updated: ${this.formatTimestamp(data.timestamp)}`;
if (data.countdown_time !== undefined) this.countdownTime = data.countdown_time;
});

// Log-say events (TTS)
this.socket.on('log_say', (data) => {
this.speakMessage(data.message);
});
Expand Down Expand Up @@ -282,23 +244,14 @@ <h3 class="text-lg font-semibold mb-4 text-gray-700">Logs</h3>
this.countdownTime = 0;
this.timestamp = '';
},

// Utility: Format timestamp (assuming seconds)
formatTimestamp(tsSeconds) {
return new Date(tsSeconds * 1000).toISOString();
},

// Enable voice (prompt user to allow TTS)
enableVoice() {
console.log('Enable Voice button clicked.');
this.loadVoices().then((voices) => {
console.log('Voices loaded:', voices.map(v => v.name));
// Attempt a short test phrase
this.speakMessage('Voice is now enabled!');
});
},

// Load voices once from the browser
loadVoices() {
return new Promise((resolve) => {
let voices = speechSynthesis.getVoices();
Expand All @@ -312,8 +265,6 @@ <h3 class="text-lg font-semibold mb-4 text-gray-700">Logs</h3>
}
});
},

// Speak a message using speech synthesis
speakMessage(message) {
const utterance = new SpeechSynthesisUtterance(message);
speechSynthesis.speak(utterance);
Expand Down

0 comments on commit 5eefcba

Please sign in to comment.