One index when controlling the EV3 is to get the angle of the motor. Also, when doing machine learning while using Python, some data is always required, but you may want to acquire motor data together with sensor data. This time, I will monitor how many angles the motor is rotating in real time in the Python environment of EV3.
Educational version LEGO® MINDSTORMS EV3 (hereafter EV3)
The content of this article is based on the following books. The basic control of EV3 using Python is covered below.
Introduction to AI starting with robots
PC Windows10 Python 3.7.3 Development environment Visual Studio Code
EV3 ev3dev API Reference
Refer to the following for environment construction, source creation with VS Code, and transfer / execution method to EV3. EV3 x Pyrhon Machine Learning Part 1 Environment Construction
from ev3dev2.motor import LargeMotor, OUTPUT_B
from ev3dev2.button import Button
import time
button = Button()
lm_bT = LargeMotor('outB')
lm_bT.reset()
def main():
while not(button.backspace):
time.sleep(0.2)
print(lm_bT.position)
lm_bT.stop(stop_action = 'brake')
if __name__ == '__main__':
main()
The value of the motor angle changes to + when turned in the positive direction and to-when turned in the negative direction. This time, the motor has tires, but for example, if the tire makes one revolution in the positive direction, the angle value will change from 0 to 360.
This time, I used the position method to check the angle of the motor. By recording this data and specifying the position, it will be possible to control the motor accurately.
Recommended Posts