if your client is expecting a number in text format, then simply send, e.g. "45.0\n"
Unfortunately we do not have the corresponding Arduino code...
Cheers
Control A Servo through Arduino by controling a joint in Coppelia Sim
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Eureka! That works, thanks a lot.
But now I want to send the joint position, p1=sim.getJointPosition(joint), and how can I add this '/n' message with this variable?
Also for this code
is there tutorial or example that I can follow to understand how it works?
Thank you very much for your time.
Sincerely,
But now I want to send the joint position, p1=sim.getJointPosition(joint), and how can I add this '/n' message with this variable?
Also for this code
Code: Select all
sim.serialSend(serialPortHandle,sim.packInt32Table({number})) -- send as coded int32
Thank you very much for your time.
Sincerely,
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Then your client must be accepting angles in degrees, as strings.
So you can do, e.g.:
Cheers
So you can do, e.g.:
Code: Select all
local stringToSend=tostring(sim.getJointPosition(joint))..'\n'
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Thanks a lot, once again everything works now. However, simulation send data so fast that the Arduino bottlenecks and gets unstable also the servo cannot reach that fast.
Is there a way to slow down the data send speed or maybe something like delay(500) to delay data send after each one.
Such as
Send Data
wait 0,5 secs
Send Data
wait 0,5 secs
Also, for this kind of codes should use a threaded script instead of the non-threaded?
Sincerely,
BS
Is there a way to slow down the data send speed or maybe something like delay(500) to delay data send after each one.
Such as
Send Data
wait 0,5 secs
Send Data
wait 0,5 secs
Also, for this kind of codes should use a threaded script instead of the non-threaded?
Sincerely,
BS
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
With a threaded script, you can use sim.wait.
With a non-threaded script, simply count how often you've sent data, and skip sensing if too frequent, e.g.:
Cheers
With a non-threaded script, simply count how often you've sent data, and skip sensing if too frequent, e.g.:
Code: Select all
function sysCall_init()
lastTime=sim.getSystemTimeInMs(-1)
end
function sysCall_actuation()
currentTime=sim.getSystemTimeInMs(-1)
if currentTime-lastTime>500 then
...send data here...
lastTime=currentTime
end
end
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Hello Mr. Admin,
Thank you very much for your contribution, your suggestions work like magic.
If a student would have a similar situation like mine - I want to write some hints.
AS I understood Coppelia Sim with basic serialsend code send to Arduino as chars and here this example 4 code works great with the task. It takes it and converts into integer.
I was not able to work with
code, I will try to do it later on.
Thank you very much for your contribution, your suggestions work like magic.
If a student would have a similar situation like mine - I want to write some hints.
AS I understood Coppelia Sim with basic serialsend code send to Arduino as chars and here this example 4 code works great with the task. It takes it and converts into integer.
I was not able to work with
Code: Select all
sim.serialSend(serialPortHandle,sim.packInt32Table({number})) -- send as coded int32
Re: Control A Servo through Arduino by controling a joint in Coppelia Sim
Another question from me is:
I need to control several actuators from Simulation and I wonder
-How can I send several serial messages with maybe different headings so that Arduino can understand which code is which code? How can I achieve this, could you please guide me?
I need to control several actuators from Simulation and I wonder
-How can I send several serial messages with maybe different headings so that Arduino can understand which code is which code? How can I achieve this, could you please guide me?