Advertisement
cosenza987

Untitled

Oct 10th, 2021
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.27 KB | None | 0 0
  1. /*
  2.  * File:          asdasss.c
  3.  * Date:
  4.  * Description:
  5.  * Author:
  6.  * Modifications:
  7.  */
  8.  
  9. /*
  10.  * You may need to add include files like <webots/distance_sensor.h> or
  11.  * <webots/motor.h>, etc.
  12.  */
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <webots/camera.h>
  17. #include <webots/motor.h>
  18. #include <webots/robot.h>
  19. #include <webots/utils/system.h>
  20.  
  21. /*
  22.  * You may want to add macros here.
  23.  */
  24. #define TIME_STEP 32
  25.  
  26. /*
  27.  * This is the main program.
  28.  * The arguments of the main function can be specified by the
  29.  * "controllerArgs" field of the Robot node
  30.  */
  31. int main(int argc, char **argv) {
  32.   /* necessary to initialize webots stuff */
  33.   WbDeviceTag rc, lm, rm;
  34.   int width, height;
  35.   int pause_counter = 0;
  36.   int left_speed, right_speed;
  37.   int i, j;
  38.   int red, blue, green;
  39.   wb_robot_init();
  40.  
  41.   /*
  42.    * You should declare here WbDeviceTag variables for storing
  43.    * robot devices like this:yguviugoyiouyg
  44.    *  WbDeviceTag my_sensor = wb_robot_get_device("my_sensor");
  45.    *  WbDeviceTag my_actuator = wb_robot_get_device("my_actuator");
  46.    */
  47.    rc = wb_robot_get_device("RightCamera");
  48.    wb_camera_enable(rc, TIME_STEP);
  49.    width = wb_camera_get_width(rc);
  50.    height = wb_camera_get_height(rc);
  51.    lm = wb_robot_get_device("LeftWheel");
  52.    rm = wb_robot_get_device("RightWheel");
  53.    wb_motor_set_position(lm, INFINITY);
  54.    wb_motor_set_position(rm, INFINITY);
  55.    wb_motor_set_velocity(lm, 0.0);
  56.    wb_motor_set_velocity(rm, 0.0);
  57.  
  58.   /* main loop
  59.    * Perform simulation steps of TIME_STEP milliseconds
  60.    * and leave the loop when the simulation is over
  61.    */
  62.   while (wb_robot_step(TIME_STEP) != -1) {
  63.     wb_motor_set_velocity(lm, 2);
  64.     wb_motor_set_velocity(rm, 2);
  65.     const unsigned char *image = wb_camera_get_image(rc);
  66.     red = 0, green = 0, blue = 0;
  67.     for(int i = 0; i < 8; i++) {
  68.         for(int j = 0; j < 8; j++) {
  69.           red += wb_camera_image_get_red(image, width, i, j);
  70.           blue += wb_camera_image_get_blue(image, width, i, j);
  71.           green += wb_camera_image_get_green(image, width, i, j);
  72.         }
  73.       }
  74.     printf("%d %d %d\n", red, green, blue);
  75.   };
  76.  
  77.   /* Enter your cleanup code here */
  78.  
  79.   /* This is necessary to cleanup webots resources */
  80.   wb_robot_cleanup();
  81.  
  82.   return 0;
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement