Skip to content

Commit

Permalink
updated api and all examples passed
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-cavalcanti committed Jun 22, 2024
1 parent 562d6d7 commit 0177732
Show file tree
Hide file tree
Showing 9 changed files with 2,008 additions and 1,799 deletions.
2 changes: 1 addition & 1 deletion examples/get_simulation_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() -> Result<(), RemoteAPIError> {
time = client.sim_get_simulation_time()?;
}

client.sim_stop_simulation()?;
client.sim_stop_simulation(None)?;

Ok(())
}
11 changes: 7 additions & 4 deletions examples/p_controller.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use std::f64::consts::PI;

use coppeliasim_zmq_remote_api::{
sim::Sim, RemoteAPIError, RemoteApiClient, RemoteApiClientParams,
sim::{Sim, self}, RemoteAPIError, RemoteApiClient, RemoteApiClientParams,
};

/*
based on pController.py
# Make sure to have CoppeliaSim running, with following scene loaded:
#
# Make sure to have CoppeliaSim running,
# scenes/messaging/pControllerViaRemoteApi.ttt
#
# Do not launch simulation, but run this script
Expand All @@ -26,6 +25,10 @@ fn main() -> Result<(), RemoteAPIError> {
host: "localhost".to_string(),
..RemoteApiClientParams::default()
})?;
let path = client.sim_get_string_param(sim::STRINGPARAM_SCENEDEFAULTDIR)?;

client.sim_load_scene(format!("{path}/messaging/pControllerViaRemoteApi.ttt"))?;


let joint_handle = client.sim_get_object("/Cuboid[0]/joint".to_string(), None)?;
let mut join_angle = client.sim_get_joint_position(joint_handle)?;
Expand Down Expand Up @@ -73,7 +76,7 @@ fn main() -> Result<(), RemoteAPIError> {
&joint_handle,
)?;

client.sim_stop_simulation()?;
client.sim_stop_simulation(Some(true))?;

println!("Program ended");
Ok(())
Expand Down
3 changes: 3 additions & 0 deletions examples/sim_ik_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ fn main() -> Result<(), RemoteAPIError> {
host: "localhost".to_string(),
..RemoteApiClientParams::default()
})?;
let path = std::env::var("CARGO_MANIFEST_DIR").unwrap();

client.sim_load_scene(format!("{path}/scenes/redundantRobot.ttt"))?;

// Must call require before usint sim_ik functions
client.require(sim::Plugin::SimIK)?;
Expand Down
6 changes: 3 additions & 3 deletions examples/simple_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn main() -> Result<(), RemoteAPIError> {
client.sim_test_cb(10, format!("{fn_cb}@func"), 20)?;
client.sim_test_cb(10, format!("{closure_cb}@func"), 20)?;

client.sim_stop_simulation()?;
client.sim_stop_simulation(Some(false))?;
// if you need to make sure we really stopped:
while client.sim_get_simulation_state()? != sim::SIMULATION_STOPPED {
std::thread::sleep(std::time::Duration::from_secs_f64(0.1))
Expand All @@ -87,10 +87,10 @@ fn main() -> Result<(), RemoteAPIError> {
println!("{}", message);
client.sim_add_log(sim::VERBOSITY_SCRIPTINFOS, message)?;
}
client.sim_stop_simulation()?;
client.sim_stop_simulation(Some(true))?;

//Remove the dummies created earlier:
client.sim_remove_objects(handles)?;
client.sim_remove_objects(handles, None)?;

//Restore the original idle loop frequency:
client.sim_set_int32_param(sim::INTPARAM_IDLE_FPS, default_idle_fps)?;
Expand Down
8 changes: 6 additions & 2 deletions examples/synchronous_image_transmission.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use coppeliasim_zmq_remote_api::{
sim::Sim, RemoteAPIError, RemoteApiClient, RemoteApiClientParams,
sim::{self, Sim}, RemoteAPIError, RemoteApiClient, RemoteApiClientParams,
};

/* Based on synchronousImageTransmission.cpp example
Expand All @@ -21,6 +21,10 @@ fn main() -> Result<(), RemoteAPIError> {
..RemoteApiClientParams::default()
})?;

let path = client.sim_get_string_param(sim::STRINGPARAM_SCENEDEFAULTDIR)?;

client.sim_load_scene(format!("{path}/messaging/synchronousImageTransmissionViaRemoteApi.ttt"))?;

let vision_sensor_handle = client.sim_get_object("/VisionSensor".to_string(), None)?;

let passive_vision_sensor_handle =
Expand All @@ -40,7 +44,7 @@ fn main() -> Result<(), RemoteAPIError> {
client.sim_step()?;
}

client.sim_stop_simulation()?;
client.sim_stop_simulation(Some(false))?;

println!("Program ended");

Expand Down
1,085 changes: 639 additions & 446 deletions src/remote_api_objects/sim/sim_api.rs

Large diffs are not rendered by default.

Loading

0 comments on commit 0177732

Please sign in to comment.