In our lab there is a robot arm (Eurobtec tr5), which has 6 joints. Each of them is a DC Motor.
What we are trying to do is to controll the robot using Raspberry Pi and Codesys. Ideally an interface for each axis should be
programmed using the Motion Controll library.
In order to rotate the motors two Adafruit DC Motor Hats(I2C) are used, and the values of all the potentiometers are being read using two
PCF8591 A/D Converters (I2C). As a basis I took the Soft Motion Servo Example project and changed it so that the
setting of the motors' velocities and the reading of the motors' positions work fine.
In the Soft Motion Servo Example project there is a virtual axis "SM_Drive_Servo", which is attached to the Adafruit_PWM device.
In our case however all our axis should be "children" of two I2C devices (1st: AdaFruitPWM DC, 2nd: PCF8591). Since I was not sure how to create
a device description in this case, I just created a function block which inherits the .
I also reprogrammed the method so that it makes sense for our application.
Now when i try to enable an axis with the function block its variable never becomes true. And concequently the variable is
also never true, so the controlling using the function block doesn't work.
I have attached the Codesys project and I would be very thankfull if someone could take a look and maybe tell me what I am missing.
Unfortunatelly I forgot to add the new device description and the adapted library for the Adafruit DC Motor Hat. Both files can be found as attachments in this post.
Also I ve attached the corresponding files for the PCF8591 A/D Converter in case someone doesn't have them. These files were downloaded from here: l viewtopic.php?f=23&t=5872&p=11016&hilit=PCF8591#p11016 l and have not been changed.
Having all the attached files no errors should be thrown when trying to open the project.
To be more precise with my question: the hardware part of the project functions without any problems.We are able to make our DC Motors rotate using the Adafruit DC Motor Hat and we are able to read the positions of our motors using the PCF8591 A/D Converter. Now we want to controll our motors using the SoftMotion function blocks. Even though our axis implements the axis interface, it cannot even be enabled using the MC_Power function block.
of course, it would be the most beautiful solution if we had a dedicated SoftMotion axis for the devices you are using. However, as the actor device (Adafruit_DC_Motor_Hat) and the sensor device (PCF8591) are not one, this is a little tricky.
But especially for such cases we have designed the PosControl drive, which can be added under the "SoftMotion General Axes Pool". You must link its velocity output to the Adafruit DC motor hat and copy the position input received from PCF8591 to the axis' input. Then, you can tune the position controller and make it a real servo-like axis.
Please open the online help and find "PosControl.project" in the index, which explains in detail, how this special axis works and how it has to be configured.
Good luck!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Setting the rotational speed and direction for the Adafruiut MotorHat is a bit trickier then just
assigning a variable as it it is done in the example project, but besides that this approach works very well.
Cheers,
sergii
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, this topic is very interesting for me. I want to control some small DC motors also with the same Adafuit Hat. The motors have quadrature encoders (signals A, B). I would wire the encoder signals into the GPIO pins of the Pi. I would need to be able to calculate the motor speed feedback and use this in the calculation for the PWM output. Is this possible ? I was thinking of using sergp's library as starting point. Has anyone used a quadrature encoder and codesys to calculate motor speed before ?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Kelad,
I think it is not possible to connect the quadrature encoder signal to the GPIOs, or only in case the frequency of the signal is very low. As we do not support GPIO-triggered interrupts on Raspberry with CODESYS, you need to poll the inputs in a cycle of your PLC (e.g. 1ms) and this will limit the maximum frequency of the quadrature signal to about 250Hz (or even less, am not sure).
Therefore I'd recommend you to use a hardware extension to decode the signal. This could either be a small microprocessor, that you program on your own and let it communicate with the RasPi via iΒ²c/SPI. Or you could use a dedicated chip for signal decoding with an appropriate interface.
Regards
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Hilmar Panzer for your response. I know this is not your area, but can you recommend any "dedicated chip for signal decoding" [i.e part numbers] ? If not, no worries.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
sorry, personally I have never implemented this. I briefly scanned the internet and found a chip called LS7166 which sounds suitable. But surely there are several others...
Regards,
Hilmar
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone,
In our lab there is a robot arm (Eurobtec tr5), which has 6 joints. Each of them is a DC Motor.
What we are trying to do is to controll the robot using Raspberry Pi and Codesys. Ideally an interface for each axis should be
programmed using the Motion Controll library.
In order to rotate the motors two Adafruit DC Motor Hats(I2C) are used, and the values of all the potentiometers are being read using two
PCF8591 A/D Converters (I2C). As a basis I took the Soft Motion Servo Example project and changed it so that the
setting of the motors' velocities and the reading of the motors' positions work fine.
In the Soft Motion Servo Example project there is a virtual axis "SM_Drive_Servo", which is attached to the Adafruit_PWM device.
In our case however all our axis should be "children" of two I2C devices (1st: AdaFruitPWM DC, 2nd: PCF8591). Since I was not sure how to create
a device description in this case, I just created a function block which inherits the .
I also reprogrammed the method so that it makes sense for our application.
Now when i try to enable an axis with the function block its variable never becomes true. And concequently the variable is
also never true, so the controlling using the function block doesn't work.
I have attached the Codesys project and I would be very thankfull if someone could take a look and maybe tell me what I am missing.
i2c_PWM_PCF8591.project [158.18 KiB]
Unfortunatelly I forgot to add the new device description and the adapted library for the Adafruit DC Motor Hat. Both files can be found as attachments in this post.
Also I ve attached the corresponding files for the PCF8591 A/D Converter in case someone doesn't have them. These files were downloaded from here: l viewtopic.php?f=23&t=5872&p=11016&hilit=PCF8591#p11016 l and have not been changed.
Having all the attached files no errors should be thrown when trying to open the project.
To be more precise with my question: the hardware part of the project functions without any problems.We are able to make our DC Motors rotate using the Adafruit DC Motor Hat and we are able to read the positions of our motors using the PCF8591 A/D Converter. Now we want to controll our motors using the SoftMotion function blocks. Even though our axis implements the axis interface, it cannot even be enabled using the MC_Power function block.
Thanks is advance!
PCF8591.devdesc.xml [2.47 KiB]
I2C_PCF8591.library [325.22 KiB]
I2C_AdafruitPWMEx.library [332.47 KiB]
AdafruitPWMDC.devdesc.xml [2.36 KiB]
Hi sergp,
of course, it would be the most beautiful solution if we had a dedicated SoftMotion axis for the devices you are using. However, as the actor device (Adafruit_DC_Motor_Hat) and the sensor device (PCF8591) are not one, this is a little tricky.
But especially for such cases we have designed the PosControl drive, which can be added under the "SoftMotion General Axes Pool". You must link its velocity output to the Adafruit DC motor hat and copy the position input received from PCF8591 to the axis' input. Then, you can tune the position controller and make it a real servo-like axis.
Please open the online help and find "PosControl.project" in the index, which explains in detail, how this special axis works and how it has to be configured.
Good luck!
Hi Hilmar,
thanks a lot for your answer!
Setting the rotational speed and direction for the Adafruiut MotorHat is a bit trickier then just
assigning a variable as it it is done in the example project, but besides that this approach works very well.
Cheers,
sergii
Hi, this topic is very interesting for me. I want to control some small DC motors also with the same Adafuit Hat. The motors have quadrature encoders (signals A, B). I would wire the encoder signals into the GPIO pins of the Pi. I would need to be able to calculate the motor speed feedback and use this in the calculation for the PWM output. Is this possible ? I was thinking of using sergp's library as starting point. Has anyone used a quadrature encoder and codesys to calculate motor speed before ?
Thanks.
Hi Kelad,
I think it is not possible to connect the quadrature encoder signal to the GPIOs, or only in case the frequency of the signal is very low. As we do not support GPIO-triggered interrupts on Raspberry with CODESYS, you need to poll the inputs in a cycle of your PLC (e.g. 1ms) and this will limit the maximum frequency of the quadrature signal to about 250Hz (or even less, am not sure).
Therefore I'd recommend you to use a hardware extension to decode the signal. This could either be a small microprocessor, that you program on your own and let it communicate with the RasPi via iΒ²c/SPI. Or you could use a dedicated chip for signal decoding with an appropriate interface.
Regards
Thanks Hilmar Panzer for your response. I know this is not your area, but can you recommend any "dedicated chip for signal decoding" [i.e part numbers] ? If not, no worries.
Hi,
sorry, personally I have never implemented this. I briefly scanned the internet and found a chip called LS7166 which sounds suitable. But surely there are several others...
Regards,
Hilmar