Learning Robotics Using Python

Learning Robotics Using Python

Author:Joseph, Lentin
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2015-05-26T16:00:00+00:00


The following code is the loop() function, which continuously reads the sensor value and prints its values through the serial port: The Update_MPU6050() custom function is responsible for printing the updated value from MPU 6050:

void loop() { //Update MPU 6050 Update_MPU6050(); }

The definition of Update_MPU6050() is given as follows. It declares six variables to handle the accelerometer and gyroscope value in 3-axis. The getMotion6() function in the MPU 6050 class is responsible for reading the new values from the sensor. After reading, it will print via the serial port:

void Update_MPU6050() { int16_t ax, ay, az; int16_t gx, gy, gz; // read raw accel/gyro measurements from device accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); // display tab-separated accel/gyro x/y/z values Serial.print("i");Serial.print("\t"); Serial.print(ax); Serial.print("\t"); Serial.print(ay); Serial.print("\t"); Serial.print(az); Serial.print("\t"); Serial.print(gx); Serial.print("\t"); Serial.print(gy); Serial.print("\t"); Serial.println(gz); Serial.print("\n"); }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.