Firmware code to be run in the arduino microcontroller for proper control of the motors of the robot.
Check encoder_driver.h
and motor_driver.h
files to check the expected pins for the connection.
Verify and Upload andino_firmware.ino
to your arduino board.
Via serial
connection (57600 baud) it is possible to interact with the microcontroller. The interface is described in the andino_firmware/commands.h file. Here are the most used commands:
- Get encoder values:
'e'
- Set open-loop speed for the motors[pwm]
'o <left> <right>'
- Example to move forward full speed:
'o 255 255'
- Range
[-255 -> 255]
- Example to move forward full speed:
- Set closed-loop speed for the motors[ticks/sec]
'm <left> <right>'
- Important!: See the
Test it!
section.
- Important!: See the
- Set PID values:
'u <kp> <kd> <ki> <offset>'
Note: Remember the carriage return character at the end of the message.
A serial port connection must be created at 57600 bauds. You can use the serial monitor from Arduino IDE for example.
-
Open loop verification:
- Send
o 255 255
to go full speed - Send
o 0 0
to stop it.
- Send
-
Read the encoders
- Send
e
to get the encoders values.
- Send
-
Get the ticks per revolution of your motor.
- First set the encoders to zero, (reeboting with
r
). - Then rotate your motors as many revs you want,(say 10 for example) and then divide the encoder ticks per the number of revs. -> Then you get the ticks per revolution. Save this value, it is calibration for the control loop.
- First set the encoders to zero, (reeboting with
-
Closed loop verification
- Send
m <tps> <tps>
wheretps
stands forticks per second
. For example if your motor-encoder system gets 700 ticks per revolution then sendingm 700 700
will rotate both motors at 1 rev per sec. (~3.14rad/sec)
- Send