feat: copy webots controller lib sources from webots upstream

This commit is contained in:
insleker 2026-05-20 19:11:32 +08:00
parent 3db9ec8572
commit c4e52d7e52
214 changed files with 30182 additions and 0 deletions

0
CMakeLists.txt Normal file
View File

0
conanfile.py Normal file
View File

View File

@ -0,0 +1,45 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Accelerometer node */
/**********************************************************************************/
#ifndef WB_ACCELEROMETER_H
#define WB_ACCELEROMETER_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_accelerometer_enable(WbDeviceTag tag, int sampling_period);
void wb_accelerometer_disable(WbDeviceTag tag);
int wb_accelerometer_get_sampling_period(WbDeviceTag tag);
int wb_accelerometer_get_lookup_table_size(WbDeviceTag tag);
const double *wb_accelerometer_get_lookup_table(WbDeviceTag tag);
// return a pointer to an array of 3 double for X, Y and Z accelerations
const double *wb_accelerometer_get_values(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_ACCELEROMETER_H */

View File

@ -0,0 +1,41 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Altimeter node */
/**********************************************************************************/
#ifndef WB_ALTIMETER_H
#define WB_ALTIMETER_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_altimeter_enable(WbDeviceTag tag, int sampling_period);
void wb_altimeter_disable(WbDeviceTag tag);
int wb_altimeter_get_sampling_period(WbDeviceTag tag);
double wb_altimeter_get_value(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_ALTIMETER_H */

View File

@ -0,0 +1,44 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the brake node */
/**********************************************************************************/
#ifndef WB_BRAKE_H
#define WB_BRAKE_H
#define WB_USING_C_API
#include "types.h"
#ifndef WB_MATLAB_LOADLIBRARY
#include <math.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
void wb_brake_set_damping_constant(WbDeviceTag tag, double damping_constant);
WbJointType wb_brake_get_type(WbDeviceTag tag);
WbDeviceTag wb_brake_get_motor(WbDeviceTag tag);
WbDeviceTag wb_brake_get_position_sensor(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_BRAKE_H */

View File

@ -0,0 +1,104 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Camera node */
/**********************************************************************************/
#ifndef WB_CAMERA_H
#define WB_CAMERA_H
#define WB_USING_C_API
#include "camera_recognition_object.h"
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_camera_enable(WbDeviceTag tag, int sampling_period);
void wb_camera_disable(WbDeviceTag tag);
int wb_camera_get_sampling_period(WbDeviceTag tag);
const unsigned char *wb_camera_get_image(WbDeviceTag tag);
int wb_camera_get_width(WbDeviceTag tag);
int wb_camera_get_height(WbDeviceTag tag);
double wb_camera_get_fov(WbDeviceTag tag);
double wb_camera_get_max_fov(WbDeviceTag tag);
double wb_camera_get_min_fov(WbDeviceTag tag);
void wb_camera_set_fov(WbDeviceTag tag, double fov); // fov specified in rad
double wb_camera_get_exposure(WbDeviceTag tag);
void wb_camera_set_exposure(WbDeviceTag tag, double exposure);
double wb_camera_get_focal_length(WbDeviceTag tag);
double wb_camera_get_focal_distance(WbDeviceTag tag);
double wb_camera_get_max_focal_distance(WbDeviceTag tag);
double wb_camera_get_min_focal_distance(WbDeviceTag tag);
void wb_camera_set_focal_distance(WbDeviceTag tag, double focal_distance);
double wb_camera_get_near(WbDeviceTag tag);
int wb_camera_save_image(WbDeviceTag tag, const char *filename, int quality);
// smart camera
bool wb_camera_has_recognition(WbDeviceTag tag);
void wb_camera_recognition_enable(WbDeviceTag tag, int sampling_period);
void wb_camera_recognition_disable(WbDeviceTag tag);
int wb_camera_recognition_get_sampling_period(WbDeviceTag tag);
int wb_camera_recognition_get_number_of_objects(WbDeviceTag tag);
const WbCameraRecognitionObject *wb_camera_recognition_get_objects(WbDeviceTag tag);
bool wb_camera_recognition_has_segmentation(WbDeviceTag tag);
void wb_camera_recognition_enable_segmentation(WbDeviceTag tag);
void wb_camera_recognition_disable_segmentation(WbDeviceTag tag);
bool wb_camera_recognition_is_segmentation_enabled(WbDeviceTag tag);
const unsigned char *wb_camera_recognition_get_segmentation_image(WbDeviceTag tag);
int wb_camera_recognition_save_segmentation_image(WbDeviceTag tag, const char *filename, int quality);
#ifdef WB_MATLAB_LOADLIBRARY
// This function should be used only in the Matlab wrapper
const WbCameraRecognitionObject *wb_camera_recognition_get_object(WbDeviceTag tag, int index);
#endif
/* useful macros to get pixel colors from the image data, width and coords *
*
* ^ y
* | (height)
* |===============
* |=============== *: pixel@(x,y)
* |---------*=====
* |=========|===== (width)
* |=========|=====
* |=========|=====
* |=========|=====
* -+-----------------> x
* o|
*/
#define wb_camera_image_get_red(image, width, x, y) (image[4 * ((y) * (width) + (x)) + 2])
#define wb_camera_image_get_green(image, width, x, y) (image[4 * ((y) * (width) + (x)) + 1])
#define wb_camera_image_get_blue(image, width, x, y) (image[4 * ((y) * (width) + (x))])
#ifdef KROS_COMPILATION
#define wb_camera_image_get_gray(image, width, x, y) (image[(y) * (width) + (x)])
#else
#define wb_camera_image_get_gray(image, w, x, y) \
((image[4 * ((y) * (w) + (x)) + 2] + image[4 * ((y) * (w) + (x)) + 1] + image[4 * ((y) * (w) + (x))]) / 3)
#endif
// alias
#define wb_camera_image_get_grey(image, width, x, y) wb_camera_image_get_gray(image, width, x, y)
#ifdef __cplusplus
}
#endif
#endif /* WB_CAMERA_H */

View File

@ -0,0 +1,36 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/***************************************************************************************************/
/* Description: Common definition of the 'WbCameraRecognitionObject' for both the C and C++ APIs */
/**************************************************************************************************/
#ifndef WB_CAMERA_RECOGNITION_OBJECT_H
#define WB_CAMERA_RECOGNITION_OBJECT_H
typedef struct {
int id;
double position[3];
double orientation[4];
double size[2];
int position_on_image[2];
int size_on_image[2];
int number_of_colors;
double *colors;
char *model;
} WbCameraRecognitionObject;
#endif /* WB_CAMERA_RECOGNITION_OBJECT_H */

View File

@ -0,0 +1,44 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Compass node */
/**********************************************************************************/
#ifndef WB_COMPASS_H
#define WB_COMPASS_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_compass_enable(WbDeviceTag tag, int sampling_period);
void wb_compass_disable(WbDeviceTag tag);
int wb_compass_get_sampling_period(WbDeviceTag tag);
int wb_compass_get_lookup_table_size(WbDeviceTag tag);
const double *wb_compass_get_lookup_table(WbDeviceTag tag);
const double *wb_compass_get_values(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_COMPASS_H */

View File

@ -0,0 +1,43 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Connector node */
/**********************************************************************************/
#ifndef WB_CONNECTOR_H
#define WB_CONNECTOR_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_connector_enable_presence(WbDeviceTag tag, int sampling_period);
void wb_connector_disable_presence(WbDeviceTag tag);
int wb_connector_get_presence_sampling_period(WbDeviceTag tag);
int wb_connector_get_presence(WbDeviceTag tag);
void wb_connector_lock(WbDeviceTag tag);
void wb_connector_unlock(WbDeviceTag tag);
bool wb_connector_is_locked(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_CONNECTOR_H */

View File

@ -0,0 +1,36 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WB_CONSOLE_H
#define WB_CONSOLE_H
#define WB_USING_C_API
#ifdef __cplusplus
extern "C" {
#endif
#define WB_STDOUT 1
#define WB_STDERR 2
// this function is for an internal purpose, please use regular stdout/stderr functions instead
void wb_console_print(const char *text, int stream);
#ifdef __cplusplus
}
#endif
#endif /* WB_CONSOLE_H */

View File

@ -0,0 +1,26 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WB_CONTACT_POINTS_H
#define WB_CONTACT_POINTS_H
typedef struct {
double point[3];
int node_id;
int padding; // this padding is anyhow added by the compiler, we make it explicit here
} WbContactPoint;
#endif

View File

@ -0,0 +1,43 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Abstraction of a robot device */
/**********************************************************************************/
#ifndef WB_DEVICE_H
#define WB_DEVICE_H
#define WB_USING_C_API
#include "nodes.h"
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
const char *wb_device_get_name(WbDeviceTag dt);
const char *wb_device_get_model(WbDeviceTag dt);
WbNodeType wb_device_get_node_type(WbDeviceTag dt);
// deprecated since Webots 8.0.0, please use wb_device_get_node_type() instead
WbNodeType wb_device_get_type(WbDeviceTag dt) WB_DEPRECATED;
#ifdef __cplusplus
}
#endif
#endif /* WB_DEVICE_H */

View File

@ -0,0 +1,72 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Display node */
/**********************************************************************************/
#ifndef WB_DISPLAY_H
#define WB_DISPLAY_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
int wb_display_get_width(WbDeviceTag tag);
int wb_display_get_height(WbDeviceTag tag);
// drawing properties
void wb_display_set_color(WbDeviceTag tag, int color);
void wb_display_set_alpha(WbDeviceTag tag, double alpha);
void wb_display_set_opacity(WbDeviceTag tag, double opacity);
void wb_display_set_font(WbDeviceTag tag, const char *font, int size, bool anti_aliasing);
void wb_display_attach_camera(WbDeviceTag tag, WbDeviceTag camera_tag);
void wb_display_detach_camera(WbDeviceTag tag);
// draw primitive
void wb_display_draw_pixel(WbDeviceTag tag, int x, int y);
void wb_display_draw_line(WbDeviceTag tag, int x1, int y1, int x2, int y2);
void wb_display_draw_rectangle(WbDeviceTag tag, int x, int y, int width, int height);
void wb_display_draw_oval(WbDeviceTag tag, int cx, int cy, int a, int b);
void wb_display_draw_polygon(WbDeviceTag tag, const int *x, const int *y, int size);
void wb_display_draw_text(WbDeviceTag tag, const char *text, int x, int y);
void wb_display_fill_rectangle(WbDeviceTag tag, int x, int y, int width, int height);
void wb_display_fill_oval(WbDeviceTag tag, int cx, int cy, int a, int b);
void wb_display_fill_polygon(WbDeviceTag tag, const int *x, const int *y, int size);
// WbImageRef handle functions
#define WB_IMAGE_RGB 3
#define WB_IMAGE_RGBA 4
#define WB_IMAGE_ARGB 5
#define WB_IMAGE_BGRA 6
#define WB_IMAGE_ABGR 7
WbImageRef wb_display_image_new(WbDeviceTag tag, int width, int height, const void *data, int format);
WbImageRef wb_display_image_copy(WbDeviceTag tag, int x, int y, int width, int height);
WbImageRef wb_display_image_load(WbDeviceTag tag, const char *filename);
void wb_display_image_delete(WbDeviceTag tag, WbImageRef ir);
void wb_display_image_paste(WbDeviceTag tag, WbImageRef ir, int x, int y, bool blend);
void wb_display_image_save(WbDeviceTag tag, WbImageRef ir, const char *filename);
#ifdef __cplusplus
}
#endif
#endif /* WB_DISPLAY_H */

View File

@ -0,0 +1,56 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the DistanceSensor node */
/**********************************************************************************/
#ifndef WB_DISTANCE_SENSOR_H
#define WB_DISTANCE_SENSOR_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_distance_sensor_enable(WbDeviceTag tag, int sampling_period);
void wb_distance_sensor_disable(WbDeviceTag tag);
int wb_distance_sensor_get_sampling_period(WbDeviceTag tag);
double wb_distance_sensor_get_value(WbDeviceTag tag);
double wb_distance_sensor_get_max_value(WbDeviceTag tag);
double wb_distance_sensor_get_min_value(WbDeviceTag tag);
double wb_distance_sensor_get_aperture(WbDeviceTag tag);
int wb_distance_sensor_get_lookup_table_size(WbDeviceTag tag);
const double *wb_distance_sensor_get_lookup_table(WbDeviceTag tag);
typedef enum {
WB_DISTANCE_SENSOR_GENERIC = 0,
WB_DISTANCE_SENSOR_INFRA_RED,
WB_DISTANCE_SENSOR_SONAR,
WB_DISTANCE_SENSOR_LASER
} WbDistanceSensorType;
WbDistanceSensorType wb_distance_sensor_get_type(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_DISTANCE_SENSOR_H */

View File

@ -0,0 +1,46 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Emitter node */
/**********************************************************************************/
#ifndef WB_EMITTER_H
#define WB_EMITTER_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef WB_CHANNEL_BROADCAST
#define WB_CHANNEL_BROADCAST -1
#endif
int wb_emitter_send(WbDeviceTag tag, const void *data, int size);
int wb_emitter_get_buffer_size(WbDeviceTag tag);
void wb_emitter_set_channel(WbDeviceTag tag, int channel);
int wb_emitter_get_channel(WbDeviceTag tag);
double wb_emitter_get_range(WbDeviceTag tag);
void wb_emitter_set_range(WbDeviceTag tag, double range);
#ifdef __cplusplus
}
#endif
#endif /* WB_EMITTER_H */

View File

@ -0,0 +1,49 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the GPS node */
/**********************************************************************************/
#ifndef WB_GPS_H
#define WB_GPS_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_gps_enable(WbDeviceTag tag, int sampling_period);
void wb_gps_disable(WbDeviceTag tag);
int wb_gps_get_sampling_period(WbDeviceTag tag);
double wb_gps_get_speed(WbDeviceTag tag);
const double *wb_gps_get_speed_vector(WbDeviceTag tag);
const double *wb_gps_get_values(WbDeviceTag tag);
const char *wb_gps_convert_to_degrees_minutes_seconds(double decimal_degrees);
typedef enum { WB_GPS_LOCAL_COORDINATE = 0, WB_GPS_WGS84_COORDINATE } WbGpsCoordinateSystem;
WbGpsCoordinateSystem wb_gps_get_coordinate_system(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_GPS_H */

View File

@ -0,0 +1,44 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Gyro node */
/**********************************************************************************/
#ifndef WB_GYRO_H
#define WB_GYRO_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_gyro_enable(WbDeviceTag tag, int sampling_period);
void wb_gyro_disable(WbDeviceTag tag);
int wb_gyro_get_sampling_period(WbDeviceTag tag);
int wb_gyro_get_lookup_table_size(WbDeviceTag tag);
const double *wb_gyro_get_lookup_table(WbDeviceTag tag);
const double *wb_gyro_get_values(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_GYRO_H */

View File

@ -0,0 +1,44 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the InertialUnit node */
/**********************************************************************************/
#ifndef WB_INERTIAL_UNIT_H
#define WB_INERTIAL_UNIT_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_inertial_unit_enable(WbDeviceTag tag, int sampling_period);
void wb_inertial_unit_disable(WbDeviceTag tag);
int wb_inertial_unit_get_sampling_period(WbDeviceTag tag);
double wb_inertial_unit_get_noise(WbDeviceTag tag);
const double *wb_inertial_unit_get_roll_pitch_yaw(WbDeviceTag tag);
const double *wb_inertial_unit_get_quaternion(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_INERTIAL_UNIT_H */

View File

@ -0,0 +1,57 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the computer joystick */
/**********************************************************************************/
#ifndef WB_JOYSTICK_H
#define WB_JOYSTICK_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_joystick_enable(int sampling_period);
void wb_joystick_disable();
int wb_joystick_get_sampling_period();
bool wb_joystick_is_connected();
const char *wb_joystick_get_model();
int wb_joystick_get_number_of_axes();
int wb_joystick_get_axis_value(int axis);
int wb_joystick_get_number_of_povs();
int wb_joystick_get_pov_value(int pov);
int wb_joystick_get_pressed_button();
// force-feedback
void wb_joystick_set_constant_force(int level);
void wb_joystick_set_constant_force_duration(double duration);
void wb_joystick_set_auto_centering_gain(double gain);
void wb_joystick_set_resistance_gain(double gain);
void wb_joystick_set_force_axis(int axis);
#ifdef __cplusplus
}
#endif
#endif /* WB_JOYSTICK_H */

View File

@ -0,0 +1,61 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the computer keyboard */
/**********************************************************************************/
#ifndef WB_KEYBOARD_H
#define WB_KEYBOARD_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
WB_KEYBOARD_END = 312,
WB_KEYBOARD_HOME,
WB_KEYBOARD_LEFT,
WB_KEYBOARD_UP,
WB_KEYBOARD_RIGHT,
WB_KEYBOARD_DOWN,
WB_KEYBOARD_PAGEUP = 366,
WB_KEYBOARD_PAGEDOWN,
WB_KEYBOARD_NUMPAD_HOME = 375,
WB_KEYBOARD_NUMPAD_LEFT,
WB_KEYBOARD_NUMPAD_UP,
WB_KEYBOARD_NUMPAD_RIGHT,
WB_KEYBOARD_NUMPAD_DOWN,
WB_KEYBOARD_NUMPAD_END = 382,
WB_KEYBOARD_KEY = 0x0000ffff,
WB_KEYBOARD_SHIFT = 0x00010000,
WB_KEYBOARD_CONTROL = 0x00020000,
WB_KEYBOARD_ALT = 0x00040000
};
void wb_keyboard_enable(int sampling_period);
void wb_keyboard_disable();
int wb_keyboard_get_sampling_period();
int wb_keyboard_get_key();
#ifdef __cplusplus
}
#endif
#endif /* WB_KEYBOARD_H */

View File

@ -0,0 +1,38 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the LED node */
/**********************************************************************************/
#ifndef WB_LED_H
#define WB_LED_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_led_set(WbDeviceTag tag, int value); // 0 for off, 1, 2, etc. for on with a color
int wb_led_get(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_LED_H */

View File

@ -0,0 +1,66 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Lidar node */
/**********************************************************************************/
#ifndef WB_LIDAR_H
#define WB_LIDAR_H
#define WB_USING_C_API
#include "lidar_point.h"
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_lidar_enable(WbDeviceTag tag, int sampling_period);
void wb_lidar_enable_point_cloud(WbDeviceTag tag);
void wb_lidar_disable(WbDeviceTag tag);
void wb_lidar_disable_point_cloud(WbDeviceTag tag);
int wb_lidar_get_sampling_period(WbDeviceTag tag);
bool wb_lidar_is_point_cloud_enabled(WbDeviceTag tag);
const float *wb_lidar_get_range_image(WbDeviceTag tag);
const float *wb_lidar_get_layer_range_image(WbDeviceTag tag, int layer);
const WbLidarPoint *wb_lidar_get_point_cloud(WbDeviceTag tag);
const WbLidarPoint *wb_lidar_get_layer_point_cloud(WbDeviceTag tag, int layer);
int wb_lidar_get_number_of_points(WbDeviceTag tag);
int wb_lidar_get_horizontal_resolution(WbDeviceTag tag);
int wb_lidar_get_number_of_layers(WbDeviceTag tag);
double wb_lidar_get_min_frequency(WbDeviceTag tag);
double wb_lidar_get_max_frequency(WbDeviceTag tag);
double wb_lidar_get_frequency(WbDeviceTag tag);
void wb_lidar_set_frequency(WbDeviceTag tag, double frequency);
double wb_lidar_get_fov(WbDeviceTag tag);
double wb_lidar_get_vertical_fov(WbDeviceTag tag);
double wb_lidar_get_min_range(WbDeviceTag tag);
double wb_lidar_get_max_range(WbDeviceTag tag);
#ifdef WB_MATLAB_LOADLIBRARY
// This function should be used only in the Matlab wrapper
const WbLidarPoint *wb_lidar_get_point(WbDeviceTag tag, int index);
#endif
#ifdef __cplusplus
}
#endif
#endif /* WB_LIDAR_H */

View File

@ -0,0 +1,32 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*************************************************************************************/
/* Description: Common definition of the 'WbLidarPoint' for both the C and C++ APIs */
/*************************************************************************************/
#ifndef WB_LIDAR_POINT_H
#define WB_LIDAR_POINT_H
typedef struct {
float x;
float y;
float z;
int layer_id;
float time;
} WbLidarPoint;
#endif /* WB_LIDAR_POINT_H */

View File

@ -0,0 +1,44 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the LightSensor node */
/**********************************************************************************/
#ifndef WB_LIGHT_SENSOR_H
#define WB_LIGHT_SENSOR_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_light_sensor_enable(WbDeviceTag tag, int sampling_period);
void wb_light_sensor_disable(WbDeviceTag tag);
int wb_light_sensor_get_sampling_period(WbDeviceTag tag);
int wb_light_sensor_get_lookup_table_size(WbDeviceTag tag);
const double *wb_light_sensor_get_lookup_table(WbDeviceTag tag);
double wb_light_sensor_get_value(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_LIGHT_SENSOR_H */

View File

@ -0,0 +1,44 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Microphone node */
/**********************************************************************************/
#ifndef WB_MICROPHONE_H
#define WB_MICROPHONE_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
// device functions
void wb_microphone_enable(WbDeviceTag tag, int sampling_period);
void wb_microphone_disable(WbDeviceTag tag);
int wb_microphone_get_sampling_period(WbDeviceTag tag);
// data packet functions
const void *wb_microphone_get_sample_data(WbDeviceTag tag);
int wb_microphone_get_sample_size(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_MICROPHONE_H */

View File

@ -0,0 +1,75 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Motor node */
/**********************************************************************************/
#ifndef WB_MOTOR_H
#define WB_MOTOR_H
#define WB_USING_C_API
#include "types.h"
#ifndef WB_MATLAB_LOADLIBRARY
#include <math.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
void wb_motor_set_position(WbDeviceTag tag, double position); // rad or meters
void wb_motor_set_acceleration(WbDeviceTag tag, double acceleration); // rad/s^2 or m/s^2
void wb_motor_set_velocity(WbDeviceTag tag, double velocity); // rad/s or m/s
void wb_motor_set_force(WbDeviceTag tag, double force); // N
void wb_motor_set_torque(WbDeviceTag tag, double torque); // N*m
void wb_motor_set_available_force(WbDeviceTag tag, double force); // N
void wb_motor_set_available_torque(WbDeviceTag tag, double torque); // N*m
void wb_motor_set_control_pid(WbDeviceTag tag, double p, double i, double d); // set the PID control parameters
void wb_motor_enable_force_feedback(WbDeviceTag tag, int sampling_period);
void wb_motor_disable_force_feedback(WbDeviceTag tag);
int wb_motor_get_force_feedback_sampling_period(WbDeviceTag tag);
double wb_motor_get_force_feedback(WbDeviceTag tag);
void wb_motor_enable_torque_feedback(WbDeviceTag tag, int sampling_period);
void wb_motor_disable_torque_feedback(WbDeviceTag tag);
int wb_motor_get_torque_feedback_sampling_period(WbDeviceTag tag);
double wb_motor_get_torque_feedback(WbDeviceTag tag);
WbJointType wb_motor_get_type(WbDeviceTag tag);
double wb_motor_get_target_position(WbDeviceTag tag);
double wb_motor_get_min_position(WbDeviceTag tag);
double wb_motor_get_max_position(WbDeviceTag tag);
double wb_motor_get_velocity(WbDeviceTag tag);
double wb_motor_get_max_velocity(WbDeviceTag tag);
double wb_motor_get_acceleration(WbDeviceTag tag);
double wb_motor_get_available_force(WbDeviceTag tag);
double wb_motor_get_max_force(WbDeviceTag tag);
double wb_motor_get_available_torque(WbDeviceTag tag);
double wb_motor_get_max_torque(WbDeviceTag tag);
double wb_motor_get_multiplier(WbDeviceTag tag);
WbDeviceTag wb_motor_get_brake(WbDeviceTag tag);
WbDeviceTag wb_motor_get_position_sensor(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_MOTOR_H */

View File

@ -0,0 +1,50 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/************************************************************************/
/* Description: Webots C programming interface for the computer mouse. */
/************************************************************************/
#ifndef WB_MOUSE_H
#define WB_MOUSE_H
#define WB_USING_C_API
#include "mouse_state.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_mouse_enable(int sampling_period);
void wb_mouse_disable();
int wb_mouse_get_sampling_period();
void wb_mouse_enable_3d_position();
void wb_mouse_disable_3d_position();
bool wb_mouse_is_3d_position_enabled();
#ifndef WB_MATLAB_LOADLIBRARY
WbMouseState wb_mouse_get_state();
#else
// This function should be used only in the Matlab wrapper
WbMouseState *wb_mouse_get_state_pointer();
#endif
#ifdef __cplusplus
}
#endif
#endif /* WB_MOUSE_H */

View File

@ -0,0 +1,40 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**************************************************************************************/
/* Description: Common definition of the 'WbMouseState' for both the C and C++ APIs. */
/**************************************************************************************/
#ifndef WB_MOUSE_STATE_H
#define WB_MOUSE_STATE_H
#include "types.h"
typedef struct {
// mouse 2D position in the 3D window
double u;
double v;
// mouse 3D position
double x;
double y;
double z;
// mouse buttons state
bool left;
bool middle;
bool right;
} WbMouseState;
#endif /* WB_MOUSE_STATE_H */

View File

@ -0,0 +1,122 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WB_NODES_H
#define WB_NODES_H
// IMPORTANT: any modification of this file must also be propagated to:
// 1. include/controller/cpp/webots/Node.hpp
// 2. lib/matlab/mgenerate.py
typedef enum {
WB_NODE_NO_NODE,
// 3D rendering
WB_NODE_APPEARANCE,
WB_NODE_BACKGROUND,
WB_NODE_BILLBOARD,
WB_NODE_BOX,
WB_NODE_CAD_SHAPE,
WB_NODE_CAPSULE,
WB_NODE_COLOR,
WB_NODE_CONE,
WB_NODE_COORDINATE,
WB_NODE_CYLINDER,
WB_NODE_DIRECTIONAL_LIGHT,
WB_NODE_ELEVATION_GRID,
WB_NODE_FOG,
WB_NODE_GROUP,
WB_NODE_IMAGE_TEXTURE,
WB_NODE_INDEXED_FACE_SET,
WB_NODE_INDEXED_LINE_SET,
WB_NODE_MATERIAL,
WB_NODE_MESH,
WB_NODE_MUSCLE,
WB_NODE_NORMAL,
WB_NODE_PBR_APPEARANCE,
WB_NODE_PLANE,
WB_NODE_POINT_LIGHT,
WB_NODE_POINT_SET,
WB_NODE_POSE,
WB_NODE_SHAPE,
WB_NODE_SPHERE,
WB_NODE_SPOT_LIGHT,
WB_NODE_TEXTURE_COORDINATE,
WB_NODE_TEXTURE_TRANSFORM,
WB_NODE_TRANSFORM,
WB_NODE_VIEWPOINT,
// robots
WB_NODE_ROBOT,
// devices
WB_NODE_ACCELEROMETER,
WB_NODE_ALTIMETER,
WB_NODE_BRAKE,
WB_NODE_CAMERA,
WB_NODE_COMPASS,
WB_NODE_CONNECTOR,
WB_NODE_DISPLAY,
WB_NODE_DISTANCE_SENSOR,
WB_NODE_EMITTER,
WB_NODE_GPS,
WB_NODE_GYRO,
WB_NODE_INERTIAL_UNIT,
WB_NODE_LED,
WB_NODE_LIDAR,
WB_NODE_LIGHT_SENSOR,
WB_NODE_LINEAR_MOTOR,
WB_NODE_PEN,
WB_NODE_POSITION_SENSOR,
WB_NODE_PROPELLER,
WB_NODE_RADAR,
WB_NODE_RANGE_FINDER,
WB_NODE_RECEIVER,
WB_NODE_ROTATIONAL_MOTOR,
WB_NODE_SKIN,
WB_NODE_SPEAKER,
WB_NODE_TOUCH_SENSOR,
WB_NODE_VACUUM_GRIPPER,
// misc
WB_NODE_BALL_JOINT,
WB_NODE_BALL_JOINT_PARAMETERS,
WB_NODE_CHARGER,
WB_NODE_CONTACT_PROPERTIES,
WB_NODE_DAMPING,
WB_NODE_FLUID,
WB_NODE_FOCUS,
WB_NODE_HINGE_JOINT,
WB_NODE_HINGE_JOINT_PARAMETERS,
WB_NODE_HINGE_2_JOINT,
WB_NODE_IMMERSION_PROPERTIES,
WB_NODE_JOINT_PARAMETERS,
WB_NODE_LENS,
WB_NODE_LENS_FLARE,
WB_NODE_PHYSICS,
WB_NODE_RECOGNITION,
WB_NODE_SLIDER_JOINT,
WB_NODE_SLOT,
WB_NODE_SOLID,
WB_NODE_SOLID_REFERENCE,
WB_NODE_TRACK,
WB_NODE_TRACK_WHEEL,
WB_NODE_WORLD_INFO,
WB_NODE_ZOOM,
// experimental
WB_NODE_MICROPHONE,
WB_NODE_RADIO
} WbNodeType;
const char *wb_node_get_name(WbNodeType t);
#endif /* WB_NODES_H */

View File

@ -0,0 +1,38 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Pen node */
/**********************************************************************************/
#ifndef WB_PEN_H
#define WB_PEN_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_pen_write(WbDeviceTag tag, bool write); // switch on/off writing
void wb_pen_set_ink_color(WbDeviceTag tag, int color, double density); // set ink color
#ifdef __cplusplus
}
#endif
#endif /* WB_PEN_H */

View File

@ -0,0 +1,41 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**************************************************************************/
/* Description: Webots C utility programming interface for the default */
/* robot window. This module is not yet complete as several */
/* devices are missing for now. More usage examples and */
/* documentation will be provided once it is complete. */
/**************************************************************************/
#ifndef WBU_DEFAULT_ROBOT_WINDOW_H
#define WBU_DEFAULT_ROBOT_WINDOW_H
#include "robot_wwi.h"
#ifdef __cplusplus
extern "C" {
#endif
void wbu_default_robot_window_configure();
void wbu_default_robot_window_update();
void wbu_default_robot_window_set_images_max_size(int max_width, int max_height);
#ifdef __cplusplus
}
#endif
#endif /* WBU_DEFAULT_ROBOT_WINDOW_H */

View File

@ -0,0 +1,44 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*************************************************************************************/
/* Description: Webots C utility to enable/disable devices and retrieve the */
/* measurements from a robot window */
/*************************************************************************************/
#ifndef WBU_GENERIC_ROBOT_WINDOW_H
#define WBU_GENERIC_ROBOT_WINDOW_H
#include <webots/types.h>
#ifdef __cplusplus
extern "C" {
#endif
void wbu_generic_robot_window_parse_device_command(char *token, char *tokens);
bool wbu_generic_robot_window_parse_device_control_command(const char *first_token, char *tokens);
bool wbu_generic_robot_window_handle_messages(const char *message);
void wbu_generic_robot_window_init();
void wbu_generic_robot_window_update();
bool wbu_generic_robot_window_is_hidden();
double wbu_generic_robot_window_refresh_rate();
bool wbu_generic_robot_window_needs_update();
#ifdef __cplusplus
}
#endif
#endif // WBU_GENERIC_ROBOT_WINDOW_H

View File

@ -0,0 +1,30 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WB_ROBOT_WINDOW_H
#define WB_ROBOT_WINDOW_H
#ifdef __cplusplus
extern "C" {
#endif
void *wb_robot_window_custom_function(void *);
#ifdef __cplusplus
}
#endif
#endif /* WB_ROBOT_WINDOW_H */

View File

@ -0,0 +1,36 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WB_ROBOT_WWI_H
#define WB_ROBOT_WWI_H
#ifdef __cplusplus
#include <cstring>
extern "C" {
#else
#include <string.h>
#endif
void wb_robot_wwi_send(const char *data, int size);
const char *wb_robot_wwi_receive(int *size);
const char *wb_robot_wwi_receive_text();
#define wb_robot_wwi_send_text(t) wb_robot_wwi_send(t, strlen(t) + 1)
#ifdef __cplusplus
}
#endif
#endif /* WB_ROBOT_WWI_H */

View File

@ -0,0 +1,47 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Motor node */
/**********************************************************************************/
#ifndef WB_POSITION_SENSOR_H
#define WB_POSITION_SENSOR_H
#define WB_USING_C_API
#include "types.h"
#ifndef WB_MATLAB_LOADLIBRARY
#include <math.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
void wb_position_sensor_enable(WbDeviceTag tag, int sampling_period); // milliseconds
void wb_position_sensor_disable(WbDeviceTag tag);
int wb_position_sensor_get_sampling_period(WbDeviceTag tag);
double wb_position_sensor_get_value(WbDeviceTag tag); // rad or meters
WbJointType wb_position_sensor_get_type(WbDeviceTag tag);
WbDeviceTag wb_position_sensor_get_motor(WbDeviceTag tag);
WbDeviceTag wb_position_sensor_get_brake(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_POSITION_SENSOR_H */

View File

@ -0,0 +1,53 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Radar node */
/**********************************************************************************/
#ifndef WB_RADAR_H
#define WB_RADAR_H
#define WB_USING_C_API
#include "radar_target.h"
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_radar_enable(WbDeviceTag tag, int sampling_period);
void wb_radar_disable(WbDeviceTag tag);
int wb_radar_get_sampling_period(WbDeviceTag tag);
int wb_radar_get_number_of_targets(WbDeviceTag tag);
const WbRadarTarget *wb_radar_get_targets(WbDeviceTag tag);
double wb_radar_get_min_range(WbDeviceTag tag);
double wb_radar_get_max_range(WbDeviceTag tag);
double wb_radar_get_horizontal_fov(WbDeviceTag tag);
double wb_radar_get_vertical_fov(WbDeviceTag tag);
#ifdef WB_MATLAB_LOADLIBRARY
// This function should be used only in the Matlab wrapper
const WbRadarTarget *wb_radar_get_target(WbDeviceTag tag, int index);
#endif
#ifdef __cplusplus
}
#endif
#endif /* WB_RADAR_H */

View File

@ -0,0 +1,31 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**************************************************************************************/
/* Description: Common definition of the 'WbRadarTarget' for both the C and C++ APIs */
/**************************************************************************************/
#ifndef WB_RADAR_TARGET_H
#define WB_RADAR_TARGET_H
typedef struct {
double distance;
double received_power;
double speed;
double azimuth;
} WbRadarTarget;
#endif /* WB_RADAR_TARGET_H */

View File

@ -0,0 +1,75 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Radio node */
/**********************************************************************************/
#ifndef WB_RADIO_H
#define WB_RADIO_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void *WbRadioMessage;
typedef void *WbRadioEvent;
WbRadioMessage wb_radio_message_new(int length, const char *body, const char *destination);
void wb_radio_message_delete(WbRadioMessage);
const char *wb_radio_message_get_destination(WbRadioMessage);
int wb_radio_message_get_length(WbRadioMessage);
const char *wb_radio_message_get_body(WbRadioMessage);
void wb_radio_enable(WbDeviceTag tag, int sampling_period);
void wb_radio_disable(WbDeviceTag tag);
void wb_radio_set_address(WbDeviceTag tag, const char *address);
const char *wb_radio_get_address(WbDeviceTag tag);
void wb_radio_set_frequency(WbDeviceTag tag, double hz);
double wb_radio_get_frequency(WbDeviceTag tag);
void wb_radio_set_channel(WbDeviceTag tag, int channel);
int wb_radio_get_channel(WbDeviceTag tag);
void wb_radio_set_bitrate(WbDeviceTag tag, int bits_per_second);
int wb_radio_get_bitrate(WbDeviceTag tag);
void wb_radio_set_rx_sensitivity(WbDeviceTag tag, double dBm);
double wb_radio_get_rx_sensitivity(WbDeviceTag tag);
void wb_radio_set_tx_power(WbDeviceTag tag, double dBm);
double wb_radio_get_tx_power(WbDeviceTag tag);
void wb_radio_set_callback(WbDeviceTag tag, void (*)(const WbRadioEvent));
WbDeviceTag wb_radio_event_get_radio(const WbRadioEvent);
char *wb_radio_event_get_data(const WbRadioEvent);
int wb_radio_event_get_data_size(const WbRadioEvent);
char *wb_radio_event_get_emitter(const WbRadioEvent);
double wb_radio_event_get_rssi(const WbRadioEvent);
void wb_radio_send(WbDeviceTag tag, const WbRadioMessage, double delay);
#ifdef __cplusplus
}
#endif
#endif /* WB_RADIO_H */

View File

@ -0,0 +1,50 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the RangeFinder node */
/**********************************************************************************/
#ifndef WB_RANGE_FINDER_H
#define WB_RANGE_FINDER_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_range_finder_enable(WbDeviceTag tag, int sampling_period);
void wb_range_finder_disable(WbDeviceTag tag);
int wb_range_finder_get_sampling_period(WbDeviceTag tag);
const float *wb_range_finder_get_range_image(WbDeviceTag tag);
int wb_range_finder_get_width(WbDeviceTag tag);
int wb_range_finder_get_height(WbDeviceTag tag);
double wb_range_finder_get_fov(WbDeviceTag tag);
double wb_range_finder_get_min_range(WbDeviceTag tag);
double wb_range_finder_get_max_range(WbDeviceTag tag);
int wb_range_finder_save_image(WbDeviceTag tag, const char *filename, int quality);
// range finder functions
#define wb_range_finder_image_get_depth(image, width, x, y) (image[(y) * (width) + (x)])
#ifdef __cplusplus
}
#endif
#endif /* WB_RANGE_FINDER_H */

View File

@ -0,0 +1,53 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Receiver node */
/**********************************************************************************/
#ifndef WB_RECEIVER_H
#define WB_RECEIVER_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef WB_CHANNEL_BROADCAST
#define WB_CHANNEL_BROADCAST -1
#endif
// device functions
void wb_receiver_enable(WbDeviceTag tag, int sampling_period);
void wb_receiver_disable(WbDeviceTag tag);
int wb_receiver_get_sampling_period(WbDeviceTag tag);
void wb_receiver_set_channel(WbDeviceTag tag, int channel);
int wb_receiver_get_channel(WbDeviceTag tag);
int wb_receiver_get_queue_length(WbDeviceTag tag);
void wb_receiver_next_packet(WbDeviceTag tag);
int wb_receiver_get_data_size(WbDeviceTag tag);
const void *wb_receiver_get_data(WbDeviceTag tag);
double wb_receiver_get_signal_strength(WbDeviceTag tag);
const double *wb_receiver_get_emitter_direction(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_RECEIVER_H */

View File

@ -0,0 +1,128 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for communicating with the */
/* remote control library */
/**********************************************************************************/
#ifndef WB_REMOTE_CONTROL_H
#define WB_REMOTE_CONTROL_H
#define WB_USING_C_API
#include "camera_recognition_object.h"
#include "radar_target.h"
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void *wb_remote_control_custom_function(void *);
// Sensor functions (values read by the controller)
void wbr_robot_battery_sensor_set_value(double value);
void wbr_accelerometer_set_values(WbDeviceTag tag, const double *values);
void wbr_camera_recognition_set_object(WbDeviceTag tag, const WbCameraRecognitionObject *objects, int object_number);
void wbr_compass_set_values(WbDeviceTag tag, const double *values);
void wbr_distance_sensor_set_value(WbDeviceTag tag, double value);
void wbr_gps_set_values(WbDeviceTag tag, const double *values);
void wbr_gps_set_speed(WbDeviceTag tag, const double speed);
void wbr_gps_set_velocity_vector(WbDeviceTag tag, const double *values);
void wbr_gyro_set_values(WbDeviceTag tag, const double *values);
void wbr_inertial_unit_set_value(WbDeviceTag tag, double value);
void wbr_light_sensor_set_value(WbDeviceTag tag, double value);
void wbr_microphone_set_buffer(WbDeviceTag tag, const unsigned char *buffer, int size);
void wbr_motor_set_position_feedback(WbDeviceTag tag, double value);
void wbr_motor_set_force_feedback(WbDeviceTag tag, double value);
void wbr_motor_set_torque_feedback(WbDeviceTag tag, double value);
void wbr_position_sensor_set_value(WbDeviceTag tag, double value);
void wbr_radar_set_targets(WbDeviceTag tag, const WbRadarTarget *targets, int target_number);
void wbr_touch_sensor_set_value(WbDeviceTag tag, double value);
void wbr_touch_sensor_set_values(WbDeviceTag tag, const double *values);
// TODO doc required
void wbr_display_save_image(WbDeviceTag tag, int id, int width, int height, unsigned char *image);
void wbr_camera_set_image(WbDeviceTag tag, const unsigned char *image);
unsigned char *wbr_camera_get_image_buffer(WbDeviceTag tag);
// Actuator functions (values written by the controller)
typedef struct WbrInterface {
// mandatory functions :
struct {
bool (*wbr_start)(const char *);
void (*wbr_stop)();
bool (*wbr_has_failed)();
void (*wbr_stop_actuators)();
int (*wbr_robot_step)(int);
} mandatory;
// user custom function to communicate data
void *(*wbr_custom_function)(void *);
// optional functions (if they are used but not defined it will print a warning) :
void (*wbr_robot_battery_set_sampling_period)(int sampling_period);
void (*wbr_set_sampling_period)(WbDeviceTag tag, int sampling_period);
void (*wbr_camera_set_fov)(WbDeviceTag tag, double fov);
void (*wbr_camera_set_exposure)(WbDeviceTag tag, double exposure);
void (*wbr_camera_set_focal_distance)(WbDeviceTag tag, double focal_distance);
void (*wbr_led_set)(WbDeviceTag tag, int state);
void (*wbr_pen_set_ink_color)(WbDeviceTag tag, int color, double density);
void (*wbr_pen_write)(WbDeviceTag tag, bool write);
void (*wbr_speaker_emit_sample)(WbDeviceTag tag, const void *data, int size);
void (*wbr_motor_set_force_sampling_period)(WbDeviceTag tag, int sampling_period);
void (*wbr_motor_set_torque_sampling_period)(WbDeviceTag tag, int sampling_period);
void (*wbr_motor_set_position)(WbDeviceTag tag, double position);
void (*wbr_motor_set_acceleration)(WbDeviceTag tag, double acceleration);
void (*wbr_motor_set_velocity)(WbDeviceTag tag, double velocity);
void (*wbr_motor_set_force)(WbDeviceTag tag, double force);
void (*wbr_motor_set_torque)(WbDeviceTag tag, double torque);
void (*wbr_motor_set_available_force)(WbDeviceTag tag, double available_force);
void (*wbr_motor_set_available_torque)(WbDeviceTag tag, double available_torque);
void (*wbr_motor_set_control_pid)(WbDeviceTag tag, double p, double i, double d);
void (*wbr_display_set_color)(WbDeviceTag tag, int color);
void (*wbr_display_set_alpha)(WbDeviceTag tag, double alpha);
void (*wbr_display_set_opacity)(WbDeviceTag tag, double opacity);
void (*wbr_display_draw_pixel)(WbDeviceTag tag, int x, int y);
void (*wbr_display_draw_line)(WbDeviceTag tag, int x1, int y1, int x2, int y2);
void (*wbr_display_draw_rectangle)(WbDeviceTag tag, int x, int y, int width, int height);
void (*wbr_display_draw_oval)(WbDeviceTag tag, int cx, int cy, int a, int b);
void (*wbr_display_draw_polygon)(WbDeviceTag tag, const int *x, const int *y, int size);
void (*wbr_display_draw_text)(WbDeviceTag tag, const char *txt, int x, int y);
void (*wbr_display_fill_rectangle)(WbDeviceTag tag, int x, int y, int width, int height);
void (*wbr_display_fill_oval)(WbDeviceTag tag, int cx, int cy, int a, int b);
void (*wbr_display_fill_polygon)(WbDeviceTag tag, const int *x, const int *y, int size);
// TODO these functions are not like the API, documentation required
void (*wbr_display_image_new)(WbDeviceTag tag, int id, int width, int height, const void *data, int format);
void (*wbr_display_image_copy)(WbDeviceTag tag, int id, int x, int y, int width, int height);
void (*wbr_display_image_delete)(WbDeviceTag tag, int id);
void (*wbr_display_image_paste)(WbDeviceTag tag, int id, int x, int y);
void (*wbr_display_image_save)(WbDeviceTag tag, int id);
} WbrInterface;
#ifdef __cplusplus
}
#endif
#endif /* WB_REMOTE_CONTROL_H */

View File

@ -0,0 +1,133 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Robot node */
/**********************************************************************************/
#ifndef WB_ROBOT_H
#define WB_ROBOT_H
#define WB_USING_C_API
#include "types.h"
#ifdef __CYGWIN__
#include <stdio.h>
#endif
#if defined(__VISUALC__) || defined(_MSC_VER)
#include "stdio.h"
#endif
#include "nodes.h"
#ifdef KROS_COMPILATION
#define main() _kros_main()
#endif
typedef void *WbMutexRef; // identifier of a mutex
typedef enum { WB_MODE_SIMULATION = 0, WB_MODE_CROSS_COMPILATION, WB_MODE_REMOTE_CONTROL } WbRobotMode;
typedef enum {
WB_EVENT_QUIT = -1,
WB_EVENT_NO_EVENT = 0,
WB_EVENT_MOUSE_CLICK = 1,
WB_EVENT_MOUSE_MOVE = 2,
WB_EVENT_KEYBOARD = 4,
WB_EVENT_JOYSTICK_BUTTON = 8,
WB_EVENT_JOYSTICK_AXIS = 16,
WB_EVENT_JOYSTICK_POV = 32
} WbUserInputEvent;
// cart function headers
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(__VISUALC__) && !defined(_MSC_VER)
int wb_robot_init();
/* In the visual studio case, the buffer size of the standard output and
* the standard error cannot be modified from a dll
*/
#else
int wb_robot_init_msvc(); // internally, this function just calls wb_robot_init()
#define wb_robot_init() (setvbuf(stdout, NULL, _IONBF, 0), setvbuf(stderr, NULL, _IONBF, 0), wb_robot_init_msvc())
#endif
int wb_robot_step_begin(int duration); // milliseconds
int wb_robot_step_end();
int wb_robot_step(int duration); // milliseconds
#ifdef __CYGWIN__ // In that case, we need to flush explicitly the stdout/stdin streams otherwise they are buffered
// We cannot call fflush from the libController as libController is compiled with gcc8 and won't flush the stdout/stderr
// of a gcc7 (cygwin) compiled binary. Therefore, we need to perform the fflush in a gcc7 compiled code, e.g., in a macro here.
#define wb_robot_step(d) (fflush(NULL), wb_robot_step(d))
#endif
WbUserInputEvent wb_robot_wait_for_user_input_event(WbUserInputEvent event_type, int timeout); // milliseconds
void wb_robot_cleanup();
double wb_robot_get_time();
const char *wb_robot_get_urdf(const char *prefix);
const char *wb_robot_get_name();
const char *wb_robot_get_model();
const char *wb_robot_get_custom_data();
void wb_robot_set_custom_data(const char *data);
WbRobotMode wb_robot_get_mode();
void wb_robot_set_mode(WbRobotMode mode, const char *arg);
bool wb_robot_get_synchronization();
bool wb_robot_get_supervisor();
const char *wb_robot_get_project_path();
const char *wb_robot_get_world_path();
double wb_robot_get_basic_time_step();
WbDeviceTag wb_robot_get_device(const char *name);
// Introspection API
int wb_robot_get_number_of_devices();
WbDeviceTag wb_robot_get_device_by_index(int index);
// robot battery API
void wb_robot_battery_sensor_enable(int sampling_period);
void wb_robot_battery_sensor_disable();
int wb_robot_battery_sensor_get_sampling_period();
double wb_robot_battery_sensor_get_value();
// robot multi-thread API
#ifndef WB_MATLAB_LOADLIBRARY
void wb_robot_task_new(void (*task)(void *), void *param); // create a task
WbMutexRef wb_robot_mutex_new();
void wb_robot_mutex_lock(WbMutexRef);
void wb_robot_mutex_unlock(WbMutexRef);
void wb_robot_mutex_delete(WbMutexRef);
#endif
// Motion editor specfic function : Please don't use this function outside qt_utils
// This function doesn't work if the robot window has not been shown at lease once
void wb_robot_pin_to_static_environment(bool pin);
// Deprecated functions
// deprecated since Webots 2018a, please use wb_robot_get_custom_data and
// wb_robot_set_custom_data instead
const char *wb_robot_get_controller_name() WB_DEPRECATED;
const char *wb_robot_get_data() WB_DEPRECATED;
void wb_robot_set_data(const char *data) WB_DEPRECATED;
#ifdef __cplusplus
}
#endif
#endif /* WB_ROBOT_H */

View File

@ -0,0 +1,42 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Skin node */
/**********************************************************************************/
#ifndef WB_SKIN_H
#define WB_SKIN_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_skin_set_bone_orientation(WbDeviceTag tag, int index, const double orientation[4], bool absolute);
void wb_skin_set_bone_position(WbDeviceTag tag, int index, const double position[3], bool absolute);
int wb_skin_get_bone_count(WbDeviceTag tag);
const char *wb_skin_get_bone_name(WbDeviceTag tag, int index);
const double *wb_skin_get_bone_orientation(WbDeviceTag tag, int index, bool absolute);
const double *wb_skin_get_bone_position(WbDeviceTag tag, int index, bool absolute);
#ifdef __cplusplus
}
#endif
#endif /* WB_SKIN_H */

View File

@ -0,0 +1,49 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Speaker node */
/**********************************************************************************/
#ifndef WB_SPEAKER_H
#define WB_SPEAKER_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_speaker_play_sound(WbDeviceTag left, WbDeviceTag right, const char *sound, double volume, double pitch, double balance,
bool loop);
void wb_speaker_stop(WbDeviceTag tag, const char *sound);
bool wb_speaker_is_sound_playing(WbDeviceTag tag, const char *sound);
// "pico" or "microsoft" (Windows only)
bool wb_speaker_set_engine(WbDeviceTag tag, const char *engine);
// "en-US", "en-UK", "de-DE", "es-ES", "fr-FR", "it-IT", etc.
bool wb_speaker_set_language(WbDeviceTag tag, const char *language);
const char *wb_speaker_get_engine(WbDeviceTag tag);
const char *wb_speaker_get_language(WbDeviceTag tag);
void wb_speaker_speak(WbDeviceTag tag, const char *text, double volume);
bool wb_speaker_is_speaking(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_SPEAKER_H */

View File

@ -0,0 +1,252 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the Supervisor node */
/**********************************************************************************/
#ifndef WB_SUPERVISOR_H
#define WB_SUPERVISOR_H
#define WB_USING_C_API
#include "contact_point.h"
#include "nodes.h"
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
WB_NO_FIELD = 0x00,
WB_SF_BOOL = 0x01,
WB_SF_INT32,
WB_SF_FLOAT,
WB_SF_VEC2F,
WB_SF_VEC3F,
WB_SF_ROTATION,
WB_SF_COLOR,
WB_SF_STRING,
WB_SF_NODE,
WB_MF = 0x10,
WB_MF_BOOL,
WB_MF_INT32,
WB_MF_FLOAT,
WB_MF_VEC2F,
WB_MF_VEC3F,
WB_MF_ROTATION,
WB_MF_COLOR,
WB_MF_STRING,
WB_MF_NODE
} WbFieldType;
typedef enum {
WB_SUPERVISOR_SIMULATION_MODE_PAUSE = 0,
WB_SUPERVISOR_SIMULATION_MODE_REAL_TIME,
WB_SUPERVISOR_SIMULATION_MODE_FAST
} WbSimulationMode;
void wb_supervisor_world_load(const char *filename);
bool wb_supervisor_world_save(const char *filename);
void wb_supervisor_world_reload();
void wb_supervisor_simulation_quit(int status);
void wb_supervisor_simulation_reset();
void wb_supervisor_simulation_reset_physics();
WbSimulationMode wb_supervisor_simulation_get_mode();
void wb_supervisor_simulation_set_mode(WbSimulationMode mode);
void wb_supervisor_set_label(int id, const char *text, double x, double y, double size, int color, double transparency,
const char *font);
void wb_supervisor_export_image(const char *filename, int quality);
void wb_supervisor_movie_start_recording(const char *filename, int width, int height, int codec, int quality, int acceleration,
bool caption);
void wb_supervisor_movie_stop_recording();
bool wb_supervisor_movie_is_ready();
bool wb_supervisor_movie_failed();
bool wb_supervisor_animation_start_recording(const char *filename);
bool wb_supervisor_animation_stop_recording();
WbNodeRef wb_supervisor_node_get_root();
WbNodeRef wb_supervisor_node_get_self();
int wb_supervisor_node_get_id(WbNodeRef node);
WbNodeRef wb_supervisor_node_get_from_id(int id);
WbNodeRef wb_supervisor_node_get_from_device(WbDeviceTag tag);
WbNodeRef wb_supervisor_node_get_from_def(const char *def);
WbNodeRef wb_supervisor_node_get_from_proto_def(WbNodeRef node, const char *def);
WbNodeRef wb_supervisor_node_get_parent_node(WbNodeRef node);
WbNodeRef wb_supervisor_node_get_selected();
WbNodeType wb_supervisor_node_get_type(WbNodeRef node);
WbFieldRef wb_supervisor_node_get_field(WbNodeRef node, const char *field_name);
WbFieldRef wb_supervisor_node_get_field_by_index(WbNodeRef node, const int index);
int wb_supervisor_node_get_number_of_fields(WbNodeRef node);
WbFieldRef wb_supervisor_node_get_base_node_field(WbNodeRef node, const char *field_name);
WbFieldRef wb_supervisor_node_get_base_node_field_by_index(WbNodeRef node, int index);
int wb_supervisor_node_get_number_of_base_node_fields(WbNodeRef node);
void wb_supervisor_node_remove(WbNodeRef node);
void wb_supervisor_node_save_state(WbNodeRef node, const char *state_name);
void wb_supervisor_node_load_state(WbNodeRef node, const char *state_name);
void wb_supervisor_node_set_joint_position(WbNodeRef node, double position, int index);
WbProtoRef wb_supervisor_node_get_proto(WbNodeRef node);
const char *wb_supervisor_node_get_def(WbNodeRef node);
const char *wb_supervisor_node_get_type_name(WbNodeRef node);
const char *wb_supervisor_node_get_base_type_name(WbNodeRef node);
bool wb_supervisor_node_is_proto(WbNodeRef node);
const double *wb_supervisor_node_get_center_of_mass(WbNodeRef node);
const double *wb_supervisor_node_get_contact_point(WbNodeRef node, int index);
WbNodeRef wb_supervisor_node_get_contact_point_node(WbNodeRef node, int index);
int wb_supervisor_node_get_number_of_contact_points(WbNodeRef node, bool include_descendants);
WbContactPoint *wb_supervisor_node_get_contact_points(WbNodeRef node, bool include_descendants, int *size);
const double *wb_supervisor_node_get_orientation(WbNodeRef node);
const double *wb_supervisor_node_get_position(WbNodeRef node);
const double *wb_supervisor_node_get_pose(WbNodeRef node, WbNodeRef from_node);
bool wb_supervisor_node_get_static_balance(WbNodeRef node);
const double *wb_supervisor_node_get_velocity(WbNodeRef node);
void wb_supervisor_node_set_velocity(WbNodeRef node, const double velocity[6]);
void wb_supervisor_node_reset_physics(WbNodeRef node);
void wb_supervisor_node_restart_controller(WbNodeRef node);
const char *wb_supervisor_node_export_string(WbNodeRef node);
void wb_supervisor_node_move_viewpoint(WbNodeRef node);
void wb_supervisor_node_set_visibility(WbNodeRef node, WbNodeRef from, bool visible);
void wb_supervisor_node_add_force(WbNodeRef node, const double force[3], bool relative);
void wb_supervisor_node_add_force_with_offset(WbNodeRef node, const double force[3], const double offset[3], bool relative);
void wb_supervisor_node_add_torque(WbNodeRef node, const double torque[3], bool relative);
const char *wb_supervisor_field_get_name(WbFieldRef field);
WbFieldType wb_supervisor_field_get_type(WbFieldRef field);
const char *wb_supervisor_field_get_type_name(WbFieldRef field);
int wb_supervisor_field_get_count(WbFieldRef field);
WbFieldRef wb_supervisor_field_get_actual_field(WbFieldRef field);
void wb_supervisor_field_enable_sf_tracking(WbFieldRef field, int sampling_period);
void wb_supervisor_field_disable_sf_tracking(WbFieldRef field);
void wb_supervisor_node_enable_pose_tracking(WbNodeRef node, int sampling_period, WbNodeRef from_node);
void wb_supervisor_node_disable_pose_tracking(WbNodeRef node, WbNodeRef from_node);
void wb_supervisor_node_enable_contact_points_tracking(WbNodeRef node, int sampling_period, bool include_descendants);
void wb_supervisor_node_disable_contact_points_tracking(WbNodeRef node);
bool wb_supervisor_field_get_sf_bool(WbFieldRef field);
int wb_supervisor_field_get_sf_int32(WbFieldRef field);
double wb_supervisor_field_get_sf_float(WbFieldRef field);
const double *wb_supervisor_field_get_sf_vec2f(WbFieldRef field);
const double *wb_supervisor_field_get_sf_vec3f(WbFieldRef field);
const double *wb_supervisor_field_get_sf_rotation(WbFieldRef field);
const double *wb_supervisor_field_get_sf_color(WbFieldRef field);
const char *wb_supervisor_field_get_sf_string(WbFieldRef field);
WbNodeRef wb_supervisor_field_get_sf_node(WbFieldRef field);
bool wb_supervisor_field_get_mf_bool(WbFieldRef field, int index);
int wb_supervisor_field_get_mf_int32(WbFieldRef field, int index);
double wb_supervisor_field_get_mf_float(WbFieldRef field, int index);
const double *wb_supervisor_field_get_mf_vec2f(WbFieldRef field, int index);
const double *wb_supervisor_field_get_mf_vec3f(WbFieldRef field, int index);
const double *wb_supervisor_field_get_mf_color(WbFieldRef field, int index);
const double *wb_supervisor_field_get_mf_rotation(WbFieldRef field, int index);
const char *wb_supervisor_field_get_mf_string(WbFieldRef field, int index);
WbNodeRef wb_supervisor_field_get_mf_node(WbFieldRef field, int index);
void wb_supervisor_field_set_sf_bool(WbFieldRef field, bool value);
void wb_supervisor_field_set_sf_int32(WbFieldRef field, int value);
void wb_supervisor_field_set_sf_float(WbFieldRef field, double value);
void wb_supervisor_field_set_sf_vec2f(WbFieldRef field, const double values[2]);
void wb_supervisor_field_set_sf_vec3f(WbFieldRef field, const double values[3]);
void wb_supervisor_field_set_sf_rotation(WbFieldRef field, const double values[4]);
void wb_supervisor_field_set_sf_color(WbFieldRef field, const double values[3]);
void wb_supervisor_field_set_sf_string(WbFieldRef field, const char *value);
void wb_supervisor_field_set_mf_bool(WbFieldRef field, int index, bool value);
void wb_supervisor_field_set_mf_int32(WbFieldRef field, int index, int value);
void wb_supervisor_field_set_mf_float(WbFieldRef field, int index, double value);
void wb_supervisor_field_set_mf_vec2f(WbFieldRef field, int index, const double values[2]);
void wb_supervisor_field_set_mf_vec3f(WbFieldRef field, int index, const double values[3]);
void wb_supervisor_field_set_mf_rotation(WbFieldRef field, int index, const double values[4]);
void wb_supervisor_field_set_mf_color(WbFieldRef field, int index, const double values[3]);
void wb_supervisor_field_set_mf_string(WbFieldRef field, int index, const char *value);
void wb_supervisor_field_insert_mf_bool(WbFieldRef field, int index, bool value);
void wb_supervisor_field_insert_mf_int32(WbFieldRef field, int index, int value);
void wb_supervisor_field_insert_mf_float(WbFieldRef field, int index, double value);
void wb_supervisor_field_insert_mf_vec2f(WbFieldRef field, int index, const double values[2]);
void wb_supervisor_field_insert_mf_vec3f(WbFieldRef field, int index, const double values[3]);
void wb_supervisor_field_insert_mf_rotation(WbFieldRef field, int index, const double values[4]);
void wb_supervisor_field_insert_mf_color(WbFieldRef field, int index, const double values[3]);
void wb_supervisor_field_insert_mf_string(WbFieldRef field, int index, const char *value);
void wb_supervisor_field_remove_mf(WbFieldRef field, int index);
void wb_supervisor_field_import_mf_node_from_string(WbFieldRef field, int position, const char *node_string);
void wb_supervisor_field_remove_sf(WbFieldRef field);
void wb_supervisor_field_import_sf_node_from_string(WbFieldRef field, const char *node_string);
const char *wb_supervisor_proto_get_type_name(WbProtoRef proto);
bool wb_supervisor_proto_is_derived(WbProtoRef proto);
WbProtoRef wb_supervisor_proto_get_parent(WbProtoRef proto);
WbFieldRef wb_supervisor_proto_get_field(WbProtoRef proto, const char *field_name);
WbFieldRef wb_supervisor_proto_get_field_by_index(WbProtoRef proto, int index);
int wb_supervisor_proto_get_number_of_fields(WbProtoRef proto);
bool wb_supervisor_virtual_reality_headset_is_used();
const double *wb_supervisor_virtual_reality_headset_get_position();
const double *wb_supervisor_virtual_reality_headset_get_orientation();
// Deprecated functions
// deprecated since Webots R2023a revision 1
// use wb_supervisor_node_enable_contact_points_tracking or wb_supervisor_node_disable_contact_points_tracking instead
void wb_supervisor_node_enable_contact_point_tracking(WbNodeRef node, int sampling_period, bool include_descendants);
void wb_supervisor_node_disable_contact_point_tracking(WbNodeRef node, bool include_descendants);
// deprecated since Webots R2018b
void wb_supervisor_simulation_revert() WB_DEPRECATED; // please use wb_supervisor_world_reload() instead
void wb_supervisor_load_world(const char *filename) WB_DEPRECATED; // please use wb_supervisor_world_load() instead
bool wb_supervisor_save_world(const char *filename) WB_DEPRECATED; // please use wb_supervisor_world_save() instead
// deprecated since Webots 8.6.0, plesae use wb_supervisor_field_remove_mf_item() instead
void wb_supervisor_field_remove_mf_node(WbFieldRef field, int position) WB_DEPRECATED;
// deprecated since Webots 8.0.0, plesae use wb_supervisor_simulation_reset_physics() instead
void wb_supervisor_simulation_physics_reset() WB_DEPRECATED;
// deprecated since Webots 8.4.0 please use wb_supervisor_movie_is_ready and wb_supervisor_movie_failed
#define WB_SUPERVISOR_MOVIE_READY 0
#define WB_SUPERVISOR_MOVIE_RECORDING 1
#define WB_SUPERVISOR_MOVIE_SAVING 2
#define WB_SUPERVISOR_MOVIE_WRITE_ERROR 3
#define WB_SUPERVISOR_MOVIE_ENCODING_ERROR 4
#define WB_SUPERVISOR_MOVIE_SIMULATION_ERROR 5
int wb_supervisor_movie_get_status();
// deprecated since webots 8.3.0: please use the wb_supervisor_movie_*() functions instead
void wb_supervisor_start_movie(const char *file, int width, int height, int codec, int quality, int acceleration,
bool caption) WB_DEPRECATED;
void wb_supervisor_stop_movie() WB_DEPRECATED;
int wb_supervisor_get_movie_status() WB_DEPRECATED;
#ifdef __cplusplus
}
#endif
#endif /* SUPERVISOR_H */

View File

@ -0,0 +1,50 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the TouchSensor node */
/**********************************************************************************/
#ifndef WB_TOUCH_SENSOR_H
#define WB_TOUCH_SENSOR_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_touch_sensor_enable(WbDeviceTag tag, int sampling_period);
void wb_touch_sensor_disable(WbDeviceTag tag);
int wb_touch_sensor_get_sampling_period(WbDeviceTag tag);
int wb_touch_sensor_get_lookup_table_size(WbDeviceTag tag);
const double *wb_touch_sensor_get_lookup_table(WbDeviceTag tag);
double wb_touch_sensor_get_value(WbDeviceTag tag);
const double *wb_touch_sensor_get_values(WbDeviceTag tag);
typedef enum { WB_TOUCH_SENSOR_BUMPER = 0, WB_TOUCH_SENSOR_FORCE, WB_TOUCH_SENSOR_FORCE3D } WbTouchSensorType;
WbTouchSensorType wb_touch_sensor_get_type(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_TOUCH_SENSOR_H */

View File

@ -0,0 +1,83 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Common definitions for both the C and C++ APIs */
/**********************************************************************************/
#if defined(WB_USING_CPP_API) && defined(WB_USING_C_API) && !defined(WB_ALLOW_MIXING_C_AND_CPP_API)
#ifdef _MSC_VER
#pragma message("warning: mixing the C and C++ APIs in the same controller is not supported.")
#else
#warning "mixing the C and C++ APIs in the same controller is not supported."
#endif
#endif
#ifndef WB_TYPES_H
#define WB_TYPES_H
// There can be a maximum of 65534 devices on a robot (65535 being reserved)
typedef unsigned short WbDeviceTag; // identifier of a device
// Opaque type definitions
typedef struct WbImageStructPrivate *WbImageRef;
typedef struct WbMotionStructPrivate *WbMotionRef;
typedef struct WbNodeStructPrivate *WbNodeRef;
typedef struct WbProtoInfoStructPrivate *WbProtoRef;
typedef struct WbFieldStructPrivate *WbFieldRef;
// define "bool" type for C controllers
// C++ code will use the standard definition of "bool"
#ifndef __cplusplus
#include <math.h> // definition of INFINITY
#ifndef INFINITY
#define INFINITY (1.0 / 0.0)
#endif
#ifndef bool
#define bool char
#endif
#ifndef true
// clang-format off
#define true ((bool)1)
// clang-format on
#endif
#ifndef false
// clang-format off
#define false ((bool)0)
// clang-format on
#endif
#endif
#define WB_ANGULAR 0 // kept for backward compatibility R2018b
typedef enum { WB_ROTATIONAL = 0, WB_LINEAR } WbJointType;
// Allow us to mark functions as 'deprecated' and have gcc emit a nice warning for each use.
// Usage: int foo(char) WB_DEPRECATED;
// and then gcc will emit a warning for each usage of the function.
#ifndef WB_DEPRECATED
#if __GNUC__ >= 3 && !defined WB_MATLAB_LOADLIBRARY
#define WB_DEPRECATED __attribute__((deprecated))
#else
#define WB_DEPRECATED
#endif
#endif
#endif /* WB_TYPES_H */

View File

@ -0,0 +1,63 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WBU_ANSI_CODES_H
#define WBU_ANSI_CODES_H
#ifndef __cplusplus
#include <stdio.h>
#endif
#define ANSI_RESET "\x1b[0m"
#define ANSI_BOLD "\x1b[1m"
#define ANSI_UNDERLINE "\x1b[4m"
#define ANSI_BLACK_BACKGROUND "\x1b[40m"
#define ANSI_RED_BACKGROUND "\x1b[41m"
#define ANSI_GREEN_BACKGROUND "\x1b[42m"
#define ANSI_YELLOW_BACKGROUND "\x1b[43m"
#define ANSI_BLUE_BACKGROUND "\x1b[44m"
#define ANSI_MAGENTA_BACKGROUND "\x1b[45m"
#define ANSI_CYAN_BACKGROUND "\x1b[46m"
#define ANSI_WHITE_BACKGROUND "\x1b[47m"
#define ANSI_BLACK_FOREGROUND "\x1b[30m"
#define ANSI_RED_FOREGROUND "\x1b[31m"
#define ANSI_GREEN_FOREGROUND "\x1b[32m"
#define ANSI_YELLOW_FOREGROUND "\x1b[33m"
#define ANSI_BLUE_FOREGROUND "\x1b[34m"
#define ANSI_MAGENTA_FOREGROUND "\x1b[35m"
#define ANSI_CYAN_FOREGROUND "\x1b[36m"
#define ANSI_WHITE_FOREGROUND "\x1b[37m"
#define ANSI_CLEAR_SCREEN "\x1b[2J"
#ifndef __cplusplus
// Convenient macros - Used only in C
#define ANSI_PRINTF_IN_BLACK(x, ...) printf(ANSI_BLACK_FOREGROUND x ANSI_RESET, ##__VA_ARGS__)
#define ANSI_PRINTF_IN_RED(x, ...) printf(ANSI_RED_FOREGROUND x ANSI_RESET, ##__VA_ARGS__)
#define ANSI_PRINTF_IN_GREEN(x, ...) printf(ANSI_GREEN_FOREGROUND x ANSI_RESET, ##__VA_ARGS__)
#define ANSI_PRINTF_IN_YELLOW(x, ...) printf(ANSI_YELLOW_FOREGROUND x ANSI_RESET, ##__VA_ARGS__)
#define ANSI_PRINTF_IN_BLUE(x, ...) printf(ANSI_BLUE_FOREGROUND x ANSI_RESET, ##__VA_ARGS__)
#define ANSI_PRINTF_IN_MAGENTA(x, ...) printf(ANSI_MAGENTA_FOREGROUND x ANSI_RESET, ##__VA_ARGS__)
#define ANSI_PRINTF_IN_CYAN(x, ...) printf(ANSI_CYAN_FOREGROUND x ANSI_RESET, ##__VA_ARGS__)
#define ANSI_PRINTF_IN_WHITE(x, ...) printf(ANSI_WHITE_FOREGROUND x ANSI_RESET, ##__VA_ARGS__)
#define ANSI_CLEAR_CONSOLE() printf(ANSI_CLEAR_SCREEN "\n")
#endif /* __cplusplus */
#endif /* WBU_ANSI_CODES_H */

View File

@ -0,0 +1,47 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for Motion file playback */
/**********************************************************************************/
#ifndef WBU_MOTION_H
#define WBU_MOTION_H
#include "../types.h"
#ifdef __cplusplus
extern "C" {
#endif
WbMotionRef wbu_motion_new(const char *filename);
void wbu_motion_delete(WbMotionRef motion);
void wbu_motion_play(WbMotionRef motion);
void wbu_motion_stop(WbMotionRef motion);
void wbu_motion_set_loop(WbMotionRef motion, bool loop);
void wbu_motion_set_reverse(WbMotionRef motion, bool reverse);
bool wbu_motion_is_over(WbMotionRef motion);
int wbu_motion_get_duration(WbMotionRef motion);
int wbu_motion_get_time(WbMotionRef motion);
void wbu_motion_set_time(WbMotionRef motion, int time);
#ifdef __cplusplus
}
#endif
#endif /* WBU_MOTION_H */

View File

@ -0,0 +1,35 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C utility to parse messages */
/**********************************************************************************/
#ifndef WBU_STRING_H
#define WBU_STRING_H
#ifdef __cplusplus
extern "C" {
#endif
char *wbu_string_strsep(char **stringp, const char *delim);
char *wbu_string_replace(char *value, const char *before, const char *after);
#ifdef __cplusplus
}
#endif
#endif // WBU_STRING_H

View File

@ -0,0 +1,55 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/************************************************************************************/
/* Description: Webots C programming interface for cross-platform system functions */
/************************************************************************************/
#ifndef WBU_SYSTEM_H
#define WBU_SYSTEM_H
#include "../types.h"
#ifdef __cplusplus
extern "C" {
#endif
// wbu_system_getenv() returns an UTF-8 multi-byte string for the specified
// environment variable.
// The return value points to a char buffer which may be overwritten by any subsequent
// call to a wbu_system function.
const char *wbu_system_getenv(const char *variable);
// On Linux and macOS, wbu_system_short_path() returns the variable passed as an
// argument. On Windows, it returns an ASCII string corresponding to the Windows 8.3
// short path (see GetShortPathName in the Windows API). This is useful when using a
// library that doesn't support UTF-8 multi-byte strings or wide characters for paths.
// The return value points to a char buffer which may be overwritten by any subsequent
// call to a wbu_system function.
const char *wbu_system_short_path(const char *path);
// Return the system tmp folder used by Webots, typically /tmp on Linux
const char *wbu_system_tmpdir();
// The following function returns the folder used by the current instance of Webots. On Linux, it is /tmp/webots-XXX.
// On macOS is it /var/tmp/webots-XXX. On Windows, it is LOCALAPPDATA/Temp/webots-XXX where XXX is the Webots TCP port
const char *wbu_system_webots_instance_path(bool refresh);
#ifdef __cplusplus
}
#endif
#endif /* WBU_SYSTEM_H */

View File

@ -0,0 +1,43 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**********************************************************************************/
/* Description: Webots C programming interface for the VacuumGripper node */
/**********************************************************************************/
#ifndef WB_VACUUM_GRIPPER_H
#define WB_VACUUM_GRIPPER_H
#define WB_USING_C_API
#include "types.h"
#ifdef __cplusplus
extern "C" {
#endif
void wb_vacuum_gripper_enable_presence(WbDeviceTag tag, int sampling_period);
void wb_vacuum_gripper_disable_presence(WbDeviceTag tag);
int wb_vacuum_gripper_get_presence_sampling_period(WbDeviceTag tag);
bool wb_vacuum_gripper_get_presence(WbDeviceTag tag);
void wb_vacuum_gripper_turn_on(WbDeviceTag tag);
void wb_vacuum_gripper_turn_off(WbDeviceTag tag);
bool wb_vacuum_gripper_is_on(WbDeviceTag tag);
#ifdef __cplusplus
}
#endif
#endif /* WB_VACUUM_GRIPPER_H */

View File

@ -0,0 +1,87 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Description: Car library to be used with the 'Car' proto (or any proto inherited by 'Car')
* Comments: Sponsored by the CTI project RO2IVSim
* (http://transport.epfl.ch/simulator-for-mobile-robots-and-intelligent-vehicles)
*/
#ifndef CAR_H
#define CAR_H
#include <webots/types.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum { WBU_CAR_TRACTION = 0, WBU_CAR_PROPULSION = 1, WBU_CAR_FOUR_BY_FOUR = 2 } WbuCarType;
typedef enum {
WBU_CAR_COMBUSTION_ENGINE = 0,
WBU_CAR_ELECTRIC_ENGINE = 1,
WBU_CAR_PARALLEL_HYBRID_ENGINE = 2,
WBU_CAR_POWER_SPLIT_HYBRID_ENGINE = 3
} WbuCarEngineType;
typedef enum {
WBU_CAR_WHEEL_FRONT_RIGHT = 0,
WBU_CAR_WHEEL_FRONT_LEFT = 1,
WBU_CAR_WHEEL_REAR_RIGHT = 2,
WBU_CAR_WHEEL_REAR_LEFT = 3,
WBU_CAR_WHEEL_NB
} WbuCarWheelIndex;
void wbu_car_init();
void wbu_car_cleanup();
WbuCarType wbu_car_get_type();
WbuCarEngineType wbu_car_get_engine_type();
void wbu_car_set_indicator_period(double period);
double wbu_car_get_indicator_period();
bool wbu_car_get_backwards_lights();
bool wbu_car_get_brake_lights();
double wbu_car_get_track_front();
double wbu_car_get_track_rear();
double wbu_car_get_wheelbase();
double wbu_car_get_front_wheel_radius();
double wbu_car_get_rear_wheel_radius();
double wbu_car_get_wheel_encoder(WbuCarWheelIndex wheel_index);
double wbu_car_get_wheel_speed(WbuCarWheelIndex wheel_index);
void wbu_car_set_left_steering_angle(double angle);
void wbu_car_set_right_steering_angle(double angle);
double wbu_car_get_right_steering_angle();
double wbu_car_get_left_steering_angle();
void wbu_car_enable_limited_slip_differential(bool enable);
void wbu_car_enable_indicator_auto_disabling(bool enable);
// kept for backward compatibility (Webots R2018a)
typedef WbuCarType wbu_car_type;
typedef WbuCarEngineType wbu_car_engine_type;
typedef WbuCarWheelIndex wbu_car_wheel_index;
#ifdef __cplusplus
}
#endif
#endif // CAR_H

View File

@ -0,0 +1,97 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Description: Driver library to be used with the 'Car' proto (or any proto inherited by 'Car') and the car library
* Comments: Sponsored by the CTI project RO2IVSim
* (http://transport.epfl.ch/simulator-for-mobile-robots-and-intelligent-vehicles)
*/
#ifndef DRIVER_H
#define DRIVER_H
#include <webots/types.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum { OFF, RIGHT, LEFT } WbuDriverIndicatorState;
typedef enum { UNDEFINED_CONTROL_MODE = -1, SPEED = 0, TORQUE } WbuDriverControlMode;
typedef enum { DOWN, SLOW, NORMAL, FAST } WbuDriverWiperMode;
// private function for webots_ros2 to identify robots that can use libdriver
bool wbu_driver_initialization_is_possible();
void wbu_driver_init();
void wbu_driver_cleanup();
int wbu_driver_step();
// positive: turn right, negative: turn left
void wbu_driver_set_steering_angle(double steering_angle);
double wbu_driver_get_steering_angle();
void wbu_driver_set_cruising_speed(double speed);
double wbu_driver_get_target_cruising_speed();
double wbu_driver_get_current_speed();
void wbu_driver_set_throttle(double throttle);
double wbu_driver_get_throttle();
void wbu_driver_set_brake_intensity(double intensity);
double wbu_driver_get_brake_intensity();
void wbu_driver_set_indicator(WbuDriverIndicatorState state);
void wbu_driver_set_hazard_flashers(bool state);
WbuDriverIndicatorState wbu_driver_get_indicator();
bool wbu_driver_get_hazard_flashers();
void wbu_driver_set_dipped_beams(bool state);
void wbu_driver_set_antifog_lights(bool state);
bool wbu_driver_get_dipped_beams();
bool wbu_driver_get_antifog_lights();
double wbu_driver_get_rpm();
int wbu_driver_get_gear();
void wbu_driver_set_gear(int gear);
int wbu_driver_get_gear_number();
WbuDriverControlMode wbu_driver_get_control_mode();
void wbu_driver_set_wiper_mode(WbuDriverWiperMode mode);
WbuDriverWiperMode wbu_driver_get_wiper_mode();
// kept for backward compatibility (Webots 8.6)
void wbu_driver_set_brake(double brake) WB_DEPRECATED;
double wbu_driver_get_brake() WB_DEPRECATED;
// kept for backward compatibility (Webots R2018a)
typedef WbuDriverWiperMode wbu_wipers_mode;
typedef WbuDriverIndicatorState wbu_indicator_state;
typedef WbuDriverControlMode wbu_control_mode;
typedef WbuDriverWiperMode wbu_wipers_mode;
void wbu_driver_set_wipers_mode(wbu_wipers_mode mode) WB_DEPRECATED;
wbu_wipers_mode wbu_driver_get_wipers_mode() WB_DEPRECATED;
#ifdef __cplusplus
}
#endif
#endif // DRIVER_H

View File

@ -0,0 +1,35 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ACCELEROMETER_HPP
#define ACCELEROMETER_HPP
#include <webots/Device.hpp>
namespace webots {
class Accelerometer : public Device {
public:
explicit Accelerometer(const std::string &name) : Device(name) {} // Use Robot::getAccelerometer() instead
explicit Accelerometer(WbDeviceTag tag) : Device(tag) {}
virtual ~Accelerometer() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
const double *getValues() const;
int getLookupTableSize() const;
const double *getLookupTable() const;
};
} // namespace webots
#endif // ACCELEROMETER_HPP

View File

@ -0,0 +1,33 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ALTIMETER_HPP
#define ALTIMETER_HPP
#include <webots/Device.hpp>
namespace webots {
class Altimeter : public Device {
public:
explicit Altimeter(const std::string &name) : Device(name) {} // Use Robot::getAltimeter instead
explicit Altimeter(WbDeviceTag tag) : Device(tag) {}
virtual ~Altimeter() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
double getValue() const;
};
} // namespace webots
#endif // ALTIMETER_HPP

View File

@ -0,0 +1,55 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef BRAKE_HPP
#define BRAKE_HPP
#include <stdio.h>
#include <webots/Device.hpp>
namespace webots {
class Motor;
class PositionSensor;
class Brake : public Device {
public:
typedef enum { ROTATIONAL = 0, LINEAR } Type;
explicit Brake(const std::string &name) :
Device(name),
motor(NULL),
positionSensor(NULL) {} // Use Robot::getBrake() instead
explicit Brake(WbDeviceTag tag) : Device(tag), motor(NULL), positionSensor(NULL) {}
virtual ~Brake() {}
Type getType() const;
void setDampingConstant(double dampingConstant) const;
Motor *getMotor();
PositionSensor *getPositionSensor();
// internal functions
int getMotorTag() const;
int getPositionSensorTag() const;
enum { // kept for backward compatibility R2018b
ANGULAR = 0
};
private:
Motor *motor;
PositionSensor *positionSensor;
};
} // namespace webots
#endif // BRAKE_HPP

View File

@ -0,0 +1,68 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CAMERA_HPP
#define CAMERA_HPP
#include <webots/Device.hpp>
#include "../../c/webots/camera_recognition_object.h"
namespace webots {
typedef WbCameraRecognitionObject CameraRecognitionObject;
class Camera : public Device {
public:
explicit Camera(const std::string &name) : Device(name) {} // Use Robot::getCamera() instead
explicit Camera(WbDeviceTag tag) : Device(tag) {}
virtual ~Camera() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
const unsigned char *getImage() const;
int getWidth() const;
int getHeight() const;
double getFov() const;
double getMaxFov() const;
double getMinFov() const;
virtual void setFov(double fov);
double getExposure() const;
void setExposure(double exposure);
double getFocalLength() const;
double getFocalDistance() const;
double getMaxFocalDistance() const;
double getMinFocalDistance() const;
virtual void setFocalDistance(double focalDistance);
double getNear() const;
int saveImage(const std::string &filename, int quality) const;
bool hasRecognition() const;
void recognitionEnable(int samplingPeriod);
void recognitionDisable();
int getRecognitionSamplingPeriod() const;
int getRecognitionNumberOfObjects() const;
const CameraRecognitionObject *getRecognitionObjects() const;
bool hasRecognitionSegmentation() const;
void enableRecognitionSegmentation();
void disableRecognitionSegmentation();
bool isRecognitionSegmentationEnabled() const;
const unsigned char *getRecognitionSegmentationImage() const;
int saveRecognitionSegmentationImage(const std::string &filename, int quality) const;
static unsigned char imageGetRed(const unsigned char *image, int width, int x, int y);
static unsigned char imageGetGreen(const unsigned char *image, int width, int x, int y);
static unsigned char imageGetBlue(const unsigned char *image, int width, int x, int y);
static unsigned char imageGetGray(const unsigned char *image, int width, int x, int y);
// alias
static unsigned char imageGetGrey(const unsigned char *image, int width, int x, int y);
};
} // namespace webots
#endif // CAMERA_HPP

View File

@ -0,0 +1,35 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef COMPASS_HPP
#define COMPASS_HPP
#include <webots/Device.hpp>
namespace webots {
class Compass : public Device {
public:
explicit Compass(const std::string &name) : Device(name) {} // Use Robot::getCompass() instead
explicit Compass(WbDeviceTag tag) : Device(tag) {}
virtual ~Compass() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
const double *getValues() const;
int getLookupTableSize() const;
const double *getLookupTable() const;
};
} // namespace webots
#endif // COMPASS_HPP

View File

@ -0,0 +1,36 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CONNECTOR_HPP
#define CONNECTOR_HPP
#include <webots/Device.hpp>
namespace webots {
class Connector : public Device {
public:
explicit Connector(const std::string &name) : Device(name) {} // Use Robot::getConnector() instead
explicit Connector(WbDeviceTag tag) : Device(tag) {}
virtual ~Connector() {}
virtual void enablePresence(int samplingPeriod);
virtual void disablePresence();
int getPresenceSamplingPeriod() const;
int getPresence() const;
bool isLocked() const;
virtual void lock();
virtual void unlock();
};
} // namespace webots
#endif // CONNECTOR_HPP

View File

@ -0,0 +1,43 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef DEVICE_HPP
#define DEVICE_HPP
#define WB_USING_CPP_API
#include <string>
#include "../../c/webots/types.h"
namespace webots {
class Device {
public:
virtual ~Device() {}
const std::string &getName() const { return name; }
std::string getModel() const;
int getNodeType() const;
int getTag() const { return tag; }
static bool hasType(int tag, int type);
protected:
explicit Device(const std::string &name);
explicit Device(WbDeviceTag tag);
private:
WbDeviceTag tag;
std::string name;
};
} // namespace webots
#endif // DEVICE_HPP

View File

@ -0,0 +1,54 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef DISPLAY_HPP
#define DISPLAY_HPP
#include <webots/Device.hpp>
#include <webots/ImageRef.hpp>
namespace webots {
class Camera;
class Display : public Device {
public:
enum { RGB = 3, RGBA, ARGB, BGRA, ABGR };
explicit Display(const std::string &name) : Device(name) {} // Use Robot::getDisplay() instead
explicit Display(WbDeviceTag tag) : Device(tag) {}
virtual ~Display() {}
int getWidth() const;
int getHeight() const;
virtual void setColor(int color);
virtual void setAlpha(double alpha);
virtual void setOpacity(double opacity);
virtual void setFont(const std::string &font, int size, bool antiAliasing);
virtual void attachCamera(Camera *camera);
virtual void detachCamera();
virtual void drawPixel(int x1, int y1);
virtual void drawLine(int x1, int y1, int x2, int y2);
virtual void drawRectangle(int x, int y, int width, int height);
virtual void drawOval(int cx, int cy, int a, int b);
virtual void drawPolygon(const int *x, const int *y, int size);
virtual void drawText(const std::string &txt, int x, int y);
virtual void fillRectangle(int x, int y, int width, int height);
virtual void fillOval(int cx, int cy, int a, int b);
virtual void fillPolygon(const int *x, const int *y, int size);
ImageRef *imageNew(int width, int height, const void *data, int format) const;
ImageRef *imageCopy(int x, int y, int width, int height) const;
virtual void imagePaste(ImageRef *ir, int x, int y, bool blend = false);
ImageRef *imageLoad(const std::string &filename) const;
void imageSave(ImageRef *ir, const std::string &filename) const;
void imageDelete(ImageRef *ir) const;
};
} // namespace webots
#endif // DISPLAY_HPP

View File

@ -0,0 +1,41 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef DISTANCESENSOR_HPP
#define DISTANCESENSOR_HPP
#include <webots/Device.hpp>
namespace webots {
class DistanceSensor : public Device {
public:
typedef enum { GENERIC = 0, INFRA_RED, SONAR, LASER } Type;
explicit DistanceSensor(const std::string &name) : Device(name) {} // Use Robot::getDistanceSensor() instead
explicit DistanceSensor(WbDeviceTag tag) : Device(tag) {}
virtual ~DistanceSensor() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
double getValue() const;
double getMaxValue() const;
double getMinValue() const;
double getAperture() const;
int getLookupTableSize() const;
const double *getLookupTable() const;
Type getType() const;
};
} // namespace webots
#endif // DISTANCESENSOR_HPP

View File

@ -0,0 +1,36 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef EMITTER_HPP
#define EMITTER_HPP
#include <webots/Device.hpp>
namespace webots {
class Emitter : public Device {
public:
explicit Emitter(const std::string &name) : Device(name) {} // Use Robot::getEmitter() instead
explicit Emitter(WbDeviceTag tag) : Device(tag) {}
virtual ~Emitter() {}
enum { CHANNEL_BROADCAST = -1 };
virtual int send(const void *data, int size);
int getBufferSize() const;
virtual void setChannel(int channel);
int getChannel() const;
double getRange() const;
virtual void setRange(double range);
};
} // namespace webots
#endif // EMITTER_HPP

View File

@ -0,0 +1,128 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef FIELD_HPP
#define FIELD_HPP
#define WB_USING_CPP_API
#include <string>
#include <webots/Node.hpp>
#include "../../c/webots/types.h"
#ifdef MF_STRING
#undef MF_STRING
#endif
namespace webots {
class Node;
class Field {
public:
typedef enum {
NO_FIELD = 0x00,
SF_BOOL = 0x01,
SF_INT32,
SF_FLOAT,
SF_VEC2F,
SF_VEC3F,
SF_ROTATION,
SF_COLOR,
SF_STRING,
SF_NODE,
MF = 0x10,
MF_BOOL,
MF_INT32,
MF_FLOAT,
MF_VEC2F,
MF_VEC3F,
MF_ROTATION,
MF_COLOR,
MF_STRING,
MF_NODE
} Type;
std::string getName() const;
Type getType() const;
std::string getTypeName() const;
int getCount() const;
Field *getActualField() const;
void enableSFTracking(int samplingPeriod);
void disableSFTracking();
bool getSFBool() const;
int getSFInt32() const;
double getSFFloat() const;
const double *getSFVec2f() const;
const double *getSFVec3f() const;
const double *getSFRotation() const;
const double *getSFColor() const;
std::string getSFString() const;
Node *getSFNode() const;
bool getMFBool(int index) const;
int getMFInt32(int index) const;
double getMFFloat(int index) const;
const double *getMFVec2f(int index) const;
const double *getMFVec3f(int index) const;
const double *getMFRotation(int index) const;
const double *getMFColor(int index) const;
std::string getMFString(int index) const;
Node *getMFNode(int index) const;
void setSFBool(bool value);
void setSFInt32(int value);
void setSFFloat(double value);
void setSFVec2f(const double values[2]);
void setSFVec3f(const double values[3]);
void setSFRotation(const double values[4]);
void setSFColor(const double values[3]);
void setSFString(const std::string &value);
void setMFBool(int index, bool value);
void setMFInt32(int index, int value);
void setMFFloat(int index, double value);
void setMFVec2f(int index, const double values[2]);
void setMFVec3f(int index, const double values[3]);
void setMFRotation(int index, const double values[4]);
void setMFColor(int index, const double values[3]);
void setMFString(int index, const std::string &value);
void insertMFBool(int index, bool value);
void insertMFInt32(int index, int value);
void insertMFFloat(int index, double value);
void insertMFVec2f(int index, const double values[2]);
void insertMFVec3f(int index, const double values[3]);
void insertMFRotation(int index, const double values[4]);
void insertMFColor(int index, const double values[3]);
void insertMFString(int index, const std::string &value);
void removeMF(int index);
void removeSF();
void importMFNodeFromString(int position, const std::string &nodeString);
void importSFNodeFromString(const std::string &nodeString);
// DO NOT USE THESE FUNCTIONS: THEY ARE RESERVED FOR INTERNAL USE:
static Field *findField(WbFieldRef ref);
static void cleanup();
private:
Field(WbFieldRef ref);
~Field() {}
WbFieldRef fieldRef;
};
} // namespace webots
#endif // FIELD_HPP

View File

@ -0,0 +1,43 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GPS_HPP
#define GPS_HPP
#include <webots/Device.hpp>
namespace webots {
class GPS : public Device {
public:
typedef enum { LOCAL = 0, WGS84 } CoordinateSystem;
explicit GPS(const std::string &name) : Device(name) {} // Use Robot::getGPS() instead
explicit GPS(WbDeviceTag tag) : Device(tag) {}
virtual ~GPS() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
const double *getValues() const;
double getSpeed() const;
const double *getSpeedVector() const;
const CoordinateSystem getCoordinateSystem() const;
static std::string convertToDegreesMinutesSeconds(double decimalDegree);
};
} // namespace webots
#endif // GPS_HPP

View File

@ -0,0 +1,35 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GYRO_HPP
#define GYRO_HPP
#include <webots/Device.hpp>
namespace webots {
class Gyro : public Device {
public:
explicit Gyro(const std::string &name) : Device(name) {} // Use Robot::getGyro() instead
explicit Gyro(WbDeviceTag tag) : Device(tag) {}
virtual ~Gyro() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
const double *getValues() const;
int getLookupTableSize() const;
const double *getLookupTable() const;
};
} // namespace webots
#endif // GYRO_HPP

View File

@ -0,0 +1,34 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef IMAGE_REF_HPP
#define IMAGE_REF_HPP
#define WB_USING_CPP_API
#include "../../c/webots/types.h"
namespace webots {
class ImageRef {
public:
// Use Display::imageNew(), Display::imageCopy() or Display::imageLoad() instead
explicit ImageRef(const WbImageRef &imageRef) : imageRef(imageRef) {}
// Use Display::imageDelete() instead
virtual ~ImageRef() {}
WbImageRef getImageRef() { return imageRef; }
private:
WbImageRef imageRef;
};
} // namespace webots
#endif // IMAGE_REF_HPP

View File

@ -0,0 +1,35 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef INERTIAL_UNIT_HPP
#define INERTIAL_UNIT_HPP
#include <webots/Device.hpp>
namespace webots {
class InertialUnit : public Device {
public:
explicit InertialUnit(const std::string &name) : Device(name) {} // Use Robot::getInertialUnit() instead
explicit InertialUnit(WbDeviceTag tag) : Device(tag) {}
virtual ~InertialUnit() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
const double *getRollPitchYaw() const;
const double *getQuaternion() const;
double getNoise() const;
};
} // namespace webots
#endif // INERTIAL_UNIT_HPP

View File

@ -0,0 +1,43 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef JOYSTICK_HPP
#define JOYSTICK_HPP
#include <string>
namespace webots {
class Joystick {
public:
Joystick() {} // Use Robot::getJoystick() instead
virtual ~Joystick() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
bool isConnected() const;
std::string getModel() const;
int getNumberOfAxes() const;
int getAxisValue(int axis) const;
int getNumberOfPovs() const;
int getPovValue(int pov) const;
int getPressedButton() const;
void setConstantForce(int level);
void setConstantForceDuration(double duration);
void setAutoCenteringGain(double gain);
void setResistanceGain(double gain);
void setForceAxis(int axis);
};
} // namespace webots
#endif // JOYSTICK_HPP

View File

@ -0,0 +1,51 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef KEYBOARD_HPP
#define KEYBOARD_HPP
namespace webots {
class Keyboard {
public:
enum {
END = 312,
HOME,
LEFT,
UP,
RIGHT,
DOWN,
PAGEUP = 366,
PAGEDOWN,
NUMPAD_HOME = 375,
NUMPAD_LEFT,
NUMPAD_UP,
NUMPAD_RIGHT,
NUMPAD_DOWN,
NUMPAD_END = 382,
KEY = 0x0000ffff,
SHIFT = 0x00010000,
CONTROL = 0x00020000,
ALT = 0x00040000
};
Keyboard() {} // Use Robot::getKeyboard() instead
virtual ~Keyboard() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
int getKey() const;
};
} // namespace webots
#endif // KEYBOARD_HPP

View File

@ -0,0 +1,31 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LED_HPP
#define LED_HPP
#include <webots/Device.hpp>
namespace webots {
class LED : public Device {
public:
explicit LED(const std::string &name) : Device(name) {} // Use Robot::getLED() instead
explicit LED(WbDeviceTag tag) : Device(tag) {}
virtual ~LED() {}
virtual void set(int value);
int get() const;
};
} // namespace webots
#endif // LED_HPP

View File

@ -0,0 +1,52 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LIDAR_HPP
#define LIDAR_HPP
#include <webots/Device.hpp>
#include "../../c/webots/lidar_point.h"
namespace webots {
typedef WbLidarPoint LidarPoint;
class Lidar : public Device {
public:
explicit Lidar(const std::string &name) : Device(name) {} // Use Robot::getLidar() instead
explicit Lidar(WbDeviceTag tag) : Device(tag) {}
virtual ~Lidar() {}
virtual void enable(int samplingPeriod);
void enablePointCloud();
virtual void disable();
void disablePointCloud();
int getSamplingPeriod() const;
bool isPointCloudEnabled() const;
const float *getRangeImage() const;
const float *getLayerRangeImage(int layer) const;
const LidarPoint *getPointCloud() const;
const LidarPoint *getLayerPointCloud(int layer) const;
int getNumberOfPoints() const;
int getHorizontalResolution() const;
int getNumberOfLayers() const;
double getMinFrequency() const;
double getMaxFrequency() const;
double getFrequency() const;
void setFrequency(double frequency);
double getFov() const;
double getVerticalFov() const;
double getMinRange() const;
double getMaxRange() const;
};
} // namespace webots
#endif // LIDAR_HPP

View File

@ -0,0 +1,35 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LIGHTSENSOR_HPP
#define LIGHTSENSOR_HPP
#include <webots/Device.hpp>
namespace webots {
class LightSensor : public Device {
public:
explicit LightSensor(const std::string &name) : Device(name) {} // Use Robot::getLightSensor() instead
explicit LightSensor(WbDeviceTag tag) : Device(tag) {}
virtual ~LightSensor() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
double getValue() const;
int getLookupTableSize() const;
const double *getLookupTable() const;
};
} // namespace webots
#endif // LIGHTSENSOR_HPP

View File

@ -0,0 +1,84 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MOTOR_HPP
#define MOTOR_HPP
#include <webots/Device.hpp>
#include <math.h> // for 'INFINITY'
namespace webots {
class Brake;
class PositionSensor;
class Motor : public Device {
public:
typedef enum { ROTATIONAL = 0, LINEAR } Type;
explicit Motor(const std::string &name) :
Device(name),
brake(NULL),
positionSensor(NULL) {} // Use Robot::getMotor() instead
explicit Motor(WbDeviceTag tag) : Device(tag), brake(NULL), positionSensor(NULL) {}
virtual ~Motor() {}
virtual void setPosition(double position);
virtual void setVelocity(double vel);
virtual void setAcceleration(double acceleration);
virtual void setAvailableForce(double availableForce);
virtual void setAvailableTorque(double availableTorque);
virtual void setControlPID(double p, double i, double d);
double getTargetPosition() const;
double getMinPosition() const;
double getMaxPosition() const;
double getVelocity() const;
double getMaxVelocity() const;
double getAcceleration() const;
double getAvailableForce() const;
double getMaxForce() const;
double getAvailableTorque() const;
double getMaxTorque() const;
double getMultiplier() const;
virtual void enableForceFeedback(int samplingPeriod);
virtual void disableForceFeedback();
int getForceFeedbackSamplingPeriod() const;
double getForceFeedback() const;
virtual void enableTorqueFeedback(int samplingPeriod);
virtual void disableTorqueFeedback();
int getTorqueFeedbackSamplingPeriod() const;
double getTorqueFeedback() const;
virtual void setForce(double force);
virtual void setTorque(double torque);
Type getType() const;
Brake *getBrake();
PositionSensor *getPositionSensor();
// internal functions
int getBrakeTag() const;
int getPositionSensorTag() const;
private:
Brake *brake;
PositionSensor *positionSensor;
};
} // namespace webots
#endif // MOTOR_HPP

View File

@ -0,0 +1,37 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MOUSE_HPP
#define MOUSE_HPP
#include "../../c/webots/mouse_state.h"
namespace webots {
typedef WbMouseState MouseState;
class Mouse {
public:
Mouse() {} // Use Robot::getMouse() instead
virtual ~Mouse() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
void enable3dPosition();
void disable3dPosition();
bool is3dPositionEnabled() const;
MouseState getState() const;
};
} // namespace webots
#endif // MOUSE_HPP

View File

@ -0,0 +1,193 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef NODE_HPP
#define NODE_HPP
#define WB_USING_CPP_API
#include <string>
#include <webots/Field.hpp>
#include <webots/Proto.hpp>
#include "../../c/webots/contact_point.h"
#include "../../c/webots/types.h"
// Note: should match with node.h
namespace webots {
typedef WbContactPoint ContactPoint;
class Field;
class Proto;
class Node {
public:
typedef enum {
NO_NODE,
// 3D rendering
APPEARANCE,
BACKGROUND,
BILLBOARD,
BOX,
CAD_SHAPE,
CAPSULE,
COLOR,
CONE,
COORDINATE,
CYLINDER,
DIRECTIONAL_LIGHT,
ELEVATION_GRID,
FOG,
GROUP,
IMAGE_TEXTURE,
INDEXED_FACE_SET,
INDEXED_LINE_SET,
MATERIAL,
MESH,
MUSCLE,
NORMAL,
PBR_APPEARANCE,
PLANE,
POINT_LIGHT,
POINT_SET,
POSE,
SHAPE,
SPHERE,
SPOT_LIGHT,
TEXTURE_COORDINATE,
TEXTURE_TRANSFORM,
TRANSFORM,
VIEWPOINT,
// robots
ROBOT,
// devices
ACCELEROMETER,
ALTIMETER,
BRAKE,
CAMERA,
COMPASS,
CONNECTOR,
DISPLAY,
DISTANCE_SENSOR,
EMITTER,
GPS,
GYRO,
INERTIAL_UNIT,
LED,
LIDAR,
LIGHT_SENSOR,
LINEAR_MOTOR,
PEN,
POSITION_SENSOR,
PROPELLER,
RADAR,
RANGE_FINDER,
RECEIVER,
ROTATIONAL_MOTOR,
SKIN,
SPEAKER,
TOUCH_SENSOR,
VACUUM_GRIPPER,
// misc
BALL_JOINT,
BALL_JOINT_PARAMETERS,
CHARGER,
CONTACT_PROPERTIES,
DAMPING,
FLUID,
FOCUS,
HINGE_JOINT,
HINGE_JOINT_PARAMETERS,
HINGE_2_JOINT,
IMMERSION_PROPERTIES,
JOINT_PARAMETERS,
LENS,
LENS_FLARE,
PHYSICS,
RECOGNITION,
SLIDER_JOINT,
SLOT,
SOLID,
SOLID_REFERENCE,
TRACK,
TRACK_WHEEL,
WORLD_INFO,
ZOOM,
// experimental
MICROPHONE,
RADIO
} Type;
virtual void remove();
int getId() const;
Type getType() const;
std::string getDef() const;
std::string getTypeName() const;
std::string getBaseTypeName() const;
Node *getParentNode() const;
bool isProto() const;
Proto *getProto() const;
Node *getFromProtoDef(const std::string &name) const;
int getNumberOfFields() const;
int getNumberOfBaseNodeFields() const;
Field *getField(const std::string &fieldName) const;
Field *getBaseNodeField(const std::string &fieldName) const;
Field *getFieldByIndex(const int index) const;
Field *getBaseNodeFieldByIndex(const int index) const;
const double *getPosition() const;
const double *getOrientation() const;
const double *getPose() const;
const double *getPose(const Node *fromNode) const;
void enableContactPointsTracking(int samplingPeriod, bool includeDescendants = false) const;
void disableContactPointsTracking(bool includeDescendants = false) const;
void enablePoseTracking(int samplingPeriod) const;
void disablePoseTracking() const;
void enablePoseTracking(int samplingPeriod, const Node *fromNode) const;
void disablePoseTracking(const Node *fromNode) const;
ContactPoint *getContactPoints(bool includeDescendants, int *size) const;
const double *getCenterOfMass() const;
const double *getContactPoint(int index) const;
Node *getContactPointNode(int index) const;
int getNumberOfContactPoints(bool includeDescendants = false) const;
bool getStaticBalance() const;
const double *getVelocity() const;
std::string exportString() const;
void setVelocity(const double velocity[6]);
void resetPhysics();
void restartController();
void moveViewpoint() const;
void setVisibility(Node *from, bool visible);
void addForce(const double force[3], bool relative);
void addForceWithOffset(const double force[3], const double offset[3], bool relative);
void addTorque(const double torque[3], bool relative);
void saveState(const std::string &stateName);
void loadState(const std::string &stateName);
void setJointPosition(double position, int index = 1);
// DO NOT USE THESE FUNCTIONS: THEY ARE RESERVED FOR INTERNAL USE:
static Node *findNode(WbNodeRef ref);
static void cleanup();
private:
Node(WbNodeRef nodeRef);
virtual ~Node() {}
WbNodeRef nodeRef;
};
} // namespace webots
#endif // NODE_HPP

View File

@ -0,0 +1,31 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef PEN_HPP
#define PEN_HPP
#include <webots/Device.hpp>
namespace webots {
class Pen : public Device {
public:
explicit Pen(const std::string &name) : Device(name) {} // Use Robot::getPen() instead
explicit Pen(WbDeviceTag tag) : Device(tag) {}
virtual ~Pen() {}
virtual void write(bool write);
virtual void setInkColor(int color, double density);
};
} // namespace webots
#endif // PEN_HPP

View File

@ -0,0 +1,57 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef POSITION_SENSOR_HPP
#define POSITION_SENSOR_HPP
#include <webots/Device.hpp>
namespace webots {
class Brake;
class Motor;
class PositionSensor : public Device {
public:
typedef enum { ROTATIONAL = 0, LINEAR } Type;
explicit PositionSensor(const std::string &name) :
Device(name),
brake(NULL),
motor(NULL) {} // Use Robot::getPositionSensor() instead
explicit PositionSensor(WbDeviceTag tag) : Device(tag), brake(NULL), motor(NULL) {}
virtual ~PositionSensor() {}
virtual void enable(int samplingPeriod); // milliseconds
virtual void disable();
int getSamplingPeriod() const;
double getValue() const; // rad or meters
Type getType() const;
Brake *getBrake();
Motor *getMotor();
// internal functions
int getBrakeTag() const;
int getMotorTag() const;
enum { // kept for backward compatibility R2018b
ANGULAR = 0
};
private:
Brake *brake;
Motor *motor;
};
} // namespace webots
#endif // POSITION_SENSOR_HPP

View File

@ -0,0 +1,46 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef PROTO_HPP
#define PROTO_HPP
#define WB_USING_CPP_API
#include <string>
#include <webots/Field.hpp>
#include "../../c/webots/types.h"
namespace webots {
class Field;
class Proto {
public:
std::string getTypeName() const;
bool isDerived() const;
Proto *getParent() const;
Field *getField(const std::string &fieldName) const;
Field *getFieldByIndex(const int index) const;
int getNumberOfFields() const;
// DO NOT USE THESE FUNCTIONS: THEY ARE RESERVED FOR INTERNAL USE:
static Proto *findProto(WbProtoRef ref);
static void cleanup();
private:
Proto(WbProtoRef ref);
~Proto() {}
WbProtoRef protoRef;
};
} // namespace webots
#endif // PROTO_HPP

View File

@ -0,0 +1,41 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef RADAR_HPP
#define RADAR_HPP
#include <webots/Device.hpp>
#include "../../c/webots/radar_target.h"
namespace webots {
typedef WbRadarTarget RadarTarget;
class Radar : public Device {
public:
explicit Radar(const std::string &name) : Device(name) {} // Use Robot::getRadar() instead
explicit Radar(WbDeviceTag tag) : Device(tag) {}
virtual ~Radar() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
int getNumberOfTargets() const;
const RadarTarget *getTargets() const;
double getMinRange() const;
double getMaxRange() const;
double getHorizontalFov() const;
double getVerticalFov() const;
};
} // namespace webots
#endif // RADAR_HPP

View File

@ -0,0 +1,39 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef RANGE_FINDER_HPP
#define RANGE_FINDER_HPP
#include <webots/Device.hpp>
namespace webots {
class RangeFinder : public Device {
public:
explicit RangeFinder(const std::string &name) : Device(name) {} // Use Robot::getRangeFinder() instead
explicit RangeFinder(WbDeviceTag tag) : Device(tag) {}
virtual ~RangeFinder() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
const float *getRangeImage() const;
int getWidth() const;
int getHeight() const;
double getFov() const;
double getMinRange() const;
double getMaxRange() const;
int saveImage(const std::string &filename, int quality) const;
static float rangeImageGetDepth(const float *image, int width, int x, int y);
};
} // namespace webots
#endif // RANGE_FINDER_HPP

View File

@ -0,0 +1,41 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef RECEIVER_HPP
#define RECEIVER_HPP
#include <webots/Device.hpp>
namespace webots {
class Receiver : public Device {
public:
explicit Receiver(const std::string &name) : Device(name) {} // Use Robot::getReceiver() instead
explicit Receiver(WbDeviceTag tag) : Device(tag) {}
virtual ~Receiver() {}
enum { CHANNEL_BROADCAST = -1 };
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
virtual void setChannel(int channel);
int getChannel() const;
int getQueueLength() const;
virtual void nextPacket();
int getDataSize() const;
const void *getData() const;
double getSignalStrength() const;
const double *getEmitterDirection() const;
};
} // namespace webots
#endif // RECEIVER_HPP

View File

@ -0,0 +1,181 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ROBOT_HPP
#define ROBOT_HPP
#include <iostream>
#include <vector>
#include "../../c/webots/types.h"
namespace webots {
class Accelerometer;
class Altimeter;
class Brake;
class Camera;
class Compass;
class Connector;
class DistanceSensor;
class Display;
class Device;
class Emitter;
class GPS;
class Gyro;
class InertialUnit;
class Joystick;
class Keyboard;
class LED;
class Lidar;
class LightSensor;
class Motor;
class Mouse;
class Pen;
class PositionSensor;
class Radar;
class RangeFinder;
class Receiver;
class Skin;
class Speaker;
class TouchSensor;
class VacuumGripper;
class Robot {
public:
typedef enum { MODE_SIMULATION = 0, MODE_CROSS_COMPILATION, MODE_REMOTE_CONTROL } Mode;
typedef enum {
EVENT_QUIT = -1,
EVENT_NO_EVENT = 0,
EVENT_MOUSE_CLICK = 1,
EVENT_MOUSE_MOVE = 2,
EVENT_KEYBOARD = 4,
EVENT_JOYSTICK_BUTTON = 8,
EVENT_JOYSTICK_AXIS = 16,
EVENT_JOYSTICK_POV = 32
} UserInputEvent;
Robot();
virtual ~Robot();
virtual int step(int duration);
int stepBegin(int duration);
int stepEnd();
UserInputEvent waitForUserInputEvent(UserInputEvent event_type, int timeout);
std::string getName() const;
std::string getUrdf(std::string prefix = "") const;
double getTime() const;
std::string getModel() const;
std::string getCustomData() const;
void setCustomData(const std::string &data);
Mode getMode() const;
void setMode(Mode, const char *);
bool getSupervisor() const;
bool getSynchronization() const;
std::string getProjectPath() const;
std::string getWorldPath() const;
double getBasicTimeStep() const;
int getNumberOfDevices() const;
Device *getDeviceByIndex(int index);
Device *getDevice(const std::string &name);
virtual void batterySensorEnable(int samplingPeriod);
virtual void batterySensorDisable();
int batterySensorGetSamplingPeriod() const;
double batterySensorGetValue() const;
Accelerometer *getAccelerometer(const std::string &name);
Altimeter *getAltimeter(const std::string &name);
Brake *getBrake(const std::string &name);
Camera *getCamera(const std::string &name);
Compass *getCompass(const std::string &name);
Connector *getConnector(const std::string &name);
Display *getDisplay(const std::string &name);
DistanceSensor *getDistanceSensor(const std::string &name);
Emitter *getEmitter(const std::string &name);
GPS *getGPS(const std::string &name);
Gyro *getGyro(const std::string &name);
InertialUnit *getInertialUnit(const std::string &name);
Joystick *getJoystick() { return mJoystick; }
Keyboard *getKeyboard() { return mKeyboard; }
LED *getLED(const std::string &name);
Lidar *getLidar(const std::string &name);
LightSensor *getLightSensor(const std::string &name);
Motor *getMotor(const std::string &name);
Mouse *getMouse() { return mMouse; }
Pen *getPen(const std::string &name);
PositionSensor *getPositionSensor(const std::string &name);
Radar *getRadar(const std::string &name);
RangeFinder *getRangeFinder(const std::string &name);
Receiver *getReceiver(const std::string &name);
Skin *getSkin(const std::string &name);
Speaker *getSpeaker(const std::string &name);
TouchSensor *getTouchSensor(const std::string &name);
VacuumGripper *getVacuumGripper(const std::string &name);
void *windowCustomFunction(void *arg);
void wwiSend(const char *data, int size);
void wwiSendText(const std::string &text);
const char *wwiReceive(int *size);
std::string wwiReceiveText();
// deprecated since Webots 2018a
std::string getData() const;
void setData(const std::string &data);
// internal functions
static Device *getDeviceFromTag(int tag);
static int getDeviceTypeFromTag(int tag);
static std::string getDeviceNameFromTag(int tag);
static int getDeviceTagFromIndex(int index);
static int getDeviceTagFromName(const std::string &name);
protected:
static Robot *cInstance;
virtual Accelerometer *createAccelerometer(WbDeviceTag tag) const;
virtual Altimeter *createAltimeter(WbDeviceTag tag) const;
virtual Brake *createBrake(WbDeviceTag tag) const;
virtual Camera *createCamera(WbDeviceTag tag) const;
virtual Compass *createCompass(WbDeviceTag tag) const;
virtual Connector *createConnector(WbDeviceTag tag) const;
virtual Display *createDisplay(WbDeviceTag tag) const;
virtual DistanceSensor *createDistanceSensor(WbDeviceTag tag) const;
virtual Emitter *createEmitter(WbDeviceTag tag) const;
virtual GPS *createGPS(WbDeviceTag tag) const;
virtual Gyro *createGyro(WbDeviceTag tag) const;
virtual InertialUnit *createInertialUnit(WbDeviceTag tag) const;
virtual LED *createLED(WbDeviceTag tag) const;
virtual Lidar *createLidar(WbDeviceTag tag) const;
virtual LightSensor *createLightSensor(WbDeviceTag tag) const;
virtual Motor *createMotor(WbDeviceTag tag) const;
virtual Pen *createPen(WbDeviceTag tag) const;
virtual PositionSensor *createPositionSensor(WbDeviceTag tag) const;
virtual Radar *createRadar(WbDeviceTag tag) const;
virtual RangeFinder *createRangeFinder(WbDeviceTag tag) const;
virtual Receiver *createReceiver(WbDeviceTag tag) const;
virtual Skin *createSkin(WbDeviceTag tag) const;
virtual Speaker *createSpeaker(WbDeviceTag tag) const;
virtual TouchSensor *createTouchSensor(WbDeviceTag tag) const;
virtual VacuumGripper *createVacuumGripper(WbDeviceTag tag) const;
private:
Keyboard *mKeyboard;
Joystick *mJoystick;
Mouse *mMouse;
Device *getOrCreateDevice(int tag);
static std::vector<Device *> deviceList;
};
} // namespace webots
#endif // ROBOT_HPP

View File

@ -0,0 +1,35 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SKIN_HPP
#define SKIN_HPP
#include <webots/Device.hpp>
namespace webots {
class Skin : public Device {
public:
explicit Skin(const std::string &name) : Device(name) {}
explicit Skin(WbDeviceTag tag) : Device(tag) {}
virtual ~Skin() {}
void setBoneOrientation(int index, const double orientation[4], bool absolute);
void setBonePosition(int index, const double position[3], bool absolute);
int getBoneCount() const;
const std::string getBoneName(int index) const;
const double *getBoneOrientation(int index, bool absolute) const;
const double *getBonePosition(int index, bool absolute) const;
};
} // namespace webots
#endif // SKIN_HPP

View File

@ -0,0 +1,39 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SPEAKER_HPP
#define SPEAKER_HPP
#include <webots/Device.hpp>
namespace webots {
class Speaker : public Device {
public:
explicit Speaker(const std::string &name) : Device(name) {} // Use Robot::getSpeaker() instead
explicit Speaker(WbDeviceTag tag) : Device(tag) {}
virtual ~Speaker() {}
static void playSound(Speaker *left, Speaker *right, const std::string &sound, double volume, double pitch, double balance,
bool loop);
bool isSoundPlaying(const std::string &sound) const;
void stop(const std::string &sound);
bool setEngine(const std::string &engine);
bool setLanguage(const std::string &language);
std::string getEngine();
std::string getLanguage();
void speak(const std::string &text, double volume);
bool isSpeaking() const;
};
} // namespace webots
#endif // SPEAKER_HPP

View File

@ -0,0 +1,90 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SUPERVISOR_HPP
#define SUPERVISOR_HPP
#include <webots/Device.hpp>
#include <webots/Node.hpp>
#include <webots/Robot.hpp>
namespace webots {
class Supervisor : public Robot {
public:
typedef enum { SIMULATION_MODE_PAUSE = 0, SIMULATION_MODE_REAL_TIME, SIMULATION_MODE_FAST } SimulationMode;
Supervisor() : Robot() {}
static Supervisor *getSupervisorInstance();
virtual ~Supervisor();
virtual void simulationQuit(int status);
virtual void simulationReset();
virtual void simulationResetPhysics();
SimulationMode simulationGetMode() const;
virtual void simulationSetMode(SimulationMode mode);
virtual void worldLoad(const std::string &file);
virtual void worldReload();
virtual bool worldSave();
virtual bool worldSave(const std::string &file);
void exportImage(const std::string &file, int quality) const;
virtual bool animationStartRecording(const std::string &file);
virtual bool animationStopRecording();
virtual void movieStartRecording(const std::string &file, int width, int height, int codec, int quality, int acceleration,
bool caption);
virtual void movieStopRecording();
bool movieIsReady() const;
bool movieFailed() const;
virtual void setLabel(int id, const std::string &label, double xpos, double ypos, double size, int color,
double transparency = 0, const std::string &font = "Arial");
Node *getRoot() const;
Node *getSelf() const;
Node *getFromDef(const std::string &name) const;
Node *getFromId(int id) const;
Node *getFromDevice(const Device *device) const;
Node *getFromDeviceTag(int tag) const;
Node *getSelected() const;
bool virtualRealityHeadsetIsUsed() const;
const double *virtualRealityHeadsetGetPosition() const;
const double *virtualRealityHeadsetGetOrientation() const;
// Deprecated functions
// Deprecated since Webots R2018b
virtual void simulationRevert(); // please use worldReload() instead
virtual void loadWorld(const std::string &file); // please use worldLoad() instead
virtual bool saveWorld(); // please use worldSave() instead
virtual bool saveWorld(const std::string &file); // please use worldSave() instead
// Deprecated since Webots 8.0.0, please use simulationResetPhysics() instead
virtual void simulationPhysicsReset();
// deprecated since webots 8.3.0: please use the wb_supervisor_movie_*() functions instead
virtual void startMovie(const std::string &file, int width, int height, int codec, int quality, int acceleration,
bool caption);
virtual void stopMovie();
int getMovieStatus();
// deprecated since Webots 8.4.0: please use movieIsReady() and movieFailed()
enum { MOVIE_READY = 0, MOVIE_RECORDING, MOVIE_SAVING, MOVIE_WRITE_ERROR, MOVIE_ENCODING_ERROR, MOVIE_SIMULATION_ERROR };
int movieGetStatus() const;
};
} // namespace webots
#endif // SUPERVISOR_HPP

View File

@ -0,0 +1,43 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef TOUCHSENSOR_HPP
#define TOUCHSENSOR_HPP
#include <webots/Device.hpp>
namespace webots {
class TouchSensor : public Device {
public:
typedef enum { BUMPER = 0, FORCE, FORCE3D } Type;
explicit TouchSensor(const std::string &name) : Device(name) {} // Use Robot::getTouchSensor() instead
explicit TouchSensor(WbDeviceTag tag) : Device(tag) {}
virtual ~TouchSensor() {}
virtual void enable(int samplingPeriod);
virtual void disable();
int getSamplingPeriod() const;
double getValue() const;
const double *getValues() const;
int getLookupTableSize() const;
const double *getLookupTable() const;
Type getType() const;
};
} // namespace webots
#endif // TOUCHSENSOR_HPP

View File

@ -0,0 +1,36 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef VACUUM_GRIPPER_HPP
#define VACUUM_GRIPPER_HPP
#include <webots/Device.hpp>
namespace webots {
class VacuumGripper : public Device {
public:
explicit VacuumGripper(const std::string &name) : Device(name) {} // Use Robot::getVacuumGripper() instead
explicit VacuumGripper(WbDeviceTag tag) : Device(tag) {}
virtual ~VacuumGripper() {}
virtual void enablePresence(int samplingPeriod);
virtual void disablePresence();
int getPresenceSamplingPeriod() const;
bool getPresence() const;
bool isOn() const;
virtual void turnOn();
virtual void turnOff();
};
} // namespace webots
#endif // VACUUM_GRIPPER_HPP

View File

@ -0,0 +1,47 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ANSICODES_HPP
#define ANSICODES_HPP
#include <string>
namespace webots {
namespace AnsiCodes {
static const std::string RESET = "\x1b[0m";
static const std::string BOLD = "\x1b[1m";
static const std::string UNDERLINE = "\x1b[4m";
static const std::string BLACK_FOREGROUND = "\x1b[30m";
static const std::string RED_FOREGROUND = "\x1b[31m";
static const std::string GREEN_FOREGROUND = "\x1b[32m";
static const std::string YELLOW_FOREGROUND = "\x1b[33m";
static const std::string BLUE_FOREGROUND = "\x1b[34m";
static const std::string MAGENTA_FOREGROUND = "\x1b[35m";
static const std::string CYAN_FOREGROUND = "\x1b[36m";
static const std::string WHITE_FOREGROUND = "\x1b[37m";
static const std::string BLACK_BACKGROUND = "\x1b[40m";
static const std::string RED_BACKGROUND = "\x1b[41m";
static const std::string GREEN_BACKGROUND = "\x1b[42m";
static const std::string YELLOW_BACKGROUND = "\x1b[43m";
static const std::string BLUE_BACKGROUND = "\x1b[44m";
static const std::string MAGENTA_BACKGROUND = "\x1b[45m";
static const std::string CYAN_BACKGROUND = "\x1b[46m";
static const std::string WHITE_BACKGROUND = "\x1b[47m";
static const std::string CLEAR_SCREEN = "\x1b[2J";
} // namespace AnsiCodes
} // namespace webots
#endif /* ANSICODES_HPP */

View File

@ -0,0 +1,45 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MOTION_HPP
#define MOTION_HPP
#define WB_USING_CPP_API
#include <string>
#include "../../../c/webots/types.h"
namespace webots {
class Motion {
public:
Motion(const std::string &fileName);
bool isValid() const;
virtual ~Motion();
virtual void play();
virtual void stop();
int getDuration() const;
int getTime() const;
virtual void setTime(int time);
virtual void setReverse(bool reverse);
virtual void setLoop(bool loop);
bool isOver() const;
protected:
WbMotionRef getMotionRef() const { return motionRef; }
private:
WbMotionRef motionRef;
};
} // namespace webots
#endif // MOTION_HPP

View File

@ -0,0 +1,65 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Description: CPP wrapper of the car library
* Comments: Sponsored by the CTI project RO2IVSim
* (http://transport.epfl.ch/simulator-for-mobile-robots-and-intelligent-vehicles)
*/
#ifndef CAR_HPP
#define CAR_HPP
#include <webots/vehicle/Driver.hpp>
namespace webots {
class Car : public Driver {
public:
typedef enum { TRACTION = 0, PROPULSION, FOUR_BY_FOUR } Type;
typedef enum { COMBUSTION_ENGINE = 0, ELECTRIC_ENGINE, PARALLEL_HYBRID_ENGINE, POWER_SPLIT_HYBRID_ENGINE } EngineType;
typedef enum { WHEEL_FRONT_RIGHT = 0, WHEEL_FRONT_LEFT, WHEEL_REAR_RIGHT, WHEEL_REAR_LEFT, WHEEL_NB } WheelIndex;
Car() : Driver() {}
virtual ~Car() {}
Type getType();
EngineType getEngineType();
void setIndicatorPeriod(double period);
double getIndicatorPeriod();
bool getBackwardsLights();
bool getBrakeLights();
double getTrackFront();
double getTrackRear();
double getWheelbase();
double getFrontWheelRadius();
double getRearWheelRadius();
double getWheelEncoder(WheelIndex wheel);
double getWheelSpeed(WheelIndex wheel);
void setLeftSteeringAngle(double angle);
void setRightSteeringAngle(double angle);
double getRightSteeringAngle();
double getLeftSteeringAngle();
void enableLimitedSlipDifferential(bool enable);
void enableIndicatorAutoDisabling(bool enable);
};
} // namespace webots
#endif // CAR_HPP

View File

@ -0,0 +1,92 @@
// Copyright 1996-2024 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* Description: CPP wrapper of the driver library
* Comments: Sponsored by the CTI project RO2IVSim
* (http://transport.epfl.ch/simulator-for-mobile-robots-and-intelligent-vehicles)
*/
#ifndef DRIVER_HPP
#define DRIVER_HPP
#include <webots/Supervisor.hpp>
namespace webots {
class Driver : public Supervisor {
public:
typedef enum { INDICATOR_OFF, INDICATOR_RIGHT, INDICATOR_LEFT } IndicatorState;
typedef enum { SPEED, TORQUE } ControlMode;
typedef enum { DOWN, SLOW, NORMAL, FAST } WiperMode;
// private function for webots_ros2 to identify robots that can use libdriver
static bool isInitialisationPossible();
Driver();
static Driver *getDriverInstance();
virtual ~Driver();
virtual int step();
// positive: turn right, negative: turn left
void setSteeringAngle(double steeringAngle);
double getSteeringAngle();
void setCruisingSpeed(double speed);
double getTargetCruisingSpeed();
double getCurrentSpeed();
void setThrottle(double throttle);
double getThrottle();
void setBrakeIntensity(double intensity);
double getBrakeIntensity();
void setIndicator(IndicatorState state);
void setHazardFlashers(bool state);
IndicatorState getIndicator();
bool getHazardFlashers();
void setDippedBeams(bool state);
void setAntifogLights(bool state);
bool getDippedBeams();
bool getAntifogLights();
double getRpm();
int getGear();
void setGear(int gear);
int getGearNumber();
ControlMode getControlMode();
void setWiperMode(WiperMode mode);
WiperMode getWiperMode();
// kept for backward compatibility only
void setBrake(double brake);
void setWipersMode(WiperMode mode);
WiperMode getWipersMode();
private:
virtual int step(int t) { return Supervisor::step(t); }
static Driver *dInstance;
};
} // namespace webots
#endif // DRIVER_HPP

View File

@ -0,0 +1,643 @@
EXPORTS
wb_ANSI_RESET
wb_ANSI_BOLD
wb_ANSI_UNDERLINE
wb_ANSI_BLACK_BACKGROUND
wb_ANSI_RED_BACKGROUND
wb_ANSI_GREEN_BACKGROUND
wb_ANSI_YELLOW_BACKGROUND
wb_ANSI_BLUE_BACKGROUND
wb_ANSI_MAGENTA_BACKGROUND
wb_ANSI_CYAN_BACKGROUND
wb_ANSI_WHITE_BACKGROUND
wb_ANSI_BLACK_FOREGROUND
wb_ANSI_RED_FOREGROUND
wb_ANSI_GREEN_FOREGROUND
wb_ANSI_YELLOW_FOREGROUND
wb_ANSI_BLUE_FOREGROUND
wb_ANSI_MAGENTA_FOREGROUND
wb_ANSI_CYAN_FOREGROUND
wb_ANSI_WHITE_FOREGROUND
wb_ANSI_CLEAR_SCREEN
wb_KEYBOARD_END
wb_KEYBOARD_HOME
wb_KEYBOARD_LEFT
wb_KEYBOARD_UP
wb_KEYBOARD_RIGHT
wb_KEYBOARD_DOWN
wb_KEYBOARD_PAGEUP
wb_KEYBOARD_PAGEDOWN
wb_KEYBOARD_NUMPAD_HOME
wb_KEYBOARD_NUMPAD_LEFT
wb_KEYBOARD_NUMPAD_UP
wb_KEYBOARD_NUMPAD_RIGHT
wb_KEYBOARD_NUMPAD_DOWN
wb_KEYBOARD_NUMPAD_END
wb_KEYBOARD_KEY
wb_KEYBOARD_SHIFT
wb_KEYBOARD_CONTROL
wb_KEYBOARD_ALT
wb_LINEAR
wb_MF
wb_MF_BOOL
wb_MF_INT32
wb_MF_FLOAT
wb_MF_VEC2F
wb_MF_VEC3F
wb_MF_ROTATION
wb_MF_COLOR
wb_MF_STRING
wb_MF_NODE
wb_NODE_NO_NODE
wb_NODE_APPEARANCE
wb_NODE_BACKGROUND
wb_NODE_BILLBOARD
wb_NODE_BOX
wb_NODE_CAD_SHAPE
wb_NODE_CAPSULE
wb_NODE_COLOR
wb_NODE_CONE
wb_NODE_COORDINATE
wb_NODE_CYLINDER
wb_NODE_DIRECTIONAL_LIGHT
wb_NODE_ELEVATION_GRID
wb_NODE_FOG
wb_NODE_GROUP
wb_NODE_IMAGE_TEXTURE
wb_NODE_INDEXED_FACE_SET
wb_NODE_INDEXED_LINE_SET
wb_NODE_MATERIAL
wb_NODE_MESH
wb_NODE_MUSCLE
wb_NODE_NORMAL
wb_NODE_PBR_APPEARANCE
wb_NODE_PLANE
wb_NODE_POINT_LIGHT
wb_NODE_POINT_SET
wb_NODE_POSE
wb_NODE_SHAPE
wb_NODE_SPHERE
wb_NODE_SPOT_LIGHT
wb_NODE_TEXTURE_COORDINATE
wb_NODE_TEXTURE_TRANSFORM
wb_NODE_TRANSFORM
wb_NODE_VIEWPOINT
wb_NODE_ROBOT
wb_NODE_ACCELEROMETER
wb_NODE_ALTIMETER
wb_NODE_BRAKE
wb_NODE_CAMERA
wb_NODE_COMPASS
wb_NODE_CONNECTOR
wb_NODE_DISPLAY
wb_NODE_DISTANCE_SENSOR
wb_NODE_EMITTER
wb_NODE_GPS
wb_NODE_GYRO
wb_NODE_INERTIAL_UNIT
wb_NODE_LED
wb_NODE_LIDAR
wb_NODE_LIGHT_SENSOR
wb_NODE_LINEAR_MOTOR
wb_NODE_PEN
wb_NODE_POSITION_SENSOR
wb_NODE_PROPELLER
wb_NODE_RADAR
wb_NODE_RANGE_FINDER
wb_NODE_RECEIVER
wb_NODE_ROTATIONAL_MOTOR
wb_NODE_SKIN
wb_NODE_SPEAKER
wb_NODE_TOUCH_SENSOR
wb_NODE_VACUUM_GRIPPER
wb_NODE_BALL_JOINT
wb_NODE_BALL_JOINT_PARAMETERS
wb_NODE_CHARGER
wb_NODE_CONTACT_PROPERTIES
wb_NODE_DAMPING
wb_NODE_FLUID
wb_NODE_FOCUS
wb_NODE_HINGE_JOINT
wb_NODE_HINGE_JOINT_PARAMETERS
wb_NODE_HINGE_2_JOINT
wb_NODE_IMMERSION_PROPERTIES
wb_NODE_JOINT_PARAMETERS
wb_NODE_LENS
wb_NODE_LENS_FLARE
wb_NODE_PHYSICS
wb_NODE_RECOGNITION
wb_NODE_SLIDER_JOINT
wb_NODE_SLOT
wb_NODE_SOLID
wb_NODE_SOLID_REFERENCE
wb_NODE_TRACK
wb_NODE_TRACK_WHEEL
wb_NODE_WORLD_INFO
wb_NODE_ZOOM
wb_NODE_MICROPHONE
wb_NODE_RADIO
wb_ROTATIONAL
wb_SF_BOOL
wb_SF_INT32
wb_SF_FLOAT
wb_SF_VEC2F
wb_SF_VEC3F
wb_SF_ROTATION
wb_SF_COLOR
wb_SF_STRING
wb_SF_NODE
wb_accelerometer_disable
wb_accelerometer_enable
wb_accelerometer_get_sampling_period
wb_accelerometer_get_values
wb_accelerometer_get_lookup_table_size
wb_accelerometer_get_lookup_table
wb_altimeter_disable
wb_altimeter_enable
wb_altimeter_get_sampling_period
wb_altimeter_get_value
wb_brake_get_motor
wb_brake_get_position_sensor
wb_brake_get_type
wb_brake_set_damping_constant
wb_camera_disable
wb_camera_enable
wb_camera_get_exposure
wb_camera_get_focal_distance
wb_camera_get_focal_length
wb_camera_get_fov
wb_camera_get_height
wb_camera_get_image
wb_camera_get_max_focal_distance
wb_camera_get_max_fov
wb_camera_get_min_focal_distance
wb_camera_get_min_fov
wb_camera_get_near
wb_camera_get_sampling_period
wb_camera_get_width
wb_camera_has_recognition
wb_camera_recognition_disable
wb_camera_recognition_disable_segmentation
wb_camera_recognition_enable
wb_camera_recognition_enable_segmentation
wb_camera_recognition_get_number_of_objects
wb_camera_recognition_get_objects
wb_camera_recognition_get_sampling_period
wb_camera_recognition_get_segmentation_image
wb_camera_recognition_has_segmentation
wb_camera_recognition_is_segmentation_enabled
wb_camera_recognition_save_segmentation_image
wb_camera_save_image
wb_camera_set_exposure
wb_camera_set_focal_distance
wb_camera_set_fov
wb_compass_disable
wb_compass_enable
wb_compass_get_sampling_period
wb_compass_get_values
wb_compass_get_lookup_table_size
wb_compass_get_lookup_table
wb_connector_disable_presence
wb_connector_enable_presence
wb_connector_get_presence
wb_connector_get_presence_sampling_period
wb_connector_is_locked
wb_connector_lock
wb_connector_unlock
wb_console_print
wb_device_get_model
wb_device_get_name
wb_device_get_type
wb_device_get_node_type
wb_display_attach_camera
wb_display_detach_camera
wb_display_draw_line
wb_display_draw_oval
wb_display_draw_pixel
wb_display_draw_polygon
wb_display_draw_rectangle
wb_display_draw_text
wb_display_fill_oval
wb_display_fill_polygon
wb_display_fill_rectangle
wb_display_get_height
wb_display_get_width
wb_display_image_copy
wb_display_image_delete
wb_display_image_load
wb_display_image_new
wb_display_image_paste
wb_display_image_save
wb_display_set_alpha
wb_display_set_color
wb_display_set_font
wb_display_set_opacity
wb_distance_sensor_disable
wb_distance_sensor_enable
wb_distance_sensor_get_aperture
wb_distance_sensor_get_max_value
wb_distance_sensor_get_min_value
wb_distance_sensor_get_sampling_period
wb_distance_sensor_get_type
wb_distance_sensor_get_value
wb_distance_sensor_get_lookup_table_size
wb_distance_sensor_get_lookup_table
wb_emitter_get_buffer_size
wb_emitter_get_channel
wb_emitter_get_range
wb_emitter_send
wb_emitter_set_channel
wb_emitter_set_range
wb_gps_disable
wb_gps_convert_to_degrees_minutes_seconds
wb_gps_enable
wb_gps_get_coordinate_system
wb_gps_get_sampling_period
wb_gps_get_speed
wb_gps_get_speed_vector
wb_gps_get_values
wb_gyro_disable
wb_gyro_enable
wb_gyro_get_sampling_period
wb_gyro_get_values
wb_gyro_get_lookup_table_size
wb_gyro_get_lookup_table
wb_inertial_unit_disable
wb_inertial_unit_enable
wb_inertial_unit_get_roll_pitch_yaw
wb_inertial_unit_get_quaternion
wb_inertial_unit_get_sampling_period
wb_inertial_unit_get_noise
wb_joystick_disable
wb_joystick_enable
wb_joystick_get_axis_value
wb_joystick_get_model
wb_joystick_get_number_of_axes
wb_joystick_get_number_of_povs
wb_joystick_get_pov_value
wb_joystick_get_pressed_button
wb_joystick_get_sampling_period
wb_joystick_is_connected
wb_joystick_set_auto_centering_gain
wb_joystick_set_constant_force
wb_joystick_set_constant_force_duration
wb_joystick_set_force_axis
wb_joystick_set_resistance_gain
wb_keyboard_disable
wb_keyboard_enable
wb_keyboard_get_key
wb_keyboard_get_sampling_period
wb_led_get
wb_led_set
wb_lidar_disable
wb_lidar_disable_point_cloud
wb_lidar_enable
wb_lidar_enable_point_cloud
wb_lidar_get_fov
wb_lidar_get_frequency
wb_lidar_get_horizontal_resolution
wb_lidar_get_layer_point_cloud
wb_lidar_get_layer_range_image
wb_lidar_get_max_frequency
wb_lidar_get_max_range
wb_lidar_get_min_frequency
wb_lidar_get_min_range
wb_lidar_get_number_of_layers
wb_lidar_get_number_of_points
wb_lidar_get_point_cloud
wb_lidar_get_range_image
wb_lidar_get_sampling_period
wb_lidar_get_vertical_fov
wb_lidar_is_point_cloud_enabled
wb_lidar_set_frequency
wb_light_sensor_disable
wb_light_sensor_enable
wb_light_sensor_get_sampling_period
wb_light_sensor_get_value
wb_light_sensor_get_lookup_table_size
wb_light_sensor_get_lookup_table
wb_microphone_enable
wb_microphone_get_sample_data
wb_microphone_get_sample_size
wb_microphone_get_sampling_period
wb_motor_disable_force_feedback
wb_motor_disable_torque_feedback
wb_motor_enable_force_feedback
wb_motor_enable_torque_feedback
wb_motor_get_acceleration
wb_motor_get_available_force
wb_motor_get_available_torque
wb_motor_get_force_feedback
wb_motor_get_force_feedback_sampling_period
wb_motor_get_max_force
wb_motor_get_max_torque
wb_motor_get_max_position
wb_motor_get_max_velocity
wb_motor_get_min_position
wb_motor_get_multiplier
wb_motor_get_target_position
wb_motor_get_torque_feedback
wb_motor_get_torque_feedback_sampling_period
wb_motor_get_type
wb_motor_get_velocity
wb_motor_get_brake
wb_motor_get_position_sensor
wb_motor_set_acceleration
wb_motor_set_available_force
wb_motor_set_available_torque
wb_motor_set_control_pid
wb_motor_set_force
wb_motor_set_position
wb_motor_set_torque
wb_motor_set_velocity
wb_mouse_disable
wb_mouse_disable_3d_position
wb_mouse_enable
wb_mouse_enable_3d_position
wb_mouse_get_sampling_period
wb_mouse_get_state
wb_mouse_is_3d_position_enabled
wb_node_get_name
wb_pen_set_ink_color
wb_pen_write
wb_position_sensor_enable
wb_position_sensor_disable
wb_position_sensor_get_value
wb_position_sensor_get_sampling_period
wb_position_sensor_get_type
wb_position_sensor_get_brake
wb_position_sensor_get_motor
wb_radar_disable
wb_radar_enable
wb_radar_get_horizontal_fov
wb_radar_get_max_range
wb_radar_get_min_range
wb_radar_get_number_of_targets
wb_radar_get_sampling_period
wb_radar_get_targets
wb_radar_get_vertical_fov
wb_range_finder_enable
wb_range_finder_disable
wb_range_finder_get_sampling_period
wb_range_finder_get_range_image
wb_range_finder_get_width
wb_range_finder_get_height
wb_range_finder_get_fov
wb_range_finder_get_min_range
wb_range_finder_get_max_range
wb_range_finder_save_image
wb_range_finder_image_get_depth
wb_remote_control_custom_function
wb_receiver_disable
wb_receiver_enable
wb_receiver_get_channel
wb_receiver_get_data
wb_receiver_get_data_size
wb_receiver_get_emitter_direction
wb_receiver_get_queue_length
wb_receiver_get_sampling_period
wb_receiver_get_signal_strength
wb_receiver_next_packet
wb_receiver_set_channel
wb_robot_battery_sensor_disable
wb_robot_battery_sensor_enable
wb_robot_battery_sensor_get_value
wb_robot_battery_sensor_get_sampling_period
wb_robot_cleanup
wb_robot_get_basic_time_step
wb_robot_get_controller_name
wb_robot_get_custom_data
wb_robot_get_data
wb_robot_get_device
wb_robot_get_device_by_index
wb_robot_get_mode
wb_robot_get_model
wb_robot_get_name
wb_robot_get_number_of_devices
wb_robot_get_project_path
wb_robot_get_supervisor
wb_robot_get_synchronization
wb_robot_get_time
wb_robot_get_urdf
wb_robot_get_world_path
wb_robot_init
wb_robot_init_msvc
wb_robot_mutex_delete
wb_robot_mutex_lock
wb_robot_mutex_new
wb_robot_mutex_unlock
wb_robot_pin_to_static_environment
wb_robot_set_custom_data
wb_robot_set_data
wb_robot_set_mode
wb_robot_step
wb_robot_step_begin
wb_robot_step_end
wb_robot_task_new
wb_robot_wait_for_user_input_event
wb_robot_window_custom_function
wb_robot_wwi_send
wb_robot_wwi_receive
wb_robot_wwi_receive_text
wb_skin_get_bone_count
wb_skin_get_bone_name
wb_skin_get_bone_orientation
wb_skin_get_bone_position
wb_skin_set_bone_orientation
wb_skin_set_bone_position
wb_speaker_get_engine
wb_speaker_get_language
wb_speaker_is_sound_playing
wb_speaker_is_speaking
wb_speaker_play_sound
wb_speaker_set_engine
wb_speaker_set_language
wb_speaker_speak
wb_speaker_stop
wb_supervisor_node_add_force
wb_supervisor_node_add_force_with_offset
wb_supervisor_node_add_torque
wb_supervisor_animation_start_recording
wb_supervisor_animation_stop_recording
wb_supervisor_export_image
wb_supervisor_field_disable_sf_tracking
wb_supervisor_field_enable_sf_tracking
wb_supervisor_field_get_actual_field
wb_supervisor_field_get_count
wb_supervisor_field_get_name
wb_supervisor_field_get_mf_bool
wb_supervisor_field_get_mf_color
wb_supervisor_field_get_mf_float
wb_supervisor_field_get_mf_int32
wb_supervisor_field_get_mf_node
wb_supervisor_field_get_mf_rotation
wb_supervisor_field_get_mf_string
wb_supervisor_field_get_mf_vec2f
wb_supervisor_field_get_mf_vec3f
wb_supervisor_field_get_sf_bool
wb_supervisor_field_get_sf_color
wb_supervisor_field_get_sf_float
wb_supervisor_field_get_sf_int32
wb_supervisor_field_get_sf_node
wb_supervisor_field_get_sf_rotation
wb_supervisor_field_get_sf_string
wb_supervisor_field_get_sf_vec2f
wb_supervisor_field_get_sf_vec3f
wb_supervisor_field_get_type
wb_supervisor_field_get_type_name
wb_supervisor_field_import_mf_node_from_string
wb_supervisor_field_import_sf_node_from_string
wb_supervisor_field_insert_mf_bool
wb_supervisor_field_insert_mf_color
wb_supervisor_field_insert_mf_float
wb_supervisor_field_insert_mf_int32
wb_supervisor_field_insert_mf_rotation
wb_supervisor_field_insert_mf_string
wb_supervisor_field_insert_mf_vec2f
wb_supervisor_field_insert_mf_vec3f
wb_supervisor_field_remove_mf
wb_supervisor_field_remove_mf_node
wb_supervisor_field_remove_sf
wb_supervisor_field_set_mf_bool
wb_supervisor_field_set_mf_color
wb_supervisor_field_set_mf_float
wb_supervisor_field_set_mf_int32
wb_supervisor_field_set_mf_rotation
wb_supervisor_field_set_mf_string
wb_supervisor_field_set_mf_vec2f
wb_supervisor_field_set_mf_vec3f
wb_supervisor_field_set_sf_bool
wb_supervisor_field_set_sf_color
wb_supervisor_field_set_sf_float
wb_supervisor_field_set_sf_int32
wb_supervisor_field_set_sf_rotation
wb_supervisor_field_set_sf_string
wb_supervisor_field_set_sf_vec2f
wb_supervisor_field_set_sf_vec3f
wb_supervisor_movie_failed
wb_supervisor_movie_is_ready
wb_supervisor_movie_start_recording
wb_supervisor_movie_stop_recording
wb_supervisor_movie_get_status
wb_supervisor_node_disable_contact_point_tracking
wb_supervisor_node_disable_contact_points_tracking
wb_supervisor_node_disable_pose_tracking
wb_supervisor_node_enable_contact_point_tracking
wb_supervisor_node_enable_contact_points_tracking
wb_supervisor_node_enable_pose_tracking
wb_supervisor_node_export_string
wb_supervisor_node_get_base_node_field
wb_supervisor_node_get_base_node_field_by_index
wb_supervisor_node_get_base_type_name
wb_supervisor_node_get_def
wb_supervisor_node_get_field
wb_supervisor_node_get_field_by_index
wb_supervisor_node_get_from_def
wb_supervisor_node_get_from_id
wb_supervisor_node_get_from_proto_def
wb_supervisor_node_get_from_device
wb_supervisor_node_get_center_of_mass
wb_supervisor_node_get_contact_point
wb_supervisor_node_get_contact_points
wb_supervisor_node_get_contact_point_node
wb_supervisor_node_get_id
wb_supervisor_node_get_number_of_base_node_fields
wb_supervisor_node_get_number_of_contact_points
wb_supervisor_node_get_number_of_fields
wb_supervisor_node_get_orientation
wb_supervisor_node_get_parent_node
wb_supervisor_node_get_pose
wb_supervisor_node_get_position
wb_supervisor_node_get_proto
wb_supervisor_node_get_root
wb_supervisor_node_get_selected
wb_supervisor_node_get_self
wb_supervisor_node_get_static_balance
wb_supervisor_node_get_type
wb_supervisor_node_get_type_name
wb_supervisor_node_get_velocity
wb_supervisor_node_is_proto
wb_supervisor_node_load_state
wb_supervisor_node_move_viewpoint
wb_supervisor_node_remove
wb_supervisor_node_reset_physics
wb_supervisor_node_restart_controller
wb_supervisor_node_save_state
wb_supervisor_node_set_joint_position
wb_supervisor_node_set_velocity
wb_supervisor_node_set_visibility
wb_supervisor_proto_get_field
wb_supervisor_proto_get_field_by_index
wb_supervisor_proto_get_number_of_fields
wb_supervisor_proto_get_parent
wb_supervisor_proto_get_type_name
wb_supervisor_proto_is_derived
wb_supervisor_set_label
wb_supervisor_simulation_get_mode
wb_supervisor_simulation_physics_reset
wb_supervisor_simulation_quit
wb_supervisor_simulation_reset
wb_supervisor_simulation_reset_physics
wb_supervisor_simulation_revert
wb_supervisor_simulation_set_mode
wb_supervisor_start_movie
wb_supervisor_stop_movie
wb_supervisor_get_movie_status
wb_supervisor_virtual_reality_headset_get_position
wb_supervisor_virtual_reality_headset_get_orientation
wb_supervisor_virtual_reality_headset_is_used
wb_supervisor_world_load
wb_supervisor_world_save
wb_supervisor_world_reload
wb_touch_sensor_disable
wb_touch_sensor_enable
wb_touch_sensor_get_sampling_period
wb_touch_sensor_get_type
wb_touch_sensor_get_value
wb_touch_sensor_get_values
wb_touch_sensor_get_lookup_table_size
wb_touch_sensor_get_lookup_table
wb_vacuum_gripper_disable_presence
wb_vacuum_gripper_enable_presence
wb_vacuum_gripper_get_presence
wb_vacuum_gripper_get_presence_sampling_period
wb_vacuum_gripper_is_on
wb_vacuum_gripper_turn_on
wb_vacuum_gripper_turn_off
wbr_accelerometer_set_values
wbr_camera_get_image_buffer
wbr_camera_set_image
wbr_camera_set_focal_distance
wbr_camera_set_fov
wbr_compass_set_values
wbr_display_save_image
wbr_distance_sensor_set_value
wbr_gps_set_values
wbr_gyro_set_values
wbr_light_sensor_set_value
wbr_microphone_set_buffer
wbr_motor_set_force_feedback
wbr_motor_set_torque_feedback
wbr_position_sensor_set_value
wbr_robot_battery_sensor_set_value
wbr_touch_sensor_set_value
wbr_touch_sensor_set_values
wbu_default_robot_window_configure
wbu_default_robot_window_update
wbu_default_robot_window_set_images_max_size
wbu_motion_delete
wbu_motion_get_duration
wbu_motion_get_time
wbu_motion_is_over
wbu_motion_new
wbu_motion_play
wbu_motion_set_loop
wbu_motion_set_reverse
wbu_motion_set_time
wbu_motion_stop
wbu_robot_window_configure
wbu_robot_window_update
wbu_string_replace
wbu_string_strsep
wbu_system_getenv
wbu_system_short_path

View File

@ -0,0 +1,5 @@
api module
This module contains all the controller API functions for controlling a robot
and handling user interaction. Moreover, it contains networking and scene
management stuff.

View File

@ -0,0 +1,171 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "abstract_camera.h"
#ifdef _WIN32
#include <windows.h>
#else // memory mapped files
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <webots/robot.h>
#include "messages.h"
#include "robot_private.h"
void wb_abstract_camera_cleanup(WbDevice *d) {
AbstractCamera *c = d->pdata;
if (c == NULL)
return;
image_cleanup(c->image);
free(c->image);
free(c);
}
void wb_abstract_camera_new(WbDevice *d, unsigned int id, int w, int h, double fov, double camnear, bool planar) {
wb_abstract_camera_cleanup(d);
AbstractCamera *c = malloc(sizeof(AbstractCamera));
c->enable = false;
c->unique_id = id;
c->width = w;
c->height = h;
c->fov = fov;
c->camnear = camnear;
c->planar = planar;
c->sampling_period = 0;
c->image = image_new();
d->pdata = c;
}
void wb_abstract_camera_write_request(WbDevice *d, WbRequest *r) {
AbstractCamera *c = d->pdata;
if (c->enable) {
request_write_uchar(r, C_SET_SAMPLING_PERIOD);
request_write_uint16(r, c->sampling_period);
c->enable = false; // done
}
}
bool wb_abstract_camera_handle_command(WbDevice *d, WbRequest *r, unsigned char command) {
bool command_handled = true;
AbstractCamera *c = d->pdata;
switch (command) {
case C_CAMERA_MEMORY_MAPPED_FILE:
// Cleanup the previous memory mapped file if any.
image_cleanup(c->image);
image_setup(c->image, r);
break;
default:
command_handled = false;
break;
}
return command_handled;
}
void abstract_camera_toggle_remote(WbDevice *d, WbRequest *r) {
AbstractCamera *c = d->pdata;
if (c->sampling_period != 0)
c->enable = true;
}
void wbr_abstract_camera_set_image(WbDevice *d, const unsigned char *image) {
AbstractCamera *c = d->pdata;
if (c && c->image->data)
memcpy(c->image->data, image, 4 * c->height * c->width);
}
unsigned char *wbr_abstract_camera_get_image_buffer(WbDevice *d) {
AbstractCamera *c = d->pdata;
if (c && c->image->data)
return c->image->data;
return NULL;
}
void abstract_camera_allocate_image(WbDevice *d, int size) {
AbstractCamera *c = d->pdata;
if (c) {
c->image->data = realloc(c->image->data, size);
c->image->size = size;
}
}
void wb_abstract_camera_enable(WbDevice *d, int sampling_period) {
robot_mutex_lock();
AbstractCamera *ac = d->pdata;
if (ac) {
ac->enable = true;
ac->sampling_period = sampling_period;
}
robot_mutex_unlock();
}
int wb_abstract_camera_get_sampling_period(const WbDevice *d) {
int sampling_period = 0;
robot_mutex_lock();
const AbstractCamera *ac = d->pdata;
if (ac)
sampling_period = ac->sampling_period;
robot_mutex_unlock();
return sampling_period;
}
int wb_abstract_camera_get_height(const WbDevice *d) {
int result = -1;
robot_mutex_lock();
const AbstractCamera *ac = d->pdata;
if (ac)
result = ac->height;
robot_mutex_unlock();
return result;
}
int wb_abstract_camera_get_width(const WbDevice *d) {
int result = -1;
robot_mutex_lock();
const AbstractCamera *ac = d->pdata;
if (ac)
result = ac->width;
robot_mutex_unlock();
return result;
}
double wb_abstract_camera_get_fov(const WbDevice *d) {
double result = NAN;
robot_mutex_lock();
const AbstractCamera *ac = d->pdata;
if (ac)
result = ac->fov;
robot_mutex_unlock();
return result;
}
double wb_abstract_camera_get_near(const WbDevice *d) {
double result = NAN;
robot_mutex_lock();
const AbstractCamera *ac = d->pdata;
if (ac)
result = ac->camnear;
robot_mutex_unlock();
return result;
}

View File

@ -0,0 +1,64 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ABSTRACT_CAMERA_PRIVATE_H
#define ABSTRACT_CAMERA_PRIVATE_H
#include <webots/types.h>
#include "device_private.h"
#include "image_private.h"
#ifdef _WIN32
#include <windows.h>
#endif
typedef struct {
bool enable;
int sampling_period;
unsigned int unique_id; // camera id
int width;
int height;
double camnear;
bool planar;
double fov; // in degrees
int mode;
void *pdata;
Image *image;
} AbstractCamera;
void wb_abstract_camera_cleanup(WbDevice *d);
void wb_abstract_camera_new(WbDevice *d, unsigned int id, int w, int h, double fov, double camnear, bool planar);
void wb_abstract_camera_write_request(WbDevice *d, WbRequest *r);
bool wb_abstract_camera_handle_command(WbDevice *d, WbRequest *r, unsigned char command);
void abstract_camera_toggle_remote(WbDevice *d, WbRequest *r);
void wbr_abstract_camera_set_image(WbDevice *d, const unsigned char *image);
unsigned char *wbr_abstract_camera_get_image_buffer(WbDevice *d);
void abstract_camera_allocate_image(WbDevice *d, int size);
void wb_abstract_camera_enable(WbDevice *d, int sampling_period);
int wb_abstract_camera_get_sampling_period(const WbDevice *d);
int wb_abstract_camera_get_height(const WbDevice *d);
int wb_abstract_camera_get_width(const WbDevice *d);
double wb_abstract_camera_get_fov(const WbDevice *d);
double wb_abstract_camera_get_near(const WbDevice *d);
#endif // ABSTRACT_CAMERA_PRIVATE_H

View File

@ -0,0 +1,191 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h> // malloc and free
#include <webots/accelerometer.h>
#include <webots/nodes.h>
#include <webots/robot.h>
#include "device_private.h"
#include "messages.h"
#include "robot_private.h"
// Static functions
typedef struct {
bool enable; // need to enable device ?
int sampling_period; // milliseconds
double values[3]; // acceleration
int lookup_table_size;
double *lookup_table;
} Accelerometer;
static Accelerometer *accelerometer_create() {
Accelerometer *acc = malloc(sizeof(Accelerometer));
acc->enable = false;
acc->sampling_period = 0;
acc->values[0] = NAN;
acc->values[1] = NAN;
acc->values[2] = NAN;
acc->lookup_table = NULL;
acc->lookup_table_size = 0;
return acc;
}
static Accelerometer *accelerometer_get_struct(WbDeviceTag t) {
WbDevice *d = robot_get_device_with_node(t, WB_NODE_ACCELEROMETER, true);
return d ? d->pdata : NULL;
}
static void accelerometer_read_answer(WbDevice *d, WbRequest *r) {
Accelerometer *acc = d->pdata;
switch (request_read_uchar(r)) {
case C_ACCELEROMETER_DATA:
acc->values[0] = request_read_double(r);
acc->values[1] = request_read_double(r);
acc->values[2] = request_read_double(r);
break;
case C_CONFIGURE:
acc->lookup_table_size = request_read_int32(r);
free(acc->lookup_table);
acc->lookup_table = NULL;
if (acc->lookup_table_size > 0) {
acc->lookup_table = (double *)malloc(sizeof(double) * acc->lookup_table_size * 3);
for (int i = 0; i < acc->lookup_table_size * 3; i++)
acc->lookup_table[i] = request_read_double(r);
}
break;
default:
ROBOT_ASSERT(0); // should never be reached
break;
}
}
int wb_accelerometer_get_lookup_table_size(WbDeviceTag tag) {
int result = 0;
robot_mutex_lock();
const Accelerometer *dev = accelerometer_get_struct(tag);
if (dev)
result = dev->lookup_table_size;
else
fprintf(stderr, "Error: %s(): invalid device tag.\n", __FUNCTION__);
robot_mutex_unlock();
return result;
}
const double *wb_accelerometer_get_lookup_table(WbDeviceTag tag) {
const double *result = NULL;
robot_mutex_lock();
const Accelerometer *dev = accelerometer_get_struct(tag);
if (dev)
result = dev->lookup_table;
else
fprintf(stderr, "Error: %s(): invalid device tag.\n", __FUNCTION__);
robot_mutex_unlock();
return result;
}
static void accelerometer_write_request(WbDevice *d, WbRequest *r) {
Accelerometer *acc = d->pdata;
if (acc->enable) {
request_write_uchar(r, C_SET_SAMPLING_PERIOD);
request_write_uint16(r, acc->sampling_period);
acc->enable = false; // done
}
}
static void accelerometer_cleanup(WbDevice *d) {
Accelerometer *acc = (Accelerometer *)d->pdata;
free(acc->lookup_table);
free(d->pdata);
}
static void accelerometer_toggle_remote(WbDevice *d, WbRequest *r) {
Accelerometer *acc = d->pdata;
if (acc->sampling_period != 0)
acc->enable = true;
}
void wbr_accelerometer_set_values(WbDeviceTag tag, const double *values) {
Accelerometer *acc = accelerometer_get_struct(tag);
if (acc) {
acc->values[0] = values[0];
acc->values[1] = values[1];
acc->values[2] = values[2];
} else
fprintf(stderr, "Error: %s(): invalid device tag.\n", __FUNCTION__);
}
// Protected functions (exported to device.cc)
void wb_accelerometer_init(WbDevice *d) {
d->pdata = accelerometer_create();
d->write_request = accelerometer_write_request;
d->read_answer = accelerometer_read_answer;
d->cleanup = accelerometer_cleanup;
d->toggle_remote = accelerometer_toggle_remote;
}
// Public function available from the user API
void wb_accelerometer_enable(WbDeviceTag tag, int sampling_period) {
if (sampling_period < 0) {
fprintf(stderr, "Error: %s() called with negative sampling period.\n", __FUNCTION__);
return;
}
robot_mutex_lock();
Accelerometer *acc = accelerometer_get_struct(tag);
if (acc) {
acc->sampling_period = sampling_period;
acc->enable = true;
} else
fprintf(stderr, "Error: %s(): invalid device tag.\n", __FUNCTION__);
robot_mutex_unlock();
}
void wb_accelerometer_disable(WbDeviceTag tag) {
const Accelerometer *acc = accelerometer_get_struct(tag);
if (acc)
wb_accelerometer_enable(tag, 0);
else
fprintf(stderr, "Error: %s(): invalid device tag.\n", __FUNCTION__);
}
int wb_accelerometer_get_sampling_period(WbDeviceTag tag) {
int sampling_period = 0;
robot_mutex_lock();
const Accelerometer *acc = accelerometer_get_struct(tag);
if (acc)
sampling_period = acc->sampling_period;
else
fprintf(stderr, "Error: %s(): invalid device tag.\n", __FUNCTION__);
robot_mutex_unlock();
return sampling_period;
}
const double *wb_accelerometer_get_values(WbDeviceTag tag) {
const double *result = NULL;
robot_mutex_lock();
const Accelerometer *acc = accelerometer_get_struct(tag);
if (acc) {
if (acc->sampling_period == 0)
fprintf(stderr, "Error: %s() called for a disabled device! Please use: wb_accelerometer_enable().\n", __FUNCTION__);
result = acc->values;
}
robot_mutex_unlock();
return result;
}

View File

@ -0,0 +1,144 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <webots/altimeter.h>
#include "messages.h"
#include "robot_private.h"
// Static functions
typedef struct {
bool enable;
int sampling_period;
double altitude;
} Altimeter;
static Altimeter *altimeter_create() {
Altimeter *altimeter = malloc(sizeof(Altimeter));
altimeter->enable = false;
altimeter->sampling_period = 0;
altimeter->altitude = NAN;
return altimeter;
}
static Altimeter *altimeter_get_struct(WbDeviceTag t) {
WbDevice *d = robot_get_device_with_node(t, WB_NODE_ALTIMETER, true);
return d ? d->pdata : NULL;
}
static void altimeter_read_answer(WbDevice *d, WbRequest *r) {
Altimeter *altimeter = d->pdata;
switch (request_read_uchar(r)) {
case C_ALTIMETER_DATA:
altimeter->altitude = request_read_double(r);
break;
default:
ROBOT_ASSERT(0); // should never be reached
break;
}
}
static void altimeter_write_request(WbDevice *d, WbRequest *r) {
Altimeter *altimeter = d->pdata;
if (altimeter->enable) {
request_write_uchar(r, C_SET_SAMPLING_PERIOD);
request_write_uint16(r, altimeter->sampling_period);
altimeter->enable = false;
}
}
static void altimeter_cleanup(WbDevice *d) {
free(d->pdata);
}
static void altimeter_toggle_remote(WbDevice *d, WbRequest *r) {
Altimeter *altimeter = d->pdata;
if (altimeter->sampling_period != 0)
altimeter->enable = true;
}
void wbr_altimeter_set_value(WbDeviceTag t, const double value) {
Altimeter *altimeter = altimeter_get_struct(t);
if (altimeter) {
altimeter->altitude = value;
} else
fprintf(stderr, "Error: %s(): invalid device tag. \n", __FUNCTION__);
}
// Protected functions (exported to device.cc)
void wb_altimeter_init(WbDevice *d) {
d->write_request = altimeter_write_request;
d->read_answer = altimeter_read_answer;
d->cleanup = altimeter_cleanup;
d->pdata = altimeter_create();
d->toggle_remote = altimeter_toggle_remote;
}
// Public function available from the user API
void wb_altimeter_enable(WbDeviceTag tag, int sampling_period) {
if (sampling_period < 0) {
fprintf(stderr, "Error: %s() called with negative sampling period. \n", __FUNCTION__);
return;
}
robot_mutex_lock();
Altimeter *altimeter = altimeter_get_struct(tag);
if (altimeter) {
altimeter->enable = true;
altimeter->sampling_period = sampling_period;
} else
fprintf(stderr, "Error: %s(): invalid device tag.\n", __FUNCTION__);
robot_mutex_unlock();
}
void wb_altimeter_disable(WbDeviceTag tag) {
const Altimeter *altimeter = altimeter_get_struct(tag);
if (altimeter)
wb_altimeter_enable(tag, 0);
else
fprintf(stderr, "Error: %s(): invalid device tag.\n", __FUNCTION__);
}
int wb_altimeter_get_sampling_period(WbDeviceTag tag) {
int sampling_period = 0;
robot_mutex_lock();
const Altimeter *altimeter = altimeter_get_struct(tag);
if (altimeter)
sampling_period = altimeter->sampling_period;
else
fprintf(stderr, "Error: %s(): invalid device tag.\n", __FUNCTION__);
robot_mutex_unlock();
return sampling_period;
}
double wb_altimeter_get_value(WbDeviceTag tag) {
double result = NAN;
robot_mutex_lock();
const Altimeter *altimeter = altimeter_get_struct(tag);
if (altimeter) {
if (altimeter->sampling_period <= 0)
fprintf(stderr, "Error: %s() called for a disabled device! Please use: wb_altimeter_enable().\n", __FUNCTION__);
result = altimeter->altitude;
} else
fprintf(stderr, "Error: %s(): invalid device tag.\n", __FUNCTION__);
robot_mutex_unlock();
return result;
}

View File

@ -0,0 +1,28 @@
/*
* Copyright 1996-2024 Cyberbotics Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <webots/utils/ansi_codes.h>
const char *wb_ANSI_RESET = ANSI_RESET, *wb_ANSI_BOLD = ANSI_BOLD, *wb_ANSI_UNDERLINE = ANSI_UNDERLINE,
*wb_ANSI_BLACK_BACKGROUND = ANSI_BLACK_BACKGROUND, *wb_ANSI_RED_BACKGROUND = ANSI_RED_BACKGROUND,
*wb_ANSI_GREEN_BACKGROUND = ANSI_GREEN_BACKGROUND, *wb_ANSI_YELLOW_BACKGROUND = ANSI_YELLOW_BACKGROUND,
*wb_ANSI_BLUE_BACKGROUND = ANSI_BLUE_BACKGROUND, *wb_ANSI_MAGENTA_BACKGROUND = ANSI_MAGENTA_BACKGROUND,
*wb_ANSI_CYAN_BACKGROUND = ANSI_CYAN_BACKGROUND, *wb_ANSI_WHITE_BACKGROUND = ANSI_WHITE_BACKGROUND,
*wb_ANSI_BLACK_FOREGROUND = ANSI_BLACK_FOREGROUND, *wb_ANSI_RED_FOREGROUND = ANSI_RED_FOREGROUND,
*wb_ANSI_GREEN_FOREGROUND = ANSI_GREEN_FOREGROUND, *wb_ANSI_YELLOW_FOREGROUND = ANSI_YELLOW_FOREGROUND,
*wb_ANSI_BLUE_FOREGROUND = ANSI_BLUE_FOREGROUND, *wb_ANSI_MAGENTA_FOREGROUND = ANSI_MAGENTA_FOREGROUND,
*wb_ANSI_CYAN_FOREGROUND = ANSI_CYAN_FOREGROUND, *wb_ANSI_WHITE_FOREGROUND = ANSI_WHITE_FOREGROUND,
*wb_ANSI_CLEAR_SCREEN = ANSI_CLEAR_SCREEN;

Some files were not shown because too many files have changed in this diff Show More